I'm trying to merge list of annotation commands to PDF.
To achieve this I'm using FDFDoc::MergeAnnots. Any kind of annotations are merged as expected, but not fields. I checked the FDFDoc content before and after merge and also the annotation command which contains field update. Everything looks valid, but after merge, all fields stay in their default state.
I'm using this code:
using (PDFDoc pdfdoc = new PDFDoc(pdfFilePath))
{
using(FDFDoc fdoc = pdfdoc.FDFExtract(PDFDoc.ExtractFlag.e_both))
{
// state of FDFDoc before merge
log.Debug(fdoc.SaveAsXFDF());
annotationsByIndex.ForEach(annotation => {
// merged annotation commands
log.Debug(annotation.command);
fdoc.MergeAnnots(annotation.command);
});
// state of FDFDoc after merge
log.Debug(fdoc.SaveAsXFDF());
pdfdoc.FDFMerge(fdoc);
pdfdoc.FlattenAnnotations();
bytes = pdfdoc.Save(SDFDoc.SaveOptions.e_linearized);
}
}
Tipical annotation command for field is:
<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
<field name="Address 1 Text Box">
<value>111111111</value>
</field>
</fields>
<add />
<modify />
<delete />
</xfdf>
I manage to change field values directly, using this code:
fdoc.GetField("Address 1 Text Box").GetValue().SetString("12345");
So I can parse annotation commands, and update fields manually, but would like to avoid this if possible.
Do you have any suggestions?
Thanks.