Hi
We have a template with two pages and in the second page we have only half of the template data (remaining half is empty). Hence when we try to build the document the data of the second record is merged (displayed in )with the last page of first record’s data as there is some empty space in the second page of template.
We tried to add forced breaks to the document to make explicit page separation (via MS Word’s Insert | Break menu.)*.*On doing this the records are displayed properly with the data of one record not merged with th other.
However is there any way by which we can put page breaks using Aspose.Words ? And we read in one discussion that “if the pages in your template are not separated by forced breaks , then it is currently impossible to extract a particular page from the document with Aspose.Words.” Is this possible to do with Aspose.Words ? Could anyone please help us on this ?
We are currently using Aspose Java 3.0 and JDK 1.4
Thanks in advance
Thanks and Regards,
Rajesh P.
Hello
Thanks for your request. Could you please attach your template here for testing? I will check the problem and provide you more information.
Best regards,
Hi Andrey,
Thanks For your Reply, Here i have attached the Documents.
- The template
- The Document Build ed.
- The Excepted Document.
Hello
Thank you for additional information. In your case you should just use SectionBreak (New Page) instead of SectionBreak (Continuous). Please see the following link to learn more:
https://docs.aspose.com/words/net/mail-merge-template/
Best regards,
Hi Andrey,
Thanks For Quick Reply.Can we achieve this using aspose.if so, can you please provide an example.
I am using aspose 1.4 and java 1.5
Advance Thanks
Hi
Thanks for your request. Sure, you can. You can use code like the following:
// Open template.
Document doc = new Document("in.doc");
// Set section strat of the first section of the template.
doc.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
// Execute mail merge and save output
// ...................................
Hope this helps.
Best regards,
Hi Alexey,
Thanks For ur reply… I have tired the way u said… but the builded document still remain the same…
Can you please help me on this…
here is the below logic…
public void mergeFields(IMailMergeDataSource argIMailMergeDataSource) throws Exception
{
currentDocument.getMailMerge().execute(argIMailMergeDataSource);
currentDocument.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
for (Section sect: currentDocument.getSections())
{
List tmpList = null;
List newList = null;
sect.getPageSetup().setRestartPageNumbering(true);
sect.getPageSetup().setPageStartingNumber(1); Removed the comment to display page number properly.
// Get collection of paragraps in the section
NodeCollection paragraphs = sect.getChildNodes(NodeType.PARAGRAPH, true);
currentDocument.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
// Loop through all paragraphs
for (int i = 0; i <paragraphs.getCount(); i++)
{
Paragraph par = (Paragraph) paragraphs.get(i);
if (par.isListItem())
{
if (!par.getListFormat().getList().equals(tmpList))
{
// Create new list
newList = currentDocument.getLists().addCopy(par.getListFormat().getList());
// Store list in temporary variable
tmpList = par.getListFormat().getList();
}
// Restart list.a
par.getListFormat().setList(newList);
}
}
}
currentDocument.getMailMerge().deleteFields();
}
Hello
Thank you for additional information. But I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java (10.0.1). You can download this version from here:
https://releases.aspose.com/words/java
I use the following code:
// Open template.
Document doc = new Document("The+Template.doc");
// Set section strat of the first section of the template.
doc.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
// Execute mail merge and save output
// ...................................
Best regards,