PDFiumPas Docs

FPdfBusinessWorkflows

Requires Small Business or Enterprise since 3.266.0; link FPdfSmallBusiness or this unit from Lib\SmallBusiness

Scan processing

function ProcessPdfScan(Source: TStream; const Provider: IPdfOcrProvider;
  const Options: TPdfScanWorkflowOptions; out OutputPdf: TBytes;
  out Report: TPdfScanWorkflowReport;
  const CancellationToken: IPdfCancellationToken = nil): Boolean;

The workflow snapshots the complete source from byte zero, restores the caller's position, opens an owned TPdf, applies ApplyPdfStructuredOcr, builds structured-text and reflow page outputs, and saves the searchable PDF into a bounded destination

It never changes source bytes or a caller-owned document; the source must be seekable and must remain stable whilst the workflow runs

OptionDefault and scope
OcrTPdfStructuredOcrOptions.Default, including optional image preprocessing, OCR page selection, existing-text skipping, pixel/word/layout limits and reviewed tables
ReflowTPdfReflowOptions.Default; generated page fragments force FullDocument=False and IncludeCss=False
MaxInputBytes / MaxOutputBytes67108864 / 134217728 bytes; the output ceiling applies to published bytes, whilst native save staging uses the library's existing working-storage policy
MaxPages1000 source pages; allowed values are 1 through 100000
PublishPartialOutputFalse; incomplete work publishes no bytes unless explicitly enabled, and cancellation always withholds output

The return value is true only when processing is complete and output was published; failed pages, cancellation or rejected OCR words keep Complete=False

A false return with OutputPublished=True is possible only for explicitly allowed partial output; inspect per-page statuses and review the candidate before using it

Report.Pages is a TPdfScanPageOutputs array; each TPdfScanPageOutput contains the OCR layout's PageNumber, StructuredText and Reflow for a successfully processed OCR page; pages skipped because they already contain text have no OCR layout or reflow entry

SourceSha256 and OutputSha256 bind the actual snapshot and published output; ToJson(Limits) exports page outcomes, and ToHtml(Limits) combines outcomes with escaped reflow markup

Since 3.267.0, scan HTML streams each reflow node through the shared report writer; node count, source text, escaped output and the default 64-level depth limit apply during serialisation, before a complete page HTML string could be allocated

OCR providers and optional native libraries/language models must be configured separately; this workflow does not infer recognition accuracy, automatic semantic tables or Tagged PDF certification

Semantic review exports

function PdfSemanticReviewToJson(const Report: TPdfSemanticDiffReport;
  const Limits: TPdfReportLimits): string;
function PdfSemanticReviewToHtml(const Report: TPdfSemanticDiffReport;
  const Limits: TPdfReportLimits): string;

Export an existing ComparePdfSemantics report with complete/incomplete status, supported scope, added/removed/changed/ambiguous items, before/after properties and unresolved identity reasons

JSON includes item provenance and PDF-space bounds; HTML escapes identity, property and error text and visibly distinguishes absent values from empty values

Comparison selection and limits remain governed by TPdfSemanticDiffOptions; exports do not resolve ambiguity, execute scripts or establish legal/document equivalence

pffSemanticReviewExports describes pure serialisation and requires no native runtime or active document once linked; the combined pfpSemanticReview workflow still checks the actual native comparison engine and document prerequisites

Source-bound semantic review

function ReviewPdfSources(BeforeSource, AfterSource: TStream;
  const PagePairs: TPdfDiffPagePairs; const Options: TPdfSemanticDiffOptions;
  out Review: TPdfSemanticSourceReview; MaxInputBytes: Int64 = 67108864;
  const CancellationToken: IPdfCancellationToken = nil): Boolean;

Since 3.267.0, this workflow snapshots each complete seekable input from byte zero, restores both positions, disables document lifecycle actions and compares owned native documents without modifying caller-owned documents

InputsCaptured, the BeforeSha256/AfterSha256 identities, BeforeBytes/AfterBytes and BeforePages/AfterPages identify the original inputs; Options retains every comparison category, geometry tolerance, work/string limits and an independent copy of custom annotation keys

ExplicitPairing distinguishes caller pairing from generated positional pairing; the copied PagePairs records both zero-based indices and supplied pair metadata, with -1 denoting an absent side

Pairing describes the effective mapping for a complete comparison and the attempted mapping otherwise; inspect ComparisonAttempted, Comparison.Complete, Cancelled and Comparison.ErrorMessage before treating results as complete

ToJson(Limits) uses pdfiumpas.source-review.v1 and includes the context plus the existing comparison payload; HTML presents the same comparison selections, bounds, identities and page mapping through the same bounded writer

The input limit is per source, and comparison work remains bounded by TPdfSemanticDiffOptions; cancellation is checked around snapshots, native loading and comparison, whilst synchronous native/comparison calls are not interruptible internally

Exact-byte PDF/R validation

function ValidatePdfRasterSource(Source: TStream;
  const Options: TPdfRasterSourceValidationOptions;
  out Report: TPdfRasterSourceValidationReport;
  const CancellationToken: IPdfCancellationToken = nil): Boolean;

Since 3.267.0, this helper applies ValidatePdfRComplianceWithOptions and native page-object/image facts to the same owned original-byte snapshot; it does not save or reserialise the source before the file-format pass

The Boolean return means inspection completed, not that the input conforms; use Report.IsCompliant, which also requires complete, noncancelled inspection and an empty validation issue set

SourceBytes, SourceSha256, Validation, Pages (TPdfRasterPageFacts, one TPdfRPageFacts per inspected page) and ErrorMessage preserve inspection evidence; partial page facts remain incomplete when a resource limit, load error or cancellation interrupts inspection

Defaults are 67108864 input bytes, 1000 MaxPages, 100000 MaxPageObjects per page and 1000000 MaxTotalObjects overall; the snapshot budget allows up to 1 TiB, with native/parser limits applying separately, and page/object maxima are 100000 pages, 1000000 objects per page and 10000000 overall

Validation selects the existing PDF/R resolution, strip geometry and encrypted-profile policy; Password supplies native load credentials and is never copied into the result or report exporters

Native lifecycle actions are disabled; cancellation is cooperative around the raw pass, native load, pages and objects, and synchronous native/parser internals retain their existing bounds

pfpPdfRSourceValidation queries the registered helper and its native/document prerequisites; pfpPdfRRaster retains the separate marker/byte-validator scope

Since 3.268.0, ProcessedPageCount counts fully inspected pages and TotalPageCount records the native page count when available; PageIssues[I] contains the page-fact issues for Pages[I] (TPdfRasterPageIssues), whilst Validation.Issues also includes raw-file issues

Status: TPdfRasterSourceStatus distinguishes prssNotStarted before inspection begins from prssCompleted, prssCancelled, prssBudgetExceeded, prssInvalidInput and prssFailed; completion can still contain conformance failures

ToJson/ToHtml and WriteJson/WriteHtml export bounded diagnostics; JSON uses pdfiumpas.raster-source.v1 and includes only processed pages, never uninspected default records

XFA migration assessment and conversion

function RunPdfXfaMigration(Source: TStream;
  const Options: TPdfXfaFlattenOptions; AssessmentOnly: Boolean;
  out OutputPdf: TBytes; out Report: TPdfXfaMigrationReport): Boolean;

Both modes run the same bounded static-XFA conversion in owned memory; assessment discards candidate bytes, whilst conversion returns them only on success

This is a conversion-based assessment, not an inexpensive syntax-only probe; existing packet/field/output/work limits and cancellation apply, and a failure reports the converter's first rejection rather than an exhaustive list of unsupported constructs

Successful field maps in Report.Fields (TPdfXfaFlattenFields) include source leaf names, subform paths, exact emitted AcroFormName, field kinds and one-based page numbers; ToJson and ToHtml omit values, passwords and image payloads

In assessment mode Conversion.OutputSha256 identifies the discarded candidate, not a published file; converting again can produce a different candidate if converter-generated metadata changes

Dynamic sizing, repeated instances and script-driven XFA-to-AcroForm conversion remain unsupported; native V8/XFA interaction and its per-document runtime checks are separate core capabilities

Report schemas and availability

Since 3.268.0, scan, source-review, raster and XFA migration records provide WriteJson(Writer) and WriteHtml(Writer); existing string-returning methods use the same implementations

WriteSemanticReviewJson(Writer, Report) and WriteSemanticReviewHtml(Writer, Report, Shell) serialise an existing comparison directly, with Shell=False producing an embeddable HTML section

Spill-capable workflow inputs

Scan processing, source review and raster inspection use an owned TPdfRandomAccessStore snapshot and LoadCustomDocument; input positions are restored and native documents close before their snapshots are released

Scan and raster options expose MemoryLimitBytes, defaulting to 8388608, and TemporaryDirectory, defaulting to the system temporary directory; allowed memory limits range from 0 through 1073741824, with zero spilling on the first nonempty write

Storage := TPdfWorkflowStorageOptions.Default;
Storage.MemoryLimitBytes := 8 * 1024 * 1024;
Complete := ReviewPdfSourcesWithStorage(BeforeStream, AfterStream,
  PagePairs, Options, Storage, Review, Token);

The existing ReviewPdfSources entry point uses the same 8 MiB memory threshold and its original per-input byte budget; source review exposes BeforeSnapshotSpilled/AfterSnapshotSpilled, and raster reports expose SnapshotSpilled

Snapshot memory limits do not bound native parsing, OCR providers, structured results or returned PDF byte arrays; XFA migration retains its converter-specific storage behaviour

WorkflowConsole demonstrates real review, raster inspection and Tesseract processing with optional Enterprise evidence

JSON schema identifiers are pdfiumpas.scan-workflow.v1, pdfiumpas.semantic-review.v1 and pdfiumpas.xfa-migration.v1; exports use TPdfReportLimits and raise on exhausted serialisation budgets

Use pfpScanWorkflow, pfpSemanticReview and pfpXfaMigration with QueryPdfFeatureProfile; these queries describe implementation linkage and caller checks without executing the workflow