Q: I would like to merge the annotations from multiple PDF documents
into a single document. Here is the scenario: Three identical copies
of a PDF are distributed to 3 individual reviewers. Each reviewer will
open the PDF copy using Adobe Professional, then proceed to add
annotations to the PDF -- sticky notes, highlighting, etc. Once the
process is completed, the reviewers will save the document to a pre-
determined location. Thereafter, the documents will be consumed by a
program that combines all of the annotations onto a single copy of the
document. Since each reviewer is reviewing the same document, we do
not need three copies of the document; we only want one copy, with the
annotations from all three reviewers. Can PDFNet SDK be used to
implement this?
-----
A: You can use PDFNet SDK (www.pdftron.com/net) to programmatically
merge annotations (either on the client or on the server). As a
starting point you may want to take a look at 'AnnotationTest' sample
project: http://www.pdftron.com/net/samplecode.html#Annotation. You
can either recreate the annotations from scratch (based on the
annotations from source PDFs) or import the annotation dictionaries
(you would need to alter some entries in annotation dictionaries to
make it work - this is similar to the code below)
Another approach to annotation merging is using FDF (Forms Data
Format) merge file. Using Acrobat Pro you can export annotations from
'Menu' > 'Commnets' > 'Export Comments' > 'To File'. This is
illustrated in the following code sample:
... Initialize PDFNet ...
...
PDFDoc doc = new PDFDoc("test.pdf");
doc.InitSecurityHandler();
FDFDoc fdf_doc = new FDFDoc("merge.fdf");
Obj root = fdf_doc.GetRoot();
Obj src_annots = root.Get("FDF").Value().Get("Annots").Value();
// Import the annotaions to destination document.
Obj annots = doc.GetSDFDoc().ImportObj(src_annots, true);
// Now place the annotations on PDF pages.
// In this case we will place all annotations on the first page
int num_annots = annots.Size();
for (int i=0; i<num_annots; ++i) {
// Use 'Page' entry in the annotation dictionary to find the
// destination page number. For example,
Obj annot_dict = annots.GetAt(i);
Obj dst_pg = annot_dict.FindObj("Page");
if (dst_pg != null) {
// Note: in FDF, pages are numbered starting from 0; PDFNet
numbers pages starting from 1.
int page_num = (int) dst_pg.GetNumber() + 1;
...
Page page = doc.GetPage(page_num);
if (page != null) {
page.AnnotPushBack(new Annot(annots.GetAt(i)));
...
}
}
}
}
fdf_doc.Close();
doc.Save("output.pdf", Doc.SaveOptions.e_linearized);
doc.Close();
...