Header fields updated when document converted to PDF

We have noticed that fields in headers and footers are being updated when documents are converted to PDF.

The attached example DOCX contains a file path field and a date field in the header and a file path field and a date field in the body. The fields in the header are updated when the file is converted to PDF, while the fields in the body are not (see attached PDF).

We would like to be able to prevent fields being updated, or alternatively be able to display the underlying code - eg. { FILENAME \p * MERGEFORMAT }

Any guidance would be appreciated.

Thanks,

Reuben

Hi Reuben,
Thanks for your inquiry. You are facing this issue due to dynamic fields. You can avoid this by replacing these fields with static field. Please check following article it will help you to achieve your requirements. You can implement ConvertFieldsToStaticText() method as following to update Date and FileName field.
https://docs.aspose.com/words/net/updating-and-removing-a-field/

Document doc = new Document(MyDir + "Fields example.docx");
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldDate);
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldFileName);
doc.Save(MyDir + "fieldstest Out.pdf");

Please feel free to contact us for any further assistance.
Best Regards,