Bug in Heading font in converting Word to PDF

I have a C# program that converts an html document to Word and then to PDF. Before the conversion to PDF I do some removal and insertion of headers using the DocumentBuilder. The html document contains a h1 tag wrapping round the text “A heading line”. In the code before converting to html I attempt to change the h1 setting to Arial 16 by parsing the DOM. In general this works, the pdf displays correctly. However, if I dynamically add a footer to the document, via the builder, that includes page numbering, the heading text displays differently when converted to pdf - Times New Roman 24, I believe.
There is a flag in the code ‘bool setFooterWithNumbering = true;’ that either does or doesnt add the page numbering footer.

I have Aspose.Words 17.9, but I have also tried the latest but it made no difference.

I have attached a simple program with the required documents that produces this issue.
CodeAndDocuments.zip (206.8 KB)

@richard.botting The problem occurs because you are updating heading styles after calling Document.UpdateFields. When this method is called document layout is built and cached. When document is saved to PDF the cached layout is used. To avoid this either call Document.UpdateFields after making all chnages in the document, just before saving. Or you can call Document.UpdatePageLayout just before saving.
By the way, upon saving to PDF, Aspose.Words automatically updates fields, so update them explicitly is not required.

That’s great. It works now.

1 Like