Class XfdfExporter
- java.lang.Object
-
- com.pd4ml.pdf.xfdf.XfdfExporter
-
public final class XfdfExporter extends java.lang.ObjectExports a PDF's markup annotations and AcroForm field values to an XFDF document (ISO 19444-1) -- built entirely on the pd4mlcom.pd4ml.pdf.cosobject model/parser (no PDFBox, no other PDF library), the same foundationcom.pd4ml.pdf.sign,com.pd4ml.pdf.mergeandcom.pd4ml.pdf.optimizerare built on.Every page's
/Annotsentries whose/SubtypeXFDF has an element for (seeAnnotationMapper's class documentation for the full list and its documented v1 scope boundaries) are exported under<annots>, and every non-signature terminal/AcroFormfield's current value is exported under<fields>(seeFieldMapper). AWidgetannotation 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 matchingFile/InputStreamoverload); 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)andXfdfExporter.Options.ids(String)are for; see their own documentation for the exact matching rules. Both are optional and independent of each other.Thread-safety:
XfdfExporterholds no state at all (every method isstatic); callexport(...)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 classXfdfExporter.OptionsExport-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 voidexport(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 voidexport(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)
-
-
-
Method Detail
-
export
public static byte[] export(byte[] pdfBytes) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(byte[] pdfBytes, java.lang.String password) throws XfdfExceptionConvenience for the common case of only needing a password, with no type/ID filtering.- Throws:
XfdfException
-
export
public static byte[] export(byte[] pdfBytes, XfdfExporter.Options options) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.File pdfFile) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.File pdfFile, java.lang.String password) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.File pdfFile, XfdfExporter.Options options) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.InputStream in) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.InputStream in, java.lang.String password) throws XfdfException- Throws:
XfdfException
-
export
public static byte[] export(java.io.InputStream in, XfdfExporter.Options options) throws XfdfException- Throws:
XfdfException
-
export
public static void export(byte[] pdfBytes, XfdfExporter.Options options, java.io.OutputStream out) throws XfdfExceptionConvenience for writing straight to a destination rather than handling the returned bytes yourself.- Throws:
XfdfException
-
export
public static void export(java.io.File pdfFile, XfdfExporter.Options options, java.io.File xfdfOutputFile) throws XfdfException- Throws:
XfdfException
-
-