THotPDF.RepairPDFUA2Structure Method
Repairs recoverable PDF/UA-2 namespace, attribute, structural, and accessibility defects inside a copy-on-write graph transaction and validates the candidate graph before commit
Declaração
function RepairPDFUA2Structure(
const Options: THPDFUA2RepairOptions;
out Report: THPDFUA2RepairReport;
out Issues: THPDFUA2ValidationIssues): boolean; overload;
function RepairPDFUA2Structure(
const Options: THPDFUA2RepairOptions;
out Report: THPDFUA2RepairReport;
out Issues: THPDFUA2ValidationIssues;
out Findings: THPDFComplianceFindings): boolean; overload;
Unidade
HPDFDoc
Repair options
Comece com THPDFUA2RepairOptions.Default and override only policy decisions required by the input workflow
| Campo | Finalidade |
|---|---|
NormalizeDuplicateNamespaces | Rebuilds StructTreeRoot/Namespaces with one canonical indirect dictionary per URI and rejects conflicting role maps |
RegisterReferencedNamespaces | Registers valid namespace dictionaries referenced by structure elements, attributes, or namespace-aware role maps |
RepairStandardStructureNamespaces | Assigns the PDF 2.0 namespace to standard roles when the namespace is missing or invalid and always normalises the top-level Document |
RepairAttributeNamespaces | Canonicalises attribute namespace references and removes invalid namespace entries from standard owners |
RepairAttributeRevisions | Normalises negative or fractional revision numbers and removes orphan revision entries from attribute arrays |
RepairListSemantics | Normalises numbering, continuation flags, invalid continuation types, and a single misplaced caption without inventing list content |
RepairTableSemantics | Normalises invalid spans and scopes, removes invalid table-local header references, and moves a single misplaced caption |
RepairRubyWarichuSequences | Reorders children only when the exact required role multiset is already present |
RepairPronunciationHints | Removes wrongly typed hints, prunes invalid lexicon references, and normalises embedded PLS MIME subtypes |
RepairMissingAlternateText | Restores missing Alt para Figure, Formula, and Form from an existing title, expansion text, same-MCID extracted text, or an explicit fallback in that order |
RepairLanguageInheritance | Promotes a valid structure-root or explicit default language to the Catalog and removes invalid or redundant structure-level language entries when inheritance is unambiguous |
RepairHeadingOrder | Renumbers only first-heading and skipped-level defects while retaining document order |
RepairArtifactTagging | Rewrites marked-content tags associated with an Artifact structure element for producer and loaded page content |
AllowDocumentFragmentHeadingStarts | Resets heading context inside each DocumentFragment for both repair and post-repair validation |
RollbackOnValidationFailure | Restores the original graph when any PDF/UA-2 error remains after repair |
CustomAttributeNamespaceURI | Supplies the explicit namespace for custom attribute owners whose semantics cannot be inferred safely, with an empty default that fails closed |
DefaultLanguage | Supplies a BCP-47 language tag only when neither the Catalog nor the structure root contains a valid language |
FallbackAlternateText | Supplies caller-reviewed alternate text after all document-derived sources fail, with an empty default that never fabricates a description |
MaxGeneratedAlternateTextCharacters | Bounds same-MCID text extraction and defaults to 4,096 UTF-16 code units |
MaxObjects | Bounds object-graph scanning and defaults to 1,000,000 objects |
MaxRepairs | Bounds retained mutations and defaults to 100,000 repair operations |
Repair report
THPDFUA2RepairReport reports whether the graph changed or rolled back, whether a bound was exceeded, post-repair validation status, objects examined, remaining errors, and counts for every repair family including alternate text, language entries, heading levels, and Artifact tags
UnresolvedAlternateTextCount, UnresolvedLanguageCount, and UnresolvedArtifactCount distinguish semantics that still require author review from automatic mutations
O devolvido THPDFUA2ValidationIssues array contains the post-repair diagnostics when validation fails and stable repair-specific diagnostics when a resource bound or conflicting duplicate role map aborts the transaction
The detailed overload also returns pre-repair findings annotated as crsApplied, crsUnresolved, crsRolledBack, or crsFailed, plus counted summaries for each repair family
This provenance overload performs an additional bounded pre-repair validation pass; use the existing three-output overload when only the final report and issues are required
Atomicity and safety
- Every mutation participates in the document graph transaction, including newly allocated indirect namespace dictionaries
- Duplicate namespace dictionaries are merged only when their role mappings agree
- Custom attribute semantics are never invented unless
CustomAttributeNamespaceURIé fornecido explicitamente - Alternate text is never fabricated unless
FallbackAlternateTexté fornecido explicitamente - Producer page-content edits are staged until validation succeeds, while loaded stream edits remain inside the graph transaction
- Ambiguous table intersections, missing structural children, conflicting IDs, unresolved continuation targets, and absent header semantics are never guessed
- The default policy rolls back the full repair when unrelated PDF/UA-2 errors remain
- Loaded and producer-side graphs use the same bounded validation and repair path
Exemplo
var
Options: THPDFUA2RepairOptions;
Report: THPDFUA2RepairReport;
Issues: THPDFUA2ValidationIssues;
begin
Options := THPDFUA2RepairOptions.Default;
Options.DefaultLanguage := 'en-US';
Options.CustomAttributeNamespaceURI :=
'https://example.com/ns/accessibility-attributes';
if not PDF.RepairPDFUA2Structure(Options, Report, Issues) then
raise Exception.CreateFmt('%s at %s',
[String(Issues[0].Code), String(Issues[0].Path)]);
end;