we noticed an issue with the
UpdatePageLayout method in some scenarios. We usually open a word document and modify it, inserting some headers and footers and such stuff. As we once had an issue with wrong page numbers in the table of content we added to call the
UpdatePageLayout before rendering to pdf. I really can´t remember if this was something suggested in any other forum topic found via google or if we found out by ourselves reading the docs
This method formats a document into pages and updates the page number related fields in the document such as PAGE, PAGES, PAGEREF and REF. The up-to-date page layout information is required for a correct rendering of the document to fixed-page formats.
However, there is some inconsistent behaviour. I attached you an example docx file which has already included header and footer files. It has 2 pages of content. When rendering it to pdf via word it somehow is reduced to one page - in the PDF but also inside the document after PDF conversion. I made a video of that behaviour.
If you render the document to PDF via Aspose, this behaviour is the same (which is good as we need the PDF output most close to word PDF output).
If you render the document to PDF with Aspose, calling
UpdatePageLayout and rendering again, it still looks same, in both output files.
But if you call
UpdatePageLayout before rendering to PDF, it looks different to the word output as the PDF is not “reduced” to one page.
First I thought it might be logical there is something changed, but then I figured out the second of the above cases and was confused why the second output still is good. Then I read the docs in more detail:
This method is automatically invoked when you first convert a document to PDF, XPS, image or print it. However, if you modify the document after rendering and then attempt to render it again - Aspose.Words will not update the page layout automatically. In this case you should call UpdatePageLayout() before rendering again.
I am confused now and have the following questions and probably bugs (or the docs are just wrong?):
- Why is it necessary to call
UpdatePageLayoutmanually to update the table of contents if it should be invoked automatically if you render a word file to PDF the first time?
- Why is it a difference when calling the
UpdatePageLayoutmethod manually before first rendering if it is invoked automatically anyways.
I attached you some input documents and example code and the above mentioned video.
files.zip (3.2 MB)