Not able to put watermark after merging fields

Hi there, the problem is that this is working:

insertWatermarkText(dstDoc, "PREVIEW");
dstDoc.getMailMerge().execute(fields, vals); + filename) + ".pdf");

and this one is not producing watermark in the output pdf:

dstDoc.getMailMerge().execute(fields, vals);
insertWatermarkText(dstDoc, "PREVIEW "); + filename + ".pdf");

if I save it as docx: + filename + ".docx");

it’s working fine, producing watermark in both cases.
insertWatermarkText procedure has been taken from documentation, dstDoc is DOCX document.
Aspose.Words 10.3., Java 1.4.2

Thanks for your request. You should call Document.UpdatePageLayout before saving document to PDF to resolve the problem. Please see the following code:


The problem is caused because when you execute mail merge, Aspose.Words automatically updates fields in the document. Updating fields also runs updating page layout and the layout is cached. So changes made after updating page layout does not appear in the output PDF. So you should simply rebuild document layout to resolve the problem.
Best regards,

it’s working, thank you very much