SetStructElemColor

Tagged PDF, Accessibility

Description

Sets the /Color attribute (Layout attribute owner) on the structure element currently open on the tag stack. The value specifies the foreground (text or stroke) color of the element's content as an RGB triplet. Equivalent to calling AddTagAttribute with Owner=Layout, Name=Color, and a space-separated R G B string.

Syntax

Delphi

function TPDFlib.SetStructElemColor(R, G, B: Double): Integer;

ActiveX

Function PDFlib::SetStructElemColor(R As Double, G As Double, B As Double) As Long

DLL

int DLSetStructElemColor(int InstanceID, double R, double G, double B);

Parameters

RRed component of the color, in the range 0.0 (no red) to 1.0 (full red).
GGreen component of the color, in the range 0.0 to 1.0.
BBlue component of the color, in the range 0.0 to 1.0.

Return value

Returns 1 on success. Returns 0 if no document is open or no tag is currently open on the tag stack.

Remarks

Call this function after BeginTag or BeginTagEx and before EndTag. The /Color attribute is defined in ISO 32000-1 §14.8.5.4.2 (Layout attribute owner, Table 340) and is stored as a three-element PDF array of numbers.

This attribute describes the foreground color of the element as perceived by an assistive technology or re-flow engine. It is advisory — the visual color rendered in the PDF is controlled by the graphics state, not by this attribute. However, providing accurate color information enables downstream tools to check color contrast ratios (WCAG 2.x Success Criterion 1.4.3) and to maintain fidelity when reflowing content.

Common color values: black = (0.0, 0.0, 0.0); white = (1.0, 1.0, 1.0); red = (1.0, 0.0, 0.0).

Example

// Tag a heading rendered in dark blue
PDFlib.BeginTag('H2', '', '', '');
PDFlib.SetStructElemColor(0.0, 0.18, 0.39);  // RGB for dark blue
PDFlib.DrawText('Section 2', 72, 700);
PDFlib.EndTag;

See also

SetStructElemEndIndent, SetStructElemBBox, AddTagAttribute, BeginTag, EndTag