PDFiumPas Docs

FPdfReport

Available in every edition since 3.266.0

Shared report utilities provide explicit serialization budgets, escaped JSON/HTML text, exact-byte hashes and bounded stream snapshots without loading PDFium

APIBehavior
TPdfReportLimits.DefaultAllows 4194304 serialized UTF-8 bytes and 65536 logical items; the conservative byte ceiling is configured by MaxCharacters and the logical-item ceiling by MaxItems
TPdfReportWriterDestroy frees the internal buffer, or a destination stream only when the writer owns it; JsonText escapes UTF-16 code units, including supplementary-character pairs; HtmlText escapes markup and emits Unicode character references
JsonString / HtmlStringAccept native Pascal strings, interpreting Free Pascal strings as UTF-8
ReflowTextStreams escaped Unicode text, normalizing line endings to spaces or explicit <br> without constructing an intermediate escaped string
AddAppends trusted ASCII or UTF-8 markup under the same byte budget; this low-level method does not sanitize arbitrary HTML
ItemConsumes one logical item from the configured budget; report exporters count nested properties as items
PdfReportSha256Computes the SHA-256 digest of the supplied bytes, including the normal empty-input digest
PdfReportBoolean / PdfReportNumberSerialize one JSON literal: true/false and a dot-decimal general-format number with up to 15 significant digits; nonfinite numbers raise EPdfReportLimit
PdfReportSingleLine(const Value: UnicodeString): UnicodeStringRenders tabs and line breaks as visible escapes and converts other C0 and C1 controls and Unicode line separators to \uXXXX for single-line report output
PdfReportFileUri(const Path: UnicodeString): stringConverts an absolute local or Windows UNC path to a file URI, or a relative path to a relative URI. Encodes file-name bytes in UTF-8 with percent escapes. Pass filesystem paths before HTML or JSON escaping
ReadPdfWorkflowSourceSnapshots a nonempty seekable stream from byte zero within MaxBytes and restores the original position on every exit
TPdfBoundedMemoryStreamCreate(MaxBytes) owns a memory buffer that Destroy frees; Read and Seek behave as for a memory stream, Write and resizing raise EPdfReportLimit beyond the configured byte ceiling, and Memory exposes the buffer until the next write or resize

Invalid limits and exhausted budgets raise EPdfReportLimit; an exporter returns a complete string or raises, rather than returning truncated JSON or HTML

The writer permits at most 67108864 serialized bytes and 1048576 logical items; the byte-array ReadPdfWorkflowSource helper and bounded memory output stream accept byte limits up to MaxInt

Since 3.267.0, TPdfReflowDocument.WriteHtml(Writer, MaxDepth) writes directly through these limits and counts every rendered node; the document's Options.MaxNodes and Options.MaxCharacters additionally bound node count and emitted source-text code units, including attribute text

The default depth is 64, configurable from 1 through 256; malformed forward/self parent indices reject, and output/escaping limits apply as each fragment is emitted

The existing TPdfReflowDocument.ToHtml string API retains its previous behavior; use WriteHtml when serialization itself must be bounded

Direct output streams

Writer := TPdfReportWriter.Create(TPdfReportLimits.Default, Destination);
try
  Report.WriteJson(Writer);
finally
  Writer.Free;
end;

Since 3.268.0, the destination constructor writes UTF-8 at the caller's current position without buffering the complete report; BytesWritten counts only bytes emitted by this writer

The stream stays caller owned and can be nonseekable; Text is available only with the original internally buffered constructor and raises EInvalidOp for an external destination

Budget or I/O failures can leave partial bytes in an external stream; discard that attempt rather than publishing it as a complete report

Streaming byte identities and snapshots

PdfReportStreamSha256(Source, MaxBytes, Token) hashes a seekable stream from byte zero in 65536-byte chunks and restores its original position, including on failure

CopyPdfWorkflowSource(Source, Destination, MaxBytes, Token) copies a nonempty source to an empty caller-owned destination and returns the copied bytes' SHA-256; the source position is restored and the completed destination is rewound

These streaming helpers allow budgets through 1099511627776 bytes and check cooperative cancellation between chunks; input/native format limits still apply separately, and a failed copy may leave a partial destination

Windows artifact bundles

Bundle := TPdfArtifactBundle.Create(NewDirectory, 256 * 1024 * 1024);
try
  Bundle.Add('result.pdf', PdfStream, pwakDocument, Token);
  Bundle.Add('report.json', ReportStream, pwakReport, Token);
  Manifest := Bundle.Publish(Token);
finally
  Bundle.Free;
end;

The parent directory must already exist and the target must be new; Windows directory rename publishes the completed staging directory without replacing an existing destination, and other platforms reject bundle creation before staging

Artifact names are flat ASCII names using letters, digits, underscores, hyphens and dots; traversal, device names, duplicates and the reserved manifest.json name are rejected

Each add preserves its source position and records the closed staged file's byte count and SHA-256; publication verifies staged payloads and writes pdfiumpas.artifacts.v1 to manifest.json

The default payload budget is 1 GiB, with at most 1000 artifacts and a maximum configurable payload budget of 1 TiB; the manifest has its own default report budget

A failed add or publish makes that bundle unusable; destruction removes owned flat staging files, while a published directory remains caller owned

VerifyPdfArtifactBundle(Directory, Manifest, MaxTotalBytes, ErrorMessage, Token) checks every named payload against an in-memory manifest and returns false with an error on mismatch, budget exhaustion or cancellation; it does not parse or authenticate a saved manifest, enumerate extra files or validate PDF content

Use a trusted parent directory; staging and final directories share a filesystem, publication is a visibility boundary rather than a power-loss durability guarantee, and another process with write access can still modify files

Use Small Business reports for document workflows and Enterprise evidence for cross-workflow context