Hello,
In my Word template, there is a dynamic Table of Contents (TOC) followed by a page break. The problem arises when the TOC fills an entire page; the page break moves to the next page, creating an empty page. When I try to delete this empty and unnecessary page, and then update the page numbers of the TOC, the TOC appears twice (one in black and one in blue). Any ideas why?
Example code in attachement
Regards,
test.zip (140,0 Ko)
@Frederic_Juglaret The problem occurs because your code that removes an empty page also removes TOC field end.
I would suggest you to use section break instead of page break. Please see the following modified template: word-template-atec2pdf.docx (154.5 KB)
In this case it would be enough to use the following code:
Document templateDoc = new Document("C:\\Temp\\word-template-atec2pdf.docx");
String htmlContent = readStream(new FileInputStream("C:\\Temp\\aspose_support.html"));
DocumentBuilder builder = new DocumentBuilder(templateDoc);
builder.moveToDocumentEnd();
builder.insertHtml(htmlContent, true);
templateDoc.updateFields();
templateDoc.save("C:\\Temp\\out.docx");
Also, in your case you use Document.updateTableLayout
method. This method is deprecated and is not normally recommended to be used unless you are sure it will improve the output.
Document.updateListLabels
method also is not required in your case. It updates Paragraph.ListLabel
property, which is not used in your code.
Thank you Alexey,
I use section break instead of page break by and now it works like a charm !
1 Like