Extracting new/modified/deleted annotations as an "XFDF diff"

250 views
Skip to first unread message

Mike Ruthven

unread,
Apr 8, 2014, 5:11:35 PM4/8/14
to pdfne...@googlegroups.com
In the WebViewer documentation, I see the following entry that indicates it is possible to extract just the changes to the annotations for the current document, in an XFDF command format:

Exporting modified annotations as XML command to server

// Inside AnnotationPanel.js, create an AJAX request to the server, with the data being the command
// string returned by AnnotationManager.GetAnnotCommand(). Note that server_url and doc_id
        // are read in as the document is initially loaded

if (readerControl.server_url == null) {
             console.warn("Not configured for server-side annotation saving.");
     return;
}
var am = readerControl.docViewer.GetAnnotationManager();
var xfdfString = am.GetAnnotCommand();
etc...

Which I can then run through this code:
        $server_dir = "C:/wamp/www/server/";
$xfdf_doc = FDFDoc::CreateFromXFDF($server_dir . $filename);
$xfdf_doc->MergeAnnots($command);
$xfdf_doc->SaveAsXFDF($server_dir . $filename);

To update the "server" copy of the document's annotations.

Is there equivalent functionality in PDFNet?

Thanks,

Mike

Full WebViewer doc link, for reference.

Mike Ruthven

unread,
Apr 9, 2014, 11:35:19 AM4/9/14
to pdfne...@googlegroups.com
Thanks for the quick reply. I had considered the two solutions you suggest already, but when I saw the GetAnnotCommand method I thought I might be able to do it completely off-the-shelf. If I copy the command structure from the WebViewer example, so that I could theoretically send diffs back and forth from the server, can I pass that to FDFDoc.mergeAnnots(String command) on all the PDFNet implementations (Android, iOS, WinRT, etc), and have things work?

Thanks,

Mike

On Tuesday, April 8, 2014 7:31:22 PM UTC-4, Support wrote:

You can extract annotations from PDF as XFDF with PDFDoc.FDFExtract() as shown in FDF sample project (http://www.pdftron.com/pdfnet/samplecode.html#FDF

Unfortunately PDFNet currently doesn't have a GetAnnotCommand() option.  You could implement it on your end by tracking which annotations are newly added, which ones are deleted, or modified... then generating XFDF string.
Possibly useful function would be annot.GetSDFObj().IsDirty().  IsDirty() can be called on any SDF/Cos object (i.e. any low-level object in PDF) to find out if the object is new or modified .

Another option may be to save & send full XFDF, then do a XML diff on the server side.

Support

unread,
Feb 22, 2016, 5:35:28 PM2/22/16
to pdfne...@googlegroups.com

You can extract annotations from PDF as XFDF with PDFDoc.FDFExtract() as shown in FDF sample project (http://www.pdftron.com/pdfnet/samplecode.html#FDF

Unfortunately PDFNet currently doesn't have a GetAnnotCommand() option.  You could implement it on your end by tracking which annotations are newly added, which ones are deleted, or modified... then generating XFDF string.

Another option may be to save & send full XFDF, then do a XML diff on the server side.


On Tuesday, April 8, 2014 2:11:35 PM UTC-7, Mike Ruthven wrote:
Reply all
Reply to author
Forward
0 new messages