BeginTag

Tagged PDF, Accessibility

Description

Opens a tagged-PDF structure element on the current page. Writes a BDC (Begin Marked Content with Dictionary) operator to the content stream and registers the element in the document's logical structure tree. The structure tree is finalized automatically when the document is saved.

Tags must be balanced: every BeginTag call must be followed by a matching EndTag call. Tags can be nested.

Syntax

Delphi

function TPDFlib.BeginTag(const TagType, AltText, ActualText: WideString): Integer;

ActiveX

Function PDFlib::BeginTag(TagType As String, AltText As String, ActualText As String) As Long

DLL

int DLBeginTag(int InstanceID, wchar_t* TagType, wchar_t* AltText, wchar_t* ActualText);
int DLBeginTagA(int InstanceID, char* TagType, char* AltText, char* ActualText);

Parameters

TagTypePDF standard structure type: P, H1H6, Figure, Table, TR, TH, TD, L, LI, LBody, Span, Link, Note, etc. (see ISO 32000-1 §14.8.4).
AltTextAlternative text for images and other non-text content (maps to the PDF /Alt attribute). Pass an empty string if not required.
ActualTextReplacement text for content whose visual representation differs from its logical meaning (maps to the PDF /ActualText attribute). Pass an empty string if not required.

Return values

0Failed (no document is open)
1Tag opened successfully

Example

// Heading, then a paragraph
PDF.SetPDFUAMode('en-US');
PDF.BeginTag('H1', '', '');
PDF.PrintText(50, 750, 'Introduction');
PDF.EndTag;
PDF.BeginTag('P', '', '');
PDF.PrintText(50, 730, 'This document demonstrates tagged PDF.');
PDF.EndTag;

// Figure with alt text
PDF.BeginTag('Figure', 'Company logo', '');
PDF.DrawImage(50, 650, 120, 60, 'logo.png');
PDF.EndTag;

Remarks

Use BeginArtifact/EndArtifact for decorative content (page headers, footers, background elements) that should not be read by screen readers.

The document must be in write mode (created or opened for modification). Call SetPDFUAMode before tagging to satisfy PDF/UA-1 requirements.