EndTag

Tagged PDF, Accessibility

Description

Closes the most recently opened structure element on the tag stack, writing an EMC (End Marked Content) operator to the current page's content stream and popping the element from the stack. Each call to BeginTag, BeginTagEx, or BeginTagEx2 must be matched by exactly one EndTag call before the document is saved or the next page is added.

Syntax

Delphi

function TPDFlib.EndTag: Integer;

ActiveX

Function PDFlib::EndTag As Long

DLL

int DLEndTag(int InstanceID);

Return values

0Failed — no document is open, or the tag stack is empty (EndTag was called more times than the corresponding Begin* functions).
1The structure element was closed successfully.

Remarks

Tags must nest cleanly. Each EndTag closes the innermost open structure element; the closing order is strictly the reverse of the opening order, the same way ordinary block elements nest in HTML or XML.

If a document is saved with one or more structure elements still open, GetPDFUADiagnostics reports the count under the STRUCT-UNCLOSED code. Unclosed elements are missing from the saved structure tree, so the corresponding marked content sections on each page have no logical parent — assistive technology will skip them.

Do not use EndTag to close an artifact region opened with BeginArtifact; call EndArtifact for that. Artifacts and structure elements live on independent marked-content stacks.

Example

// Nested structure: a section with a heading and two paragraphs
PDF.BeginTag('Sect', '', '');
  PDF.BeginTag('H1', '', '');
    PDF.PrintText(50, 750, 'Introduction');
  PDF.EndTag;   // H1
  PDF.BeginTag('P', '', '');
    PDF.PrintText(50, 720, 'First paragraph of the introduction.');
  PDF.EndTag;   // P
  PDF.BeginTag('P', '', '');
    PDF.PrintText(50, 690, 'Second paragraph follows in the same section.');
  PDF.EndTag;   // P
PDF.EndTag;     // Sect

See also

BeginTag, BeginTagEx, BeginTagEx2, EndArtifact, GetPDFUADiagnostics