
Microsoft.Office.Interop.Word.Document.ExportAsFixedFormat() not working as expected
Our application is actively communicating with Word in order to perform certain operations. One of the operations is to export the word document to PDF. Recently in the new versions of word (Microsoft® Word for Microsoft 365 MSO (Version 2301 Build 16.0.16026.20002) 32-bit) we got some complains from our users that the export is not working as expected even though we didn't have any major code changes in that area. The problem is that we have a lot of content controls in our document (Microsoft.Office.Interop.Word.Document) and before exporting it to PDF using ExportAsFixedFormat method we go through all of the content controls and hide the empty ones (that are missing information usually filled from our application). However recently I've noticed the empty content controls are still shown even thought our 'manully hide' implementation is being executed before exporting. I was hoping to get more information about that topic or maybe someone already had encountered such issue.
Note: I have tried to to print the exact same document using PDF printer and deselected the option (print hidden fields) + selected option (update fields at print) and it worked as expected (hide the empty controls). Having done that I tried to replicate this configuration in the code by setting those two properties to the document's options (see the code snippet).
But unfortunately I didn't have any success with it as I assume ExportAsFixedFormat() method works differently internally compared to print with PDF printer feature.
Any suggestions or ideas would be very much appreciated. Thank you very much.
document.Application.Options.UpdateFieldsAtPrint = true;
document.Application.Options.PrintHiddenText = false;
Microsoft 365 and Office | Development | Other
