Available starting from PD4ML v4.1.1

8 runnable, self-contained com.pd4ml.pdf.cos use-case examples - parsing, COS-path queries, incremental-update editing, encrypted PDFs, filters, and building a PDF from scratch, no signing involved.

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

1. Running the examples

All examples live under src/test/java/com/pd4ml/pdf/cos/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.cos.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_ParsingAndCatalogThe minimal call: parse a PDF, walk trailer to Root (the Catalog). Start here.
02Ex02_CosPathQueriesThe COS-path query language: /Root/..., [N] array indexing, evaluate vs. evaluateStrict.
03Ex03_ListingObjectsAndPagesEnumerating every indirect object, and walking the page tree by index.
04Ex04_IncrementalUpdateEditingEditing an existing PDF as a real incremental update via IncrementalUpdateWriter - the same mechanism signing and LTV build on.
05Ex05_ReadingEncryptedPdfReading an encrypted PDF: transparent decryption once given the right password.
06Ex06_FiltersAndDecodedStreamsCOSStream.getDecodedBytes()/isFullyDecodable() and the /Filter chain.
07Ex07_BuildingAndWritingADocumentFromScratchBuilding a PDF entirely from the COS object model, then serializing it with COSDocumentWriter - no template, no other library.
08Ex08_ErrorHandlingAndRecoveryCOSParseException for genuinely unparseable input, versus the brute-force recovery scan for a corrupt-but-recoverable one.

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

↑ Back to top

3. See also

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