Class XfdfExporter


  • public final class XfdfExporter
    extends java.lang.Object
    Exports a PDF's markup annotations and AcroForm field values to an XFDF document (ISO 19444-1) -- built entirely on the pd4ml com.pd4ml.pdf.cos object model/parser (no PDFBox, no other PDF library), the same foundation com.pd4ml.pdf.sign, com.pd4ml.pdf.merge and com.pd4ml.pdf.optimizer are built on.

    Every page's /Annots entries whose /Subtype XFDF has an element for (see AnnotationMapper's class documentation for the full list and its documented v1 scope boundaries) are exported under <annots>, and every non-signature terminal /AcroForm field's current value is exported under <fields> (see FieldMapper). A Widget annotation is exported only through its field's value, never as its own <annots> entry -- matching how real XFDF producers use the format.

    Encrypted input is supported the same way every other pd4ml PDF feature supports it: pass the user or owner password to export(byte[], String) (or the matching File/ InputStream overload); the COS reader decrypts transparently while parsing, so annotation and field extraction afterwards works exactly as it would on a plain PDF. An empty/omitted password still works for a document that's encrypted with only an owner password (the common "restrict editing, not reading" case).

    Selecting a subset to export -- rather than every annotation and field -- is what XfdfExporter.Options.types(String) and XfdfExporter.Options.ids(String) are for; see their own documentation for the exact matching rules. Both are optional and independent of each other.

    Thread-safety: XfdfExporter holds no state at all (every method is static); call export(...) freely and concurrently from any number of threads.

    Example

    
     byte[] xfdf = XfdfExporter.export(pdfBytes);
     Files.write(Paths.get("annotations.xfdf"), xfdf);
    
     // Only this reviewer's highlights and one specific sticky note:
     XfdfExporter.Options options = new XfdfExporter.Options()
             .types("highlight")
             .ids("4689ceaa1bf2862a-67c011b0fe95d2aa");
     byte[] subset = XfdfExporter.export(pdfBytes, options);
     
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  XfdfExporter.Options
      Export-time settings: the input password, and an optional type/ID subset to export.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] export​(byte[] pdfBytes)  
      static byte[] export​(byte[] pdfBytes, XfdfExporter.Options options)  
      static void export​(byte[] pdfBytes, XfdfExporter.Options options, java.io.OutputStream out)
      Convenience for writing straight to a destination rather than handling the returned bytes yourself.
      static byte[] export​(byte[] pdfBytes, java.lang.String password)
      Convenience for the common case of only needing a password, with no type/ID filtering.
      static byte[] export​(java.io.File pdfFile)  
      static byte[] export​(java.io.File pdfFile, XfdfExporter.Options options)  
      static void export​(java.io.File pdfFile, XfdfExporter.Options options, java.io.File xfdfOutputFile)  
      static byte[] export​(java.io.File pdfFile, java.lang.String password)  
      static byte[] export​(java.io.InputStream in)  
      static byte[] export​(java.io.InputStream in, XfdfExporter.Options options)  
      static byte[] export​(java.io.InputStream in, java.lang.String password)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait