I was trying to add sub htmls as altchunks. My requirement is i have to parse html and if any img tag with base64 data is found, i have to add image inline using docx4j API. other data i am adding as alt chunk. in this process if img tag is inside <td>. till td i use addAltchunk and then addimag inline. In this case table is closed by call to addAltchunk. My image is coming out of table.
I tried below sample. i see the same behaviur. attached word doc produced as well. The content "kk" should come inside table. but it is coming out side the table.
- Code: Select all
WordprocessingMLPackage wordMLPackage=null;
wordMLPackage=WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addAltChunk(
org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType.Html,
"<html><table style=\"border:1px solid black;\"><tr><td><p>hi</p></td></tr><tr><td></html>".getBytes());
wordMLPackage.getMainDocumentPart().addAltChunk(
org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType.Html,
"<html>kk</td></tr></table></html>".toString().getBytes());
FileOutputStream out = new FileOutputStream("test1.docx");
wordMLPackage.save(out);
looks like addaltchunk is closing table.
We could not use XHTMImporter API for this requirement of converting base64 images inline. We need to parse html and replace all img tags with img inline.For which above approach tried that do not give expected results. Pls suggest.