PDF Filter Support

Overview

PDF streams and embedded images identify their encoding through filter names. HotPDF primarily works with the following filter families when generating documents or decoding external content.

Common Filters

  • FlateDecode: Main compression filter for generated streams and the primary zlib-based decompression path
  • LZWDecode: Supported for legacy and compatibility scenarios through HPDFLZW.pas
  • DCTDecode: Used for standard JPEG image data handled by HotPDF image loading paths
  • CCITTFaxDecode: Common in monochrome TIFF and fax-style image data
  • ASCIIHexDecode / ASCII85Decode / RunLengthDecode: Encoder helpers exposed in HPDFTypes.pas (_ASCIIHexEncode, _ASCII85Encode, _RunLengthEncode) since HotPDF v2.4.0. Useful when wrapping arbitrary binary content for 7-bit channels or for explicit PDF 1.7 7.4 round-trip support
  • JBIG2Decode / JPXDecode: Filter names defined by PDF 1.7 7.4.7 / 7.4.9. HotPDF's bundled JBIG2 and JPEG 2000 helpers are stubs that report unsupported (return False) until a real OpenJPEG / JBIG2 backend is linked. Earlier builds returned a fake 100×100 success which produced unreadable images; this is now corrected

Practical Notes

  • Not every filter is exposed through a single generic API; some are reached through dedicated image or stream helper units
  • For generated PDF content, THotPDF.Compression remains the central user-facing setting
  • When loading external data, the applicable filter depends on the source file format and the helper class being used
  • Encrypted PDFs combine these filters with the security handler; see CryptKeyLength for the supported AES‑128 (V=4 R=4 / CFM=AESV2) and RC4 (V=1/V=2) options
  • Interactive form fields are emitted as Widget annotations that the viewer paints; see AcroForm Support
  • Text-markup annotations (Highlight, Underline, Squiggly, StrikeOut) and intra-document jump links (GoTo, GoToR, Launch) are exposed as new THPDFPage.Add*Annotation / AddGoToLink / AddGoToRLink / AddLaunchLink methods since HotPDF v2.6.0
  • DeviceCMYK output is available through THPDFPage.SetCMYKColor / SetCMYKFillColor / SetCMYKStrokeColor; ICC-managed colour spaces are registered with THotPDF.RegisterICCProfile and applied via SetFillColorSpace / SetStrokeColorSpace + SetFillColor / SetStrokeColor since HotPDF v2.7.0
  • Set THotPDF.UseXRefStream to true before saving to emit a single /Type /XRef FlateDecode-compressed cross-reference stream instead of the textual xref / trailer / startxref sequence (PDF 1.7 7.5.8); available since HotPDF v2.8.0
  • Set THotPDF.EnableXMPMetadata to true to attach an XMP /Type /Metadata /Subtype /XML stream to the Catalog (PDF 1.7 14.3.2); auto-built from the Info dict fields, or supply a hand-authored packet via CustomXMP. Available since HotPDF v2.9.0
  • Per-method PDF version gating (since HotPDF v2.24.0). Every feature method introduced in v2.4.0+ consults RequirePDFVersion before emitting; with StrictVersionLock=false (the default) the document Version is silently auto-bumped to the minimum the feature requires, and with StrictVersionLock=true the call is refused so the saved file strictly conforms to the chosen 1.3 / 1.4 / 1.5 / 1.6 / 1.7 reference spec.
  • PNG and TIFF predictor encoders for FlateDecode-compressed image data (PDF 1.7 7.4.4.4): _PNGPredictorEncode applies the libpng minimum-absolute-difference filter heuristic (Predictor=15), _TIFFPredictor2Encode applies horizontal differencing (Predictor=2). Available since HotPDF v2.10.0
  • Tagged PDF entry points (PDF 1.7 14.7-14.8): THotPDF.Lang populates /Lang in the Catalog, EnableTaggedPDF emits /MarkInfo <</Marked true>> and a stub /StructTreeRoot, and the new THPDFPage.BeginMarkedContent / BeginMarkedContentMCID / EndMarkedContent methods write the BMC / BDC / EMC content-stream operators. Available since HotPDF v2.11.0
  • Axial and radial gradients (PDF 1.7 7.10 / 8.7): THotPDF.RegisterAxialGradient / RegisterRadialGradient build the full Function Type 2 / Shading Type 2-3 / Pattern Type 2 stack and return a stable pattern name; THPDFPage.SetFillPattern / SetStrokePattern install it onto the page. Component count of the start / end colour selects DeviceGray (1) / DeviceRGB (3) / DeviceCMYK (4). Available since HotPDF v2.13.0; multi-stop axial gradients via Function Type 3 are exposed through RegisterMultiStopAxialGradient since v2.18.0
  • Inline images (PDF 1.7 8.9.7) via THPDFPage.DrawInlineImage; raw bytes are auto-wrapped with ASCIIHex when no Filter is supplied so the content stream stays 7-bit-clean. Available since HotPDF v2.18.0
  • OutputIntents (PDF 1.7 14.11) via THotPDF.AddOutputIntent; each call appends a /Type /OutputIntent dict to the Catalog with optional /DestOutputProfile referencing a registered ICC profile. Available since HotPDF v2.18.0
  • AcroForm appearance-stream auto-generation (PDF 1.7 12.5.5 / 12.7.3.3 / 8.10): set THotPDF.AutoFormAppearances to true before adding interactive form fields and HotPDF will pre-build a /Subtype /Form Form XObject for each widget's /AP /N entry (Yes / Off sub-dicts for buttons), populate the AcroForm /DR default resources with Helvetica / ZapfDingbats indirect font dicts, and switch /NeedAppearances to false so renderers honour the embedded streams. Available since HotPDF v2.28.0
  • ViewerPreferences /ViewArea and /ViewClip (PDF 1.4 12.2 Table 152) are now exposed through THotPDF.ViewArea / THotPDF.ViewClip properties (with the matching vpViewArea / vpViewClip set members). Both accept the THPDFPageBoundary values (MediaBox / CropBox / BleedBox / TrimBox / ArtBox) and complete HotPDF's coverage of the four PDF 1.4 page-boundary ViewerPreferences. Available since HotPDF v2.29.0
  • Page transitions (PDF 1.1 / 1.5 12.4.4): THPDFPage.SetPageTransition writes a /Trans dictionary on the page so PDF readers in /PageMode /FullScreen animate navigation. PDF 1.1 styles (Split, Blinds, Box, Wipe, Dissolve, Glitter, R) and PDF 1.5 styles (Fly, Push, Cover, Uncover, Fade) are exposed through the THPDFTransitionStyle enumeration; companion /Dm, /M and /Di sub-options are also exposed. THPDFPage.SetPageDuration writes the /Dur auto-advance delay in seconds. Available since HotPDF v2.30.0
  • Page-level transparency group (PDF 1.4 11.6.6 / 7.5.5): THPDFPage.SetTransparencyGroup attaches a /Group dictionary (/Type /Group /S /Transparency) so renderers composite alpha-bearing content predictably. Choose a device colour space through the THPDFGroupColorSpace enumeration (DeviceGray / DeviceRGB / DeviceCMYK or omit), or call THPDFPage.SetTransparencyGroupICC with the name of an ICC profile previously registered through THotPDF.RegisterICCProfile. Optional /I (Isolated) and /K (Knockout) flags steer the compositor; THPDFPage.ClearTransparencyGroup removes a previously-attached entry. Available since HotPDF v2.32.0
  • Incremental update (PDF 1.7 ISO 32000-1 7.5.6): THotPDF.BeginIncrementalUpdate(SourceFile) loads an existing PDF in append-only mode; subsequent CreateIndirect* calls auto-mark new objects dirty, and THotPDF.MarkDirty(Obj) tags pre-existing loaded objects for re-emission. THotPDF.SaveIncrementalUpdate(TargetFile) writes the original source bytes verbatim, appends only dirty objects with their object numbers preserved, emits a new xref subsection, and finishes with a trailer carrying /Prev pointing at the previous xref. Combine with the existing AddSignedSignatureField + PreparePDFForSigning + InsertSignatureHex pipeline to add subsequent signature fields to an already-signed document without invalidating earlier signatures (their /ByteRange digests remain valid because none of the original bytes mutate). Available since HotPDF v2.35.0
  • Embedded TrueType font-name normalization: HotPDF reads the embedded TrueType name table and aligns /BaseFont, /FontDescriptor /FontName, /FontFamily, and descendant CID font names with the font program's PostScript name. This avoids Adobe Acrobat Font Capture failures caused by a mismatch between the PDF font dictionary and the embedded TTF payload. Available since HotPDF v2.35.1
  • TrueType font subsetting (PDF 1.7 ISO 32000-1 9.6.4 / 9.8.2): set THotPDF.EnableFontSubsetting to true before BeginDoc and HotPDF rebuilds the embedded TrueType payload to contain only the glyphs actually used by the document. Typical Latin documents see ~90% reduction in embedded font weight (1 MB Arial -> ~70 KB on a one-line "Hello, world."). Composite-glyph dependencies are tracked recursively, GID numbering is preserved (so existing Type0 / Identity-H content streams keep working), and the new /BaseFont automatically gains the spec-mandated six-letter "+"-suffixed prefix (e.g. /BaseFont /AAAAAA+ArialMT). Off by default; enable opt-in to keep full-font embedding for editing workflows. Available since HotPDF v2.36.0
  • Compact Font Format (CFF) subsetter (PDF 1.7 ISO 32000-1 9.7.4 / 9.9): companion to the TrueType subsetter for OpenType-CFF (.otf, sfntVersion OTTO) and Type 1 / Type 1C fonts. The unit-exported HPDFSubsetCFF(CFFBytes, KeepGlyph) function rebuilds the CharStrings INDEX with un-kept glyphs replaced by the minimal 1-byte endchar stub, preserving GID numbering byte-for-byte. Available since HotPDF v2.37.0.
  • OpenType-CFF (.otf) embed path wired into StoreFont (PDF 1.6+ 9.7.4 Table 117). When the GDI-loaded font binary is an sfnt OTTO container, HotPDF subsets the embedded 'CFF ' sub-table through HPDFSubsetOTFContainer, emits the font program via /FontFile3 /Subtype /OpenType, and writes the descendant font dictionary with /Subtype /CIDFontType0 instead of /CIDFontType2. TrueType fonts continue through the existing /FontFile2 + /CIDFontType2 path with no behavior change. Available since HotPDF v2.38.0.
  • CFF subroutine subsetting end-to-end (PDF 1.7 9.7.4 §6 / Adobe Tech Note #5177 §3.1): the CFF subsetter now strips unused entries from BOTH the Global Subr INDEX (located immediately after String INDEX in the CFF binary) and the Local Subr INDEX (nested under Private DICT, reached via Top DICT operator 18 + Private DICT operator 19). A single fixed-point closure follows callsubr (op 0x0A) AND callgsubr (op 0x1D) chains transitively, so a CharString that calls a Local Subr that calls a Global Subr that calls another Local Subr is picked up in one iteration. Each unused entry is replaced by a 1-byte return stub and the INDEX is rewritten in place with the trailing slack zero-filled. This behavior is exposed through the public HPDFSubsetCFF and HPDFSubsetOTFContainer helpers; lower-level CFF scanners remain internal. Available since HotPDF v2.39.0.
  • CID-keyed CFF subsetting (PDF 1.7 ISO 32000-1 9.7.4 / Adobe Tech Note #5176 §18-19): the CFF subsetter now recognises the Top DICT ROS operator (12-30) that marks a CID-keyed OpenType-CFF font and walks the FDArray (12-36) INDEX of Font DICTs, each carrying its own Private DICT + Local Subr INDEX. The FDSelect (12-37) glyph-to-FD map is preserved byte-for-byte. The subroutine-closure scan tracks each kept CharString's FD context so a glyph in FD #5 marks Local Subrs in FD #5 only - global subrs remain shared across FDs. Each FD's Local Subr INDEX is rewritten in place with unused entries collapsed to 1-byte return stubs. CJK / Indic / Arabic OTF fonts (Adobe Fan/Gothic/Heiti/Ming/Myungjo/Song Std, Kozuka Pr6N, Source Han Sans, etc.) now go through the full subsetting pipeline instead of being embedded as-is. Available since HotPDF v2.40.0.
  • Annotation border style and Popup linkage (PDF 1.7 12.5.4 / 12.5.6.14): THPDFPage.SetAnnotationBorderStyle(Annot, Width, Style, DashPattern) attaches a /BS dictionary with the chosen THPDFAnnotBorderStyle (absSolid / absDashed / absBeveled / absInset / absUnderline). THPDFPage.AddPopupAnnotationFor(ParentAnnot, Rect, Open) emits a /Popup annotation that is wired in both directions (parent /Popup -> popup, popup /Parent -> parent) so the viewer can render the speech-balloon connector. The new THPDFPage.LastAnnotation property feeds either helper without changing the signature of the existing Add*Annotation procedures. Available since HotPDF v2.34.0
  • Public-Key Security Handler (PDF 1.7 7.6.5): THotPDF.EnablePubKeyEncryption(seed, KeyType, EncryptMetadata) + THotPDF.AddPubKeyRecipient(envelope) emit a /Filter /Adobe.PubSec encrypt dictionary (/SubFilter /adbe.pkcs7.s4 for V=1 RC4-40 / /adbe.pkcs7.s5 for V=2 RC4-128 / V=4 AESV2). Caller supplies the 20-byte random seed and one PKCS#7 envelopedData binary blob per recipient (built externally with Windows CryptoAPI, OpenSSL, or pycryptodome). HotPDF derives the file encryption key through algorithm 9 (SHA-1 of seed concatenated with each envelope) and reuses the standard per-object key derivation for AES-128 / RC4 streams. Available since HotPDF v2.33.0

See Also