I’m trying to join two docs and save in one pdf. I’m having problem with SectionStart.CONTINUOUS, I think. When the second doc has more than one page the SectionStart.CONTINUOUS doesn’t work. My code is:
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("files/source.doc")));
Document doc = new Document(in);
doc.getRange().replace("_$#GANGUE#$_", "RATS", false, false);
doc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
Document result = new Document("files/result.doc");
for (Paragraph para : (Iterable)result.getChildNodes(NodeType.PARAGRAPH, true))
{
para.getParagraphFormat().setKeepWithNext(true);
}
doc.appendDocument(result, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc.save("files/result.pdf");
Thanks for sharing the detail. Please set the SectionStart property as continuous of first section of result.doc as shown in following code snippet to get the required output.
Please let us know if you have any more queries.
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("files/source.doc")));
Document doc = new Document(in);
doc.getRange().replace("_$#GANGUE#$_", "RATS", false, false);
Document result = new Document("files/result.doc");
result.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
for (Paragraph para : (Iterable)result.getChildNodes(NodeType.PARAGRAPH, true))
{
para.getParagraphFormat().setKeepWithNext(true);
}
doc.appendDocument(result, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc.save("files/result.pdf");
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("files/source.doc")));
Document doc = new Document(in);
doc.getRange().replace("_$#GANGUE#$_", "RATS", false, false);
doc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
Document result = new Document("files/result2.doc");
result.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
doc.appendDocument(result, ImportFormatMode.KEEP_SOURCE_FORMATTING);
doc.save("files/result.pdf");
Your code snippet is ok for the result.doc. So, I created a second file, result2.doc to test.With the result2.doc it doesn’t work. What I’m doing wrong?
Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert section break of type continues at the end of source.doc using MS Word and copy the contents of result2.doc after section break, you will get the same output.