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

CampoFinalidade
NormalizeDuplicateNamespacesRebuilds StructTreeRoot/Namespaces with one canonical indirect dictionary per URI and rejects conflicting role maps
RegisterReferencedNamespacesRegisters valid namespace dictionaries referenced by structure elements, attributes, or namespace-aware role maps
RepairStandardStructureNamespacesAssigns the PDF 2.0 namespace to standard roles when the namespace is missing or invalid and always normalises the top-level Document
RepairAttributeNamespacesCanonicalises attribute namespace references and removes invalid namespace entries from standard owners
RepairAttributeRevisionsNormalises negative or fractional revision numbers and removes orphan revision entries from attribute arrays
RepairListSemanticsNormalises numbering, continuation flags, invalid continuation types, and a single misplaced caption without inventing list content
RepairTableSemanticsNormalises invalid spans and scopes, removes invalid table-local header references, and moves a single misplaced caption
RepairRubyWarichuSequencesReorders children only when the exact required role multiset is already present
RepairPronunciationHintsRemoves wrongly typed hints, prunes invalid lexicon references, and normalises embedded PLS MIME subtypes
RepairMissingAlternateTextRestores missing Alt para Figure, Formula, and Form from an existing title, expansion text, same-MCID extracted text, or an explicit fallback in that order
RepairLanguageInheritancePromotes a valid structure-root or explicit default language to the Catalog and removes invalid or redundant structure-level language entries when inheritance is unambiguous
RepairHeadingOrderRenumbers only first-heading and skipped-level defects while retaining document order
RepairArtifactTaggingRewrites marked-content tags associated with an Artifact structure element for producer and loaded page content
AllowDocumentFragmentHeadingStartsResets heading context inside each DocumentFragment for both repair and post-repair validation
RollbackOnValidationFailureRestores the original graph when any PDF/UA-2 error remains after repair
CustomAttributeNamespaceURISupplies the explicit namespace for custom attribute owners whose semantics cannot be inferred safely, with an empty default that fails closed
DefaultLanguageSupplies a BCP-47 language tag only when neither the Catalog nor the structure root contains a valid language
FallbackAlternateTextSupplies caller-reviewed alternate text after all document-derived sources fail, with an empty default that never fabricates a description
MaxGeneratedAlternateTextCharactersBounds same-MCID text extraction and defaults to 4,096 UTF-16 code units
MaxObjectsBounds object-graph scanning and defaults to 1,000,000 objects
MaxRepairsBounds 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

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;

APIs relacionadas