Available starting from PD4ML v4.1.1

18 runnable, self-contained com.pd4ml.pdf.sign use-case examples - from a minimal invisible signature to visible signatures, PKCS#11/cloud KMS, DocMDP certification, RFC 3161 timestamping, and PAdES-LT.

Package root com.pd4ml.pdf.sign.example.usecases Class count 18 (+ 1 minimal CLI-style sample)

1. Running the examples

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

Every example was compiled against real BouncyCastle classes and, except where noted (live network calls, or a real PKCS#11 token this environment doesn't have), run end-to-end to produce a real signed PDF. Each one builds its own throwaway sample PDF and test certificate in memory, so none of them needs an external file to run.

See also com.pd4ml.pdf.sign.example.SignPdfExample (src/test/java/com/pd4ml/pdf/sign/example/SignPdfExample.java) - the original minimal single-file CLI sample (PKCS#12 + optional TSA only, real files expected), kept for the simplest possible reference.

↑ Back to top

2. Example index

#ClassDemonstrates
01Ex01_InvisibleSigningBasicThe minimal call: PKCS#12 key, invisible signature. Start here.
02Ex02_VisibleSignatureWithTextA visible widget with wrapped text only, built-in Helvetica metrics.
03Ex03_VisibleSignatureWithImageA visible widget with a stamp image (PNG/JPEG) plus a text caption.
04Ex04_DigestAlgorithmChoiceChoosing SHA-256 / SHA-384 / SHA-512; algorithm auto-derived from key type.
05Ex05_RfcTimestampingRFC 3161 trusted timestamp from a TSA, with optional Basic Auth.
06Ex06_DocMdpCertificationLevelsPDF "Certify" at all three DocMDP levels (P=1/2/3).
07Ex07_CoSigningExistingDocumentTwo independent signers on the same (uncertified) document.
08Ex08_Pkcs11HsmSigningSigning with a PKCS#11 hardware token/HSM - key never leaves the token.
09Ex09_CloudKmsSigningThe RemoteSigner seam for cloud KMS (AWS/Azure/GCP), with a real AWS KMS sketch in comments.
10Ex10_CustomPlaceholderSizeSizing the /Contents placeholder for a long chain + timestamp; the resulting error if it's too small.
11Ex11_CustomFieldNameNaming the AcroForm signature field explicitly.
12Ex12_StreamBasedSigningThe three equivalent call shapes: File, InputStream/OutputStream, byte[].
13Ex13_LtvImmediatelyAfterSigningSign, then add PAdES-LT validation info in the same process.
14Ex14_LtvOnExistingSignedPdfAdd LTV to a PDF signed earlier/elsewhere - chain recovered from the CMS itself, no original signing context needed.
15Ex15_ErrorHandlingPatternsEvery PdfSigningException failure mode and how to recognize it.
16Ex16_FullyLoadedCombinedExampleEvery major option combined: visible + certify + timestamp + LTV.
17Ex17_CosInspectionAndPathQueryUsing com.pd4ml.pdf.cos alone (no signing) to parse and COS-path-query a PDF.
18Ex18_ListSignatureFieldsProgrammatically enumerating signature fields and their metadata.

For a ready-made command-line tool covering the same ground without writing any code, see the pd4signcli Reference and run com.pd4ml.pdf.sign.cli.PdfSignCli. For com.pd4ml.pdf.cos alone - inspection, COS-path queries, object listing, and incremental-update editing, with no signing involved - see the pd4coscli Reference (and its own examples) and run com.pd4ml.pdf.cos.cli.CosCli.

↑ Back to top

3. See also

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