Hector
Hector

Reputation: 5344

how to generate PDF XFDF (or FDF) files to add annotations from custom annotation data model

I am developing an Android PDF reader (That is Read Only).

I have external annotations that are defined using a proprietary format as the pdf files they are associated with are consumed both in a web and desktop application.

these web and desktop applications can add, remove, & update annotations where the android companion app can only display annotations.

the annotations are held outside the pdf document with the annotations colour, type, dimensions and location all being defined in a proprietary format.

I would like to be able to import these annotations into their associated pdf document via XFDF format file or a string that contains XFDF formate definitions for annotations.

where can i find the definition for XFDF or FDF files (strings) ?

is there an industry standard library for generating XFDF/FDF files i can employ in my android application to convert from my proprietary annotation format to XFDF format?

Upvotes: 1

Views: 722

Answers (1)

K J
K J

Reputation: 11722

The definitive "Manual" / "User Guide" is https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#page=411

So this text file will on opening (in an Adobe compliant PDF reader)

%FDF-1.4
%âãÏÓ

1 0 obj
<<
/FDF <</Annots [2 0 R 3 0 R]/F (blank.pdf)/UF (blank.pdf)>>/Type /Catalog
>>
endobj

2 0 obj
<<
/C [1 1 0]/Contents (Hello World!)/F 4/M (D:20230301)/NM (12345678-1234-1234-1234567890123456)
/Page 0/Popup 3 0 R
/QuadPoints [36 792 180 792 36 756 180 756]
/RC (<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:10.1.5" xfa:spec="2.1" style="text-align:left;line-height:normal;font-family:Arial;font-size:12pt;font-weight:normal;font-style:normal;text-decoration:none;color:#000000;text-valign:top;">
<p><span>Hello World!</span></p></body>)
/Rect [36 756 180 792]/Subtype /Highlight/Type /Annot
>>
endobj

3 0 obj
<<
/F 28/M (D:20230301)/NM (2ee012cf-1c67-4434-91afce778705a2f4)
/Open true/Page 0/Parent 2 0 R/Rect [48 792 156 840]/Subtype /Popup/Type /Annot
>>
endobj

trailer
<<
/Root 1 0 R
>>
%%EOF

Will be able to draw all these objects.

![enter image description here

If we strip it to the bone its almost as good (OR we could add more for reviewers collaborative historic comments)

%FDF-1.4
%âãÏÓ

1 0 obj
<<
/FDF <</Annots [2 0 R]/F (Jupiter.pdf)/UF (Jupiter.pdf)>>/Type /Catalog
>>
endobj

2 0 obj
<<
/C [1 1 0]/Contents (Hello World!)/F 4/M (D:20230301)/NM (12345678-1234-1234-1234567890123456)
/Page 0/QuadPoints [36 792 180 792 36 756 180 756]/Rect [36 756 180 792]/Subtype /Highlight/Type /Annot
>>
endobj

trailer
<<
/Root 1 0 R
>>
%%EOF

You need both of /QuadPoints [36 792 180 792 36 756 180 756]/Rect [36 756 180 792] to define the workarea and /RECT coloured zone.

Note the points are easier when integers as default 1/72" but can be scaled imperial or metric real units ##.## depending on other transforms

enter image description here

So my quads example could be considered up-side down or Z order but works The Rect is easier to determine as LLx LLy URx URy based on a page Media Origin itself at Lower Left.

enter image description here

Upvotes: 1

Related Questions