Hi there,
I have a child document which I'm testing the merging of into a parent document using the following 3 methods:
1. Add child to parent as an AltChunk of type AltChunkType.WordprocessingML using the addAltChunk(...) method
e.g.
parentDocument.getMainDocumentPart().addAltChunk(AltChunkType.WordprocessingML, new FileInputStream(inputFilePath));
parentDocument.getMainDocumentPart().convertAltChunks();
2. Add child to parent as an AltChunk of type AltChunkType.Xhtml using the addAltChunk(...) method
e.g.
parentDocument.getMainDocumentPart().addAltChunk(AltChunkType.Xhtml, childDocumentAsXHTMLDocument);
parentDocument.getMainDocumentPart().convertAltChunks();
3. Add child to parent using the XHTMLImporter.convert(...) method passing in the exported child document XHTML as ByteArrayInputStream
e.g.
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(parentDocument);
List wordDocumentElementsConvertedFromXHTML = XHTMLImporter.convert(childDocumentAsXHTMLDocument, null);
parentDocument.getMainDocumentPart().getContent().addAll(wordDocumentElementsConvertedFromXHTML);
What I've found is that both method 2 and 3 result in the font size from the original document being increased by 1pt on inclusion into the parent document. I also have a table in the child document that is within the page margins but winds up being pushed beyond the page width on inclusion in the parent document as again the font size has increased by 1pt for the text in the table.
My code to export the child document to XHTML and return the "childDocumentAsXHTMLDocument" ByteArrayInputStream mentioned above is as follows:
HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings.setImageDirPath(inputFilePath + "_files");
htmlSettings.setImageTargetUri("file:/" + inputFilePath + "_files");
WordprocessingMLPackage childDocument = WordprocessingMLPackage.load(new FileInputStream(inputFilePath));
VariablePrepare.prepare(childDocument);
htmlSettings.setWmlPackage(childDocument);
htmlSettings.getFeatures().remove(ConversionFeatures.PP_HTML_COLLECT_LISTS); // I have a numbered list in the child document that I want to retain on merge into the parent e.g. clauses marked a), b), c) etc
OutputStream os = new ByteArrayOutputStream();
Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
ByteArrayInputStream childDocumentAsXHTMLDocument = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
Am I missing setting something either on the export out to XHTML or the import in from it that is preventing it from retaining the original font sizing on merging?
It is worth noting that all child document styling retained perfectly when merged into the parent using method 1. Add child to parent as an AltChunk of type AltChunkType.WordprocessingML.
Thanks,
Brad.