Optional Document Handlers

THPDFDocumentHandlerRegistry selects replaceable handlers by inspected content before weak extension or MIME hints, then converts the selected source into one immutable PDF cache shared by export and rendering

Built-in optional handlers

Budgets and failure isolation

One validated ZIP central-directory scan enforces entry, compressed-byte, expanded-byte, per-entry, duplicate-path, unsafe-path, and compression-ratio limits before conversion

Classic PKZIP ZipCrypto entries can request credentials through ArchivePasswordCallback; the callback receives the source name, entry name, and one-based attempt number, while MaxPasswordAttempts bounds retries from 1 through 16

Credentials and partially decoded entry bytes remain in memory and are cleared between attempts, cancellation is checked before and after every callback, and missing callbacks, declined credentials, exhausted retries, or unsupported encryption fail closed

ZipCrypto is legacy password protection rather than modern authenticated encryption, and non-ASCII password byte conventions can vary between ZIP producers

Password-protected entries need Delphi 12 or later, whose System.Zip exposes the decryption hook; built with an earlier Delphi version, the handlers still read unencrypted entries but reject encrypted ones as unsupported before ArchivePasswordCallback is called

Entries whose sizes or offsets need ZIP64 fields require Delphi 11 or later; earlier Delphi versions reject them as unsupported

Resource, reflow, page, pixel, DPI, output, and cancellation limits remain active throughout conversion and rendering, while failed output publication restores a seekable destination stream

Registration and use

var
  Registry: THPDFDocumentHandlerRegistry;
  Options: THPDFDocumentHandlerOptions;
  Handled: IHPDFHandledDocument;
  Info: THPDFDocumentHandlerInfo;
begin
  Registry:= THPDFDocumentHandlerRegistry.Create;
  try
    Registry.RegisterStandardHandlers;
    Options:= THPDFDocumentHandlerOptions.Default;
    Options.ArchivePasswordCallback:= SupplyArchivePassword;
    if Registry.OpenFromFile('book.epub', '', Options, Handled, Info) then
      Handled.WritePDF(OutputStream, Options, Info);
  finally
    Registry.Free;
  end;
end;

Related APIs