Parsing XFDF Annotations

383 views
Skip to first unread message

Thorsten Hersam

unread,
Jun 6, 2018, 12:09:29 PM6/6/18
to PDFTron WebViewer
Hi,

I am using the WebViewer to display PDFs. Using the annotationManager.exportAnnotations() method I am able to create a XFDF String of the annotations create in the PDF by the user. I now would like to send this XFDF String to my server and process it.
Is there any parsing tool for XFDF? Or can you provided an XSD for XFDF Annotations?

I am looking forward to your reply.


Kind regards,

Thorsten

Matt Parizeau

unread,
Jun 7, 2018, 2:55:30 PM6/7/18
to PDFTron WebViewer
Hi Thorsten,

XFDF is just XML so you can use any XML parsing library on your server. What are you trying to achieve by parsing the XFDF? PDFNet has APIs that allow you to merge the XFDF into a PDF document which might be good enough depending on what you're looking for.


Matt Parizeau
Software Developer
PDFTron Systems Inc.

Thorsten Hersam

unread,
Jun 8, 2018, 1:50:00 PM6/8/18
to PDFTron WebViewer
Hi Matt,

I want to save annotations of individual users for the same identical PDF. Therefore I cannot acutally save the annotations to the PDF. 
My usecase is export annotations as XFDF send the XML to a server, parse the XML to create persistable objects, persist these objects into a database. Upon the next visit of the user the user's annotations are loaded from the database, marschalled into XML an send to the Client in order to be imported into the PDFTron WebViewer.

I managed to successfully establish this roundtrip by parsing the XFDF XML with a custom xsd. However it would probably be more reliable if there was an official xsd.
Do you know of any official xsd?

Kind regards,

Thorsten

Matt Parizeau

unread,
Jun 8, 2018, 2:50:34 PM6/8/18
to PDFTron WebViewer
Hi Thorsten,


One thing to note is that we've found it's not uncommon for Acrobat to output attributes that aren't in the XFDF spec so there may be attributes that WebViewer or other PDF libraries output that aren't in the xsd. Also note that WebViewer adds some custom elements to the XFDF for widgets, though these aren't generally user creatable so it may not be a problem for you. We don't have an xsd for the widgets.

Another option is to save the XFDF as a string to persist in the database so not much parsing would be necessary (possibly just username and id), though this is up to your requirements.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Thorsten Hersam

unread,
Jun 13, 2018, 1:19:39 PM6/13/18
to PDFTron WebViewer
Thank you!

It works for me. Only thing that needed to be adapted is
<xs:group name="value.group.type">
   
<xs:all>
       
<xs:element name="value" type="value.elem.type" minOccurs="0"/>
       
<xs:element name="value-richtext" type="richtext.elem.type" minOccurs="0"/>
   
</xs:all>
</xs:group>

into 
<xs:group name="value.group.type">
   
<xs:sequence>
       
<xs:element name="value" type="value.elem.type" minOccurs="0"/>
       
<xs:element name="value-richtext" type="richtext.elem.type" minOccurs="0"/>
   
</xs:sequence>
</xs:group>

because "xs:all" does not allow nested hierarchies. JAXB would not parse with the original XSD but it does with this adaptation. However, I am not using this part. Therefore I do not know if it is correct.

Thorsten
Reply all
Reply to author
Forward
0 new messages