com.pd4ml 4.1.2 API Documentation
PD4ML converts HTML and CSS to PDF, DOCX, RTF and raster images from Java applications, servlets and JSP pages, and edits, merges, signs and optimizes existing PDF documents.
Getting started
PD4ML is the converter. Create an instance, set the page format and the
other options, read the HTML with one of its readHTML(...) methods, then write the result
with writePDF(...), writeDOCX(...), writeRTF(...) or
renderAsImages(...):
PD4ML pd4ml = new PD4ML();
pd4ml.setPageSize(PageSize.A4);
pd4ml.setPageMargins(new PageMargins(36, 36, 36, 36)); // left, top, right, bottom in points
pd4ml.setHtmlWidth(950); // the virtual browser width in pixels
pd4ml.readHTML(new URL("https://example.com/page.html"));
try (OutputStream out = new FileOutputStream("result.pdf")) {
pd4ml.writePDF(out);
}
A PD4ML instance converts one document at a time; use one instance per thread.
Main classes
PD4ML- The converter: page format and margins, fonts (
PD4ML.useTTF(java.lang.String)), headers and footers, bookmarks, security, PDF/A and PDF/UA output, and the output to PDF, DOCX, RTF or images. PageSize,PageMargins,Dimensions- Page formats, margins and units.
Constants- Permission flags, parameter names, error policies and the other constants the API takes.
PdfSpec- The PDF version and the standards (PDF/A, PDF/UA, ZUGFeRD, Factur-X) the output conforms to.
PdfDocument- An existing PDF document: merge, overlay, page operations and saving.
ResourceProvider- Loads the images, style sheets and fonts of a document from places PD4ML does not reach by itself (a database, an application's own storage).
ProgressListener- Receives progress messages of a conversion
(
PD4ML.monitorProgressWith(com.pd4ml.ProgressListener)). CustomTag- Renders application-defined HTML tags; the built-in ones (SVG, MathML, QR codes) are in
com.pd4ml.plugins.
PDF tools
The com.pd4ml.pdf packages work on existing PDF files, independently of the converter:
com.pd4ml.pdf.merge- Combines page ranges of several PDF files into one document (
PdfMerger). com.pd4ml.pdf.sign- Digital signatures (PAdES-compatible CMS), visible signature fields, remote signing keys, and
long-term validation data (
PdfSigner). com.pd4ml.pdf.optimizer- Removes unreachable objects and rewrites a PDF compactly (
PdfOptimizer). com.pd4ml.pdf.xfdf- Exports and imports annotations and form field values as XFDF.
com.pd4ml.pdf.cos- The low-level PDF object model all of them are built on: parsing, COS path queries, encryption and incremental updates.
Command-line tools
Pd4Cmd is the Main-Class of pd4ml.jar
(java -jar pd4ml.jar <url> <htmlWidth>); each PDF tool has a command-line entry point of
its own in its cli package.
More documentation
- PD4ML Programmer's Manual
- Usage examples
- Pd4Cmd command-line reference
- PDF tools manuals
- PD4ML v3 API (the
org.zefer.pd4mlAPI, still shipped for compatibility) and the v3 to v4 migration guide
| Package | Description |
|---|---|
| com.pd4ml |
The PD4ML converter API:
PD4ML turns HTML and CSS into PDF, DOCX, RTF or raster images; PdfDocument works on existing PDF documents. |
| com.pd4ml.pdf |
The base of
PdfDocument: an existing PDF document that can be inspected, changed and saved. |
| com.pd4ml.pdf.cos |
The PDF object model (COS): arrays, dictionaries, names, numbers, strings, streams and indirect references, and
COSDocument, the whole document. |
| com.pd4ml.pdf.cos.cli |
The command-line entry point of the COS API: inspects PDF files, evaluates COS paths and edits objects.
|
| com.pd4ml.pdf.cos.filter |
Stream filters for reading PDF streams: FlateDecode, ASCIIHexDecode and ASCII85Decode.
|
| com.pd4ml.pdf.cos.parser |
Parses a PDF file into a
COSDocument: its objects, cross-reference tables and streams. |
| com.pd4ml.pdf.cos.path |
COS paths: a compact syntax for addressing an object in a PDF document, like
/Root/Pages/Kids[0], and its evaluator. |
| com.pd4ml.pdf.cos.security |
Decrypting and encrypting COS documents with the PDF standard security handler.
|
| com.pd4ml.pdf.cos.util |
Helpers for working with COS documents: page tree and outline navigation, inheritable page attributes, number trees, PDF dates, and copying objects between documents.
|
| com.pd4ml.pdf.cos.writer |
Writes COS documents: complete PDF files, and incremental updates appended to an existing file.
|
| com.pd4ml.pdf.encryption |
PDF encryption: the standard (password) and public-key security handlers, protection policies and access permissions.
|
| com.pd4ml.pdf.merge |
Merging PDF files:
PdfMerger combines page ranges of several documents into one, keeping bookmarks, links and tagged structure. |
| com.pd4ml.pdf.merge.cli |
The command-line entry point of the merge API.
|
| com.pd4ml.pdf.optimizer |
Optimizing PDF files:
PdfOptimizer drops unreachable objects and rewrites a document compactly. |
| com.pd4ml.pdf.optimizer.cli |
The command-line entry point of the optimizer API.
|
| com.pd4ml.pdf.overlay |
Overlay and underlay: places pages of one PDF document over or under pages of another (see
PdfDocumentBase). |
| com.pd4ml.pdf.sign |
Signing PDF files:
PdfSigner applies PAdES-compatible digital signatures, visible or invisible, with local or remote (RemoteSigner) keys. |
| com.pd4ml.pdf.sign.cli |
The command-line entry point of the signing API.
|
| com.pd4ml.pdf.sign.ltv |
Long-term validation (PAdES-LT): fetches OCSP responses and CRLs and adds them to a signed PDF.
|
| com.pd4ml.pdf.sign.pdf |
The low-level signing mechanics: a signature applied as an incremental update over the signed byte ranges.
|
| com.pd4ml.pdf.xfdf |
XFDF (ISO 19444-1): exports a PDF document's annotations and form field values to XFDF, and imports them from it.
|
| com.pd4ml.pdf.xfdf.cli |
The command-line entry point of the XFDF API.
|
| com.pd4ml.plugins |
Built-in custom tags: SVG (Batik and the built-in renderer), MathML and QR codes, registered with
PD4ML.addCustomTagHandler(java.lang.String, com.pd4ml.CustomTag). |
| com.pd4ml.tools |
Command-line tools:
Pd4Cmd, the Main-Class of pd4ml.jar, converts documents, edits PDF files, indexes fonts and starts the previewer. |