Free Support Forum - aspose.com

Page No Issue with Page orientation

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

Hello

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java 10.3.0 and the following code:

Document mailDoc = new Document("C:\\Temp\\Report Series Definition Name.doc");

Document srcDoc1 = new Document("C:\\Temp\\Sec1.doc");

Document srcDoc2 = new Document("C:\\Temp\\Sec2.doc");

Document srcDoc3 = new Document("C:\\Temp\\Sec3.doc");

// Insert srcDoc to mailDoc

mailDoc.appendDocument(srcDoc1, ImportFormatMode.USE_DESTINATION_STYLES);

mailDoc.appendDocument(srcDoc2, ImportFormatMode.USE_DESTINATION_STYLES);

mailDoc.appendDocument(srcDoc3, ImportFormatMode.USE_DESTINATION_STYLES);

mailDoc.save("C:\\Temp\\out.doc");

Best regards,