Hello
I'm trying to use PDFBox for importing annotations from an XFDF file
into a PDF Document.
I found the class ImportXFDF which seemed appropriate but discovered
that was "only" able to import fields (AcroForm). I also find some other
limitation in other classes (FDFAnnotation, FDFDicionary) which were
only able to deal with text annotations.
I allowed myself to integrate into the ImportXFDF's importFDF method
also the capability to import annotations (in case it will work I will
also send you all the changes I've done in this and in the other classes):
...
List<FDFAnnotation> fdfAnnotations =
fdfDocument.getCatalog().getFDF().getAnnotations();
if ( fdfAnnotations != null)
{
Map<Integer, List<PDAnnotation>> pdAnnotations =
createPDAnnotations(fdfAnnotations);
List<PDPage> pages =
pdfDocument.getDocumentCatalog().getAllPages();
for ( int i = 0; i < pages.size(); i++ )
{
List<PDAnnotation> annotations = pdAnnotations.get(i);
if ( annotations != null )
{
pages.get(i).setAnnotations(annotations);
}
}
}
...
At the end of this method the pdfDocument pages are filled with the
relative annotations. However, if I perform a test in the output file
there is no annotation:
PDDocument pdfDocument = PDDocument.load(pdfFile);
FDFDocument fdfDocument = FDFDocument.loadXFDF(xfdfFile);
ImportXFDF importFDF = new ImportXFDF();
importFDF.importFDF(pdfDocument, fdfDocument);
pdfDocument.save(new FileOutputStream(dest));
I wonder therefore, if I'm proceeding in the right way. Is this the
correct way to modify the content of the document pages (in this case
adding annotations)?
Thanks for your support and best regards,
Patrick