convertAltChunks removing altChunks from docx
 Posted: Sat May 04, 2019 6:18 am
Posted: Sat May 04, 2019 6:18 amI have a docx I am creating using a template with placeholders. I find the placeholders and add alt chunks using this method:
I insert some of the altchunks into table cells. (The Tc contains a P which contains an R. I use that R as the ContentAccessor to insert the altchunk).
When I save the doc without converting the altchunks, everything works great. However, I need to convert the docx to pdf after and when I do so the altchunks do not display (bc they have not been converted).
so I call:
The resulting docx is missing the altChunk content. There are no errors. My dependencies are the following:
I appreciate any help, thanks!
			- Code: Select all
- public static void addAltChunk(R run, String html){
 String chunk = "<!DOCTYPE><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head></head><body>" + html + "</body></html>";
 try {
 mdp.addAltChunk(AltChunkType.Xhtml, chunk.getBytes(), run);
 } catch (Exception e) {
 e.printStackTrace();
 }
 }
I insert some of the altchunks into table cells. (The Tc contains a P which contains an R. I use that R as the ContentAccessor to insert the altchunk).
When I save the doc without converting the altchunks, everything works great. However, I need to convert the docx to pdf after and when I do so the altchunks do not display (bc they have not been converted).
so I call:
- Code: Select all
- WordprocessingMLPackage tempPackage = mdp.convertAltChunks();
 tempPackage.save(new java.io.File(finalPath + documentName));
The resulting docx is missing the altChunk content. There are no errors. My dependencies are the following:
- Code: Select all
- <dependency>
 <groupId>org.docx4j</groupId>
 <artifactId>docx4j-JAXB-Internal</artifactId>
 <version>8.0.0</version>
 </dependency>
 <dependency>
 <groupId>org.docx4j</groupId>
 <artifactId>docx4j-ImportXHTML</artifactId>
 <version>8.0.0</version>
 </dependency>
I appreciate any help, thanks!
