Reproduced using the latest version of Aspose (14.2.0). This issue does not occur in Aspose.Words 9.4.0, however we need to upgrade to something newer to address some other bugs in Aspose.Words that have since been fixed.
I am attaching the sample document and code used to reproduce.
We have .docx that is going through a mailmerge. The result is then saved to PDF. However, once saved to PDF, we have fields showing up as “Error! Bookmark Not Defined”.
If I inspect the source document, and hit Alt-F9 to show hidden fields, I can see there are some additional funky fields that surround the “normal” merge field. I’m not sure if these are artifacts from a copy/paste from an older version of Word, but in either case I believe they are the source of the error. Without Alt-F9, the document looks like this:
½SAL_DEP_OPTIONS╗
However, if I hit Alt-F9, I see the following:
{ MERGEFIELD "SAL_DEP_OPTIONS" \# "#,##0"}{{ MERGEFIELD COM_ID }+{MERGEFIELD COM_ID}+{MERGEFIELD COM_ID}}
What is odd is the merge field COM_ID does not show unless I hit Alt-F9 (it is not a field we actually want in the document).
The data for SAL_DEP_OPTIONS is populating fine. If I make sure I include merge data for COM_ID, something weird happens:
- I still get the “Error! Bookmark not defined!” message in the PDF
- If I save the merged document to .docx, and then hit Alt-F9, I can see that the hidden merge fields for COM_ID now look like this:
FOOBAR {""+""+""}
Where FOOBAR is the value of SAL_DEP_OPTIONS and “” is the value assigned to COM_ID. FOOBAR is visible normally, while the extraneous is only visible if I ALT-F9.
If I remove the merge field SAL_DEP_OPTIONS and recreate it, the issue goes away. However, this problem has been replicated across about 2500 documents, and in more than one place. It was not an issue when we were on Aspose 9.4 (hence it went for so long unnoticed), but now we are stuck and cannot upgrade.
My questions are:
- Is there a way to suppress Bookmark Not Defined errors when saving to PDF?
- Alternatively, is there a way to programatically locate the Bookmark Not Defined problems and remove them from the document, prior to saving to PDF?
- Would you consider this a bug, since it did not have this problem in 9.4, but now does in 14.2?
Documents and screenshots (showing before and afters, including w/ Alt-F9 mode) attached. Code used:
var doc = new Document("test.docx");
doc.MailMerge.Execute(new []
{
"SAL_DEP_OPTIONS",
"COM_ID"
}, new []
{
"FOOBAR",
""
});
doc.Save(@"out.docx");
doc.Save(@"out.pdf", SaveFormat.Pdf);