Hi,
we have a customer who embedded the TOC inside the header of the first page. This generates a wrong output when rendering to PDF. I was able to reduce the problem to our code, which updates the page numbers for toc fields.
var lic = new License();
lic.SetLicense(@"S:\Aspose.Total.lic");
var doc = new Document(@"S:\tmp\test.docx");
// Inhaltsverzeichnis
foreach (var fs in doc.GetChildNodes(NodeType.FieldStart, true).AsEnumerable().Cast<FieldStart>()
.Where(fs => fs.FieldType == FieldType.FieldTOC))
((FieldToc)fs.GetField()).UpdatePageNumbers();
doc.Save(@"S:\tmp\out.docx");
doc.Save(@"S:\tmp\out.pdf");
Attached files:
test.docx -> reduced input file
out.docx -> above code saved to docx (output still is good)
out.pdf -> above code saved to PDF (output is wrong)
word.pdf -> PDF generated with word (from test.docx)
If you remove the loop, updating page numbers, the PDF generated with Aspose looks fine btw.
example.zip (1.1 MB)
Kind Regards,
Daniel