Available starting from PD4ML v4.1.1

7 runnable, self-contained com.pd4ml.pdf.optimizer use-case examples - unreferenced-object cleanup, duplicate-content dedup, encrypted input/output, and error handling.

Package root com.pd4ml.pdf.optimizer.example.usecases Class count 7

1. Running the examples

All examples live under src/test/java/com/pd4ml/pdf/optimizer/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.optimizer.example.usecases.<ClassName> <args...>
Not untested snippets

Every example builds its own small sample PDF in memory (no external fixture files needed) and was actually run end-to-end.

↑ Back to top

2. Example index

#ClassDemonstrates
01Ex01_BasicCleanupThe minimal call: clean up a PDF with real orphaned objects from an incremental-update edit. Start here.
02Ex02_AlreadyCleanIsANoopOptimizing an already-clean document reports zero removed objects - a report, not an assumption.
03Ex03_SharedResourceIsNotDuplicatedTwo pages sharing one font object still share it after optimizing.
04Ex04_EncryptedInputRequiresPasswordOptimizing an encrypted input needs its password; the output is plain by default.
05Ex05_EncryptOutputCleaning a PDF and re-encrypting the output in the same call.
06Ex06_ErrorHandlingPatternsEvery PdfOptimizeException failure mode and how to recognize it.
07Ex07_DuplicateContentDeduplicationTwo originally-distinct but byte-identical font objects are merged into one by default; turning that off with deduplicateContent(false).

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

↑ Back to top

3. See also

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