@rausch Could you please attach your document here? We will check and provide you more information.
Most likely in your document you use Structured Document Tags because legacy form fields cannot be inserted in Header footer. In this case, you can simply replace Structured Document Tags in headers and footers of your document with their text representation. for example see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
// Convert sdts in the document's header and footers with text.
NodeCollection headerFooters = doc.GetChildNodes(NodeType.HeaderFooter, true);
foreach (HeaderFooter hf in headerFooters)
{
NodeCollection sdts = hf.GetChildNodes(NodeType.StructuredDocumentTag, true);
foreach (StructuredDocumentTag sdt in sdts)
{
if (sdt.SdtType == SdtType.PlainText)
{
foreach (Node child in sdt.ChildNodes)
{
sdt.ParentNode.InsertAfter(child, sdt);
}
sdt.Remove();
}
}
}
PdfSaveOptions opt = new PdfSaveOptions();
opt.PreserveFormFields = true;
doc.Save(@"C:\Temp\out.pdf", opt);
@rausch Yes, you understand the proposed approach correctly. The code replaces structured document tags with their content. Please attach your document here for testing. The provided code works properly with a simple test document I created on my side.