Hello
After reviewing the code and also the content of the resulting PDF I
suspect that the problem comes from the "conversion" from an
FDFAnnotation into a PDAnnotation.
Currently in my createPDAnnotations method I use following call to make
this conversion:
PDAnnotation.createAnnotation(fdfAnnotation.getCOSObject());
In the PDF I see that for example the FDF annotation:
<underline page="0" color="#000000" date="D:20131210135518+00'00'"
rect="155.300000,553.230000,188.470000,563.370000" flags="print"
name="00C9AC47-D600-4D45-9696-30B35016664C" opacity="1" rotation="0"
coords="155.300000,563.370000,188.470000,563.370000,155.300000,553.230000,188.470000,553.230000"/>
is converted into the following object:
16 0 obj
<<
/Type /Annot
/Page 0
/color [0.0 0.0 0.0]
/date (D:20131210135518+00'00')
/F 4
/NM ()
/Rect [155.3 553.23 188.47 563.37]
/CA 1.0
/Subj ()
/Subtype /Underline
>>
Which does not seem to be complete... (Please also note that with this
call every FDFAnnotation (highlight, strikeout, text, ...) is translated
with a /Subtype /Underline!)
I've also tried using the matching PDAnnotation subclasses for doing
this conversion:
if (fdfAnnotation instanceof FDFAnnotationLine)
{
pdAnnotation =
PDAnnotationLine.createAnnotation(fdfAnnotation.getCOSObject());
}
else if (fdfAnnotation instanceof FDFAnnotationSquare ||fdfAnnotation
instanceof FDFAnnotationCircle)
{
pdAnnotation =
PDAnnotationSquareCircle.createAnnotation(fdfAnnotation.getCOSObject()));
}
...
But the result does not better.
Do you have any suggestion how I should proceed?
Thanks for your support and best regards,
Patrick
On 12/11/2013 03:49 PM, Patrick Herber wrote:
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