AutoTagPages
Accessibility
Description
Tags unmarked existing pages using either the original line-based mode or an opt-in semantic layout analysis with review diagnostics
Syntax
Delphi
Function TPDFlib.AutoTagPages(Const PageRange: WideString; Options: Integer): Integer;
Parameters
| PageRange | A page range such as 1-3,5, or an empty string for every page |
|---|---|
| Options | 0 preserves the original line-based behaviour; PDF_AUTOTAG_SEMANTIC = 1 analyses paragraphs, columns, headings, list markers, tables and images; combine it with PDF_AUTOTAG_REVIEW_ONLY = 2 to inspect candidates without changing the document |
Return values
The number of supported pages tagged, or the number of supported candidate pages in review-only mode; pages with existing marked content or StructParents are preserved and excluded
Semantic mode
The semantic mode uses column-aware geometric reading order and groups body lines into P elements, larger text into H1 or H2 candidates, numeric or bullet markers into L / LI / LBody, and supported geometric tables into Table / TR / TH / TD with inferred spans and column header scope for a bold first row
Supported page, nested Form and exactly qualified inline images become Figure candidates with an explicit alternate-text and decoration review requirement; other unassigned painting is marked as Artifact and no alternate description is invented
Candidate order uses a bounded deterministic sort with stable ties, and each page gets its own private content streams and Sect, keeping shared source streams and previously tagged pages intact; existing parent-tree entries are preserved in the extended number tree and every generated MCID maps to its owning element
Inherited page rotations at integer multiples of 90 degrees and non-zero media/crop origins are supported; semantic analysis uses the displayed CropBox orientation without changing page content co-ordinates, boxes or rotation
Nested and shared Form text and images are bound to verified invocation paths; each invocation receives a private Form copy and resource alias, preserving matrices, BBox clipping, transparency groups and unaffected uses on other pages
Each private Form containing semantic marked content has its own StructParents key and local MCID array; owning elements use explicit MCR dictionaries with Pg, Stm and MCID, so repeated uses of the same original Form do not share semantic ownership
Inline image source locations use exact sample-row and supported filter-chain boundary proofs, including verified raw and ASCIIHex input; pixel bytes resembling EI or content operators remain image data, and qualified images are bound to the actual page or Form instruction without replacing the image bytes
Incomplete headers, unsupported or ambiguous boundaries, truncated samples, invalid filter termination and rendering qualification errors skip the page before content changes; proof work and decoded samples share 64 MiB budgets per call, with a 16 MiB per-payload bound and 100000 component-resolution steps
Supported Tj, TJ and quote text-show instructions spanning inferred semantic cells are split at captured source-byte ownership boundaries; original encoded bytes, numeric TJ adjustments, quote line moves, word spacing and character spacing are preserved, including in invocation-specific Form copies
A glyph byte range assigned to different elements is ambiguous and rejects the page; no Unicode re-encoding, guessed ligature split or font substitution is used, and unassigned original byte spans remain artefacts
Review and corrections
Read GetLastStructuredTextDiagnostics immediately after the call for JSON with committed status, skipped-page reasons and candidates containing role, parent candidate, reading order, column, bounding box, confidence, review requirements and the committed structure object number; review-only candidates have object number zero
Use GetObjectJSON and SetObjectJSON on a committed object number to edit a role or alternate text using the typed object representation, or to reorder its child references while preserving their parent relationships; typed PDF names use hexadecimal bytes, such as 466967757265 for Figure, and a human description belongs in the structure dictionary's Alt text string
Inspect the containing Sect or other parent to correct sibling reading order, and keep child P references and parent-tree MCID ownership consistent; converting a figure to a decorative artifact also requires rewriting its marked content and removing its structure ownership, rather than assigning an Artifact structure role
Limits
Semantic inference is heuristic and always reports fullCertification=false and requiresHumanReview=true; document language, alternate text quality, actual semantic meaning, complex table headers and accessibility conformance require review
Pages with inline images lacking verified semantic source provenance, unknown operators, invalid page rotation or bounds, unqualified Form sources, unknown source locations, overlapping paint ranges or ambiguous glyph-byte ownership across inferred cells are skipped with a reason before their page content is changed; existing marked content remains untouched
Reference Form proxies, external Form streams, already structured or marked Forms, cyclic invocations, unresolved XObjects and malformed Form geometry/resources are skipped before page content changes; no external target is resolved or relabelled as if its proxy were authoritative
Each page accepts at most 4096 prepared content scopes and 64 nested Form levels; copied resource dictionaries are limited to 100000 entries each and 1000000 total entry-copy work per call, whilst decoded Form bytes count against the shared source budget
Text binding is limited to 1000000 captured-location bindings per call; a split instruction accepts at most 65536 captured byte ranges, a 1 MiB text string and 4000000 byte-ownership checks, with resulting fragments included in the normal source-unit and output limits
A call accepts at most 1,000 pages, 64 MiB of decoded source content, 200,000 source units, 100,000 candidates and 96 MiB of prepared output; each page is additionally bounded to 10,000 extraction blocks, 100,000 source units and 50,000 candidates
Original mode
With Options = 0, adjacent body-size lines form paragraphs and lines larger than the median body size form headings at factors 1.6 and 1.25; paths, images and shadings remain artefacts and reading order follows painting order
Example
PDF.LoadFromFile('report.pdf', '');
Count:= PDF.AutoTagPages('', PDF_AUTOTAG_SEMANTIC or PDF_AUTOTAG_REVIEW_ONLY);
Diagnostics:= PDF.GetLastStructuredTextDiagnostics;
if Count > 0 then
begin
PDF.AutoTagPages('', PDF_AUTOTAG_SEMANTIC);
Diagnostics:= PDF.GetLastStructuredTextDiagnostics;
PDF.SaveToFile('report-tagged.pdf');
end;