Hi,
We have a requirement of compiling multiple documents into one document in an order. we are facing issue with footer not coming for one of the section when page orientation changes from portrait to landscape in between. I have attached 4 document made as one single document for your reference. kindly let me know what needs to be done.
Here is the code what is used by us to achieve the above.
public static void appendDoc(Document dstDoc, Document srcDoc, boolean includeSection) throws Throwable
{
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can
// just enumerate the Document.
if (includeSection)
{
for (Section srcSection: srcDoc.getSections())
{
Node dstNode = dstDoc.importNode(srcSection, true,
ImportFormatMode.USE_DESTINATION_STYLES);
dstDoc.appendChild(dstNode);
}
}
else
{
// find the last paragraph of the last section
Node node = dstDoc.getLastSection().getBody().getLastParagraph();
if (node == null)
{
node = new Paragraph(srcDoc);
dstDoc.getLastSection().getBody().appendChild(node);
}
if ((node.getNodeType() != NodeType.PARAGRAPH) &
(node.getNodeType() != NodeType.TABLE))
{
throw new Exception("Use appendDoc(dstDoc, srcDoc, true) instead of appendDoc(dstDoc, srcDoc, false)");
}
insertDocumentAfterNode(node, dstDoc, srcDoc);
}
}
public static void insertDocumentAfterNode(Node insertAfterNode, Document mainDoc, Document srcDoc) throws Throwable
{
// Make sure that the node is either a pargraph or table.
if ((insertAfterNode.getNodeType() != NodeType.PARAGRAPH) &
(insertAfterNode.getNodeType() != NodeType.TABLE))
throw new Exception("The destination node should be either a paragraph or table.");
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.getParentNode();
// Remove empty paragraphs from the end of document
while (null != srcDoc.getLastSection().getBody().getLastParagraph() &&
!srcDoc.getLastSection().getBody().getLastParagraph().hasChildNodes())
{
srcDoc.getLastSection().getBody().getLastParagraph().remove();
}
NodeImporter importer = new NodeImporter(srcDoc, mainDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
// Loop through all sections in the source document.
int sectCount = srcDoc.getSections().getCount();
for (int sectIndex = 0; sectIndex <sectCount; sectIndex++)
{
Section srcSection = srcDoc.getSections().get(sectIndex);
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
int nodeCount = srcSection.getBody().getChildNodes().getCount();
for (int nodeIndex = 0; nodeIndex <nodeCount; nodeIndex++)
{
Node srcNode = srcSection.getBody().getChildNodes().get(nodeIndex);
Node newNode = importer.importNode(srcNode, true);
dstStory.insertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
Regards,
Spoorthy