We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reflect Correct Headers Footers in Sections Nested inside IF Field Condition during Word DOCX Document to PDF Conversion using C# .NET

We have a situation, where saving a Word (docx) document to PDF, in which the header of the last saved page is incorrect.

The document layout is as follows:

  • 4 sections, with independent headers (without link to previous)
  • the 3rd and 4th section contents are within a common if

With this structure, and the if condition evaluating as false, the saved document has only 2 ou of 4 pages, as expected, but the header on the 2nd page is replaced by the header of the last section.

In attachment I added a working sample (minus license) of this situation, including:

  • the sample source code - simple console application that loads the Word and immediately saves as PDF
  • the source Word document
  • the expected result (as exported through Word directly)
  • the actual result, as saved by the sample application provided

Is this a known issue? Any idea for a fix or workaround?

Thanks in advance

AsposeSample.zip (82.2 KB)

@teameim,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20009. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

@teameim,

Regarding WORDSNET-20009, it is to update you that we have completed the analysis of this issue and the root cause has been identified. The issue occurs because Aspose.Words currently does not handle section breaks inside field codes the way MS Word does.

Aspose.Words currently ignores section breaks in field codes. MS Word takes them into account when determining header/footer even though it disregards them in other respects.

I am afraid, because of complexity, the implementation of this issue has been postponed till a later date. There are no estimates available at the moment. We will be sure to inform you via this thread as soon as this issue will be resolved in future. We apologize for your inconvenience.

In the meantime, you may move the problematic section break out of the field or set the expected footer to the next section that has section break outside of field code as a workaround.

Thanks for the follow-up.
We appreciate you keeping us in the loop.