How to Add Page Break with LINQ Reporting using Java

Dear Aspose team,

When composing a template in MS Word, what is the syntax to continue on the next page ?

i.e. when iterating of a list and write every output on a new page?

Many thanks, Jeffrey

@Jeffrey1

You can use the following template syntax to insert the page break into document.
<<[ControlChar.PageBreak]>>

Following code example shows how to use ControlChar.

DocumentBuilder builder = new DocumentBuilder();
builder.write("<<foreach [in items]>>");
builder.write("Page #<<[numberOf()]>>");
builder.write("<<[ControlChar.PAGE_BREAK]>>");
builder.write("<</foreach>>");

ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(ControlChar.class);

ArrayList items = new ArrayList();
for (int i = 0; i < 3; i++)
    items.add(new Object());

engine.buildReport(builder.getDocument(), items, "items");
builder.getDocument().save(MyDir + "output.docx");

If your requirement is different, please share some more detail about your query. We will then provide you more information on it.

1 Like

Thanks @tahir.manzoor , this is working many thanks =)

Can you also inform from the template syntax how to start each textblok after 5 line breaks(enters).

I tried :

<<ParagraphFormat.setSpaceBefore(5.0)>>

java code:

ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(ControlChar.class);
engine.getKnownTypes().add(ParagraphFormat.class);

stacktrace:
Exception in thread “main” java.lang.IllegalStateException: Tag ‘ParagraphFormat’ is not well-formed. Token ‘ParagraphFormat’ is unexpected.
at com.aspose.words.internal.zzGE.zzZ(Unknown Source)
at com.aspose.words.internal.zzGE.zzZ(Unknown Source)
at com.aspose.words.internal.zz99.zzZ(Unknown Source)
at com.aspose.words.internal.zz99.zzZ(Unknown Source)
at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
at xx.documentGenerator(DocumentGenerator.java:36)
at xx.main(DocumentGenerator.java:18)

Thanks, Jeffrey

@Jeffrey1

We have already answered your query here in this post. Please follow that thread for further proceedings.