API referenceCore SDK

pdfSetCharWidth

Override a specific character code's advance width for

C
int32_t __stdcall pdfSetCharWidth(PPDF IPDF, int32_t CharCode, int32_t NewWidth);
Delphi
function pdfSetCharWidth(const IPDF: PPDF; CharCode, NewWidth: Integer): Integer; stdcall;

Purpose. Override a specific character code's advance width for subsequent text-measurement calls (pdfGetTextWidth and similar) on the currently-selected font — not a rendering-width override; it affects only the SDK's own measurement math.

Description. Real, and scoped to FCurrentFontIdx at the moment pdfSetCharWidth is called — switching to a different font afterward does not carry the override with it, and a later pdfSetCharWidth call for the same CharCode under a different current font creates a separate, independent override entry (keyed by (FontIdx, CharCode) together). The adjustment (CharWidthOverrideAdjustA/W) is only wired into text-width measurement for Standard-14 fonts — per an explicit source comment: "Standard-14 only (the default width for embedded fonts isn't resolved here); returns 0 otherwise" — so calling this against a custom embedded (TrueType/CID) font has no effect on subsequent measurement calls.

Parameters.

ParameterDescription
IPDFDocument handle.
CharCodeThe character code (0..$FFFF) to override.
NewWidthThe new advance width, replacing the font's default AFM width in measurement math.

Return value. 1 on success; 0 if IPDF is invalid, no font is currently selected, or CharCode is out of range.

See also. pdfGetTextWidth (the measurement consumer, Standard-14 only).

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfSetCharWidth(IntPtr IPDF, int CharCode, int NewWidth);
Area
Core SDK
Category

Setters

Exported names

pdfSetCharWidth

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.