Concrete providers for document repair
Enterprise edition: this unit ships in Lib\Enterprise and is linked by FPdfEnterprise and the PDFiumPasEnt / PDFiumLazEnt packages; see the edition matrix
Add FPdfDocumentRepairProviders and register providers in TPdfDocumentARepairOptions.Providers to run reviewed changes through the transactional PDF/A repair workflow
Declarations
type
TPdfDocumentColourRepairProvider= class(TInterfacedObject, IPdfDocumentARepairProvider)
private
FTargetSpace: TPdfColourSpace;
FTargetProfile: TBytes;
FTransform: IPdfColourTransform;
FOptions: TPdfDocumentColourOptions;
FLastReport: TPdfDocumentColourReport;
function GetLastReport: TPdfDocumentColourReport;
public
constructor Create(TargetSpace: TPdfColourSpace; const TargetProfile: TBytes;
Transform: IPdfColourTransform; const Options: TPdfDocumentColourOptions);
function Supports(Category: TPdfARepairCategory): Boolean;
function RequiresStableObjectIdentities: Boolean;
function PreservesObjectIdentities: Boolean;
function Repair(const Source: TBytes; const Step: TPdfARepairStep;
const Context: TPdfDocumentARepairContext; out OutputPdf: TBytes;
out ErrorText: string): Boolean;
property LastReport: TPdfDocumentColourReport read GetLastReport;
end;
TPdfDocumentStructureRepairProvider= class(TInterfacedObject, IPdfDocumentARepairProvider)
private
FBaseSourceSha256: string;
FOperations: TPdfStructureEditOperations;
FOptions: TPdfStructureEditOptions;
FLastReport: TPdfStructureEditReport;
function GetLastReport: TPdfStructureEditReport;
public
constructor Create(const BaseSourceSha256: string;
const Operations: TPdfStructureEditOperations; const Options: TPdfStructureEditOptions);
function Supports(Category: TPdfARepairCategory): Boolean;
function RequiresStableObjectIdentities: Boolean;
function PreservesObjectIdentities: Boolean;
function Repair(const Source: TBytes; const Step: TPdfARepairStep;
const Context: TPdfDocumentARepairContext; out OutputPdf: TBytes;
out ErrorText: string): Boolean;
property LastReport: TPdfStructureEditReport read GetLastReport;
end;
TPdfDocumentTextRepairProvider= class(TInterfacedObject, IPdfDocumentARepairProvider)
private
FPlan: TPdfDocumentTextRepairPlan;
FOptions: TPdfDocumentTextRepairOptions;
FCategory: TPdfARepairCategory;
FLastReport: TPdfDocumentTextRepairReport;
public
constructor Create(const Plan: TPdfDocumentTextRepairPlan;
const Options: TPdfDocumentTextRepairOptions; Category: TPdfARepairCategory=parcFonts);
function Supports(Category: TPdfARepairCategory): Boolean;
function RequiresStableObjectIdentities: Boolean;
function PreservesObjectIdentities: Boolean;
function Repair(const Source: TBytes; const Step: TPdfARepairStep;
const Context: TPdfDocumentARepairContext; out OutputPdf: TBytes;
out ErrorText: string): Boolean;
property LastReport: TPdfDocumentTextRepairReport read FLastReport;
end;
Colour repair
TPdfDocumentColourRepairProvider deals with parcColour by way of ConvertPdfDocumentColours with an explicit target colour space, ICC profile and IPdfColourTransform
The provider copies the profile and options, insists on complete conversion and forces FailOnUnsupported True together with OutputIntentKind pdoikPdfA, writing the PDF/A GTS_PDFA1 subtype
Source and output budgets are capped by the parent repair limits; cancellation travels through the conversion workflow, and unsupported painting features trigger failure and rollback
The provider preserves object identities and needs no fixed source snapshot; LastReport brings back the conversion report with an independent issue array
Reviewed existing structure repair
TPdfDocumentStructureRepairProvider covers parcStructure using reviewed TPdfStructureEditOperations and the SHA-256 digest of the original input snapshot
Build the provider once ReadPdfDocumentStructure has supplied the digest and node IDs; call RepairPdfDocumentAFromBytes with those same original bytes
The provider verifies the immutable base digest and stable identity state, then applies the reviewed operations to the current staged bytes; identity-preserving colour changes made beforehand are supported
Node, text, source and output budgets are capped by the parent limits; local and parent cancellation are checked either side of execution, and an available token is passed down to the structure editor
LastReport hands back an independent copy of the inserted-node identities; the existing structure editor's restrictions and inherited-context checks carry on applying
Reviewed text resources
TPdfDocumentTextRepairProvider takes a TPdfDocumentTextRepairPlan, options and a single execution Category, parcFonts by default; parcStructure and parcOther are also there for application-authored semantic plans
The chosen category executes the whole supplied recipe once; when separate categories must carry out different subsets, split the recipes across distinct providers
The constructor takes deep copies of font bytes, glyph maps, mapping-entry arrays and ActualText records once the aggregate constructor budgets have been checked
The immutable base source digest and stable object-identity state have to match; after those checks the current staged digest is handed to the resource editor, which permits identity-preserving repairs beforehand
Parent limits cap source/output, recipe count and the per-font/per-stream and text budgets; local and parent cancellation are checked around the inner operation, with an available token used inside it
LastReport brings back the text-resource result; every concrete provider clears its success/publication state should a final cancellation check fail
Postvalidation and scope
These providers hold on to the original object numbers and generations and return independent output; the final built-in PDF/A checks run over the exact bytes and the reopened native model
Only automatic, unblocked plan steps run; reviewed or manual steps wait for an application decision before execution
These providers synthesise no missing semantic content and invent no fonts, character mappings or replacement text; the text provider insists on explicit reviewed resource recipes
A passing built-in check is not the same as external standards certification
See also
Document colour conversion, Existing structure editing, Transactional repair