Available starting from PD4ML v4.1.1

8 runnable, self-contained com.pd4ml.pdf.xfdf use-case examples - export/import round trips, the update-if-exists switch, form fields, type/ID filtering, and post-import encryption/optimization.

Package root com.pd4ml.pdf.xfdf.example.usecases Class count 8

1. Running the examples

All examples live under src/test/java/com/pd4ml/pdf/xfdf/example/usecases/ (test scope - not shipped in the distributed jar) and are ordinary runnable classes with a main(String[] args). Easiest from an IDE: right-click the class, Run. From the command line:

$ mvn test-compile
$ mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
$ java -cp "target/test-classes;target/classes;$(cat cp.txt)" \
     com.pd4ml.pdf.xfdf.example.usecases.<ClassName> <args...>
Not untested snippets

Every example builds its own small sample PDF(s) in memory (via com.pd4ml.examples.support.SamplePdf, no external fixture files needed) and was actually run end-to-end.

↑ Back to top

2. Example index

#ClassDemonstrates
01Ex01_BasicExportAndImportThe minimal round trip: export a PDF's annotations to XFDF, then import that XFDF into a different PDF. Start here.
02Ex02_InspectingTheParsedModelXfdfReader.read(...) turns XFDF bytes into a plain XfdfDocument/XfdfAnnotation model you can inspect directly.
03Ex03_UpdateIfExistsSwitchOptions.updateIfExists(boolean) - update a matching annotation in place vs. always adding a new one.
04Ex04_FormFieldValuesForm field values travel through <fields>, only ever updating an existing AcroForm field - including checkbox /AS sync.
05Ex05_TypeAndIdFilteringOptions.types(String)/ids(String) restrict export or import to a comma-separated subset.
06Ex06_EncryptedSourceExportExporting from an encrypted PDF - transparent decryption via the password overload.
07Ex07_PostImportOptimizeAndEncryptOptions.optimizeOutput(boolean) + encryptOutput(...) chained after an import.
08Ex08_ErrorHandlingPatternsEvery XfdfException failure mode and how to recognize it.

For a ready-made command-line tool covering the same ground without writing any code, see the pd4xfdfcli Reference and run com.pd4ml.pdf.xfdf.cli.Pd4XfdfCli.

↑ Back to top

3. See also

↑ Back to top
PD4ML XFDF Examples · Java 1.8 · com.pd4ml.pdf.xfdf.example.usecases · no third-party PDF dependency