API reference › Text

pdfWriteText

Draw a single line of text at an absolute page position with the

CategoryText output
Exported namespdfWriteTextA, pdfWriteTextW
Thread safetypdfWriteTextA serializes via the instance mutex when pdfEnableMutex is armed (D.Lock/D.Unlock); pdfWriteTextW does not take the lock — a verified inconsistency between the two variants.

Purpose — Draw a single line of text at an absolute page position with the current font/size/color.

Description — Requires an open document, open page, and a font selected via pdfSetFont/pdfSetFontEx; a NULL/empty string or missing precondition returns FALSE with nothing drawn. Dispatches by font kind:

  • CID-predefined fonts (W only supports UCS2-mode CMaps; A accepts pre-encoded bytes verbatim in the CMap's source encoding for both UCS2 and legacy -H CMaps).
  • Embedded TrueType: encoded to Identity-H GIDs directly from Unicode (W) or via a WinAnsi decode step (A); synthetic bold/oblique (from -SynBold/-SynItal markers set when pdfSetFont couldn't find a real styled face) is honored automatically.
  • Standard 14 / embedded Type 1: A writes raw bytes as WinAnsi; W transcodes to code page 1252 (WinAnsi) — deliberately not CP_ACP (see the source comment: CP_ACP "corrupts output on non-Western systems"). If any character can't round-trip through WinAnsi (WC_NO_BEST_FIT_CHARS detects this precisely, not just "close enough" substitution), the engine transparently loads an embedded Unicode TrueType fallback — the first available of Arial, Segoe UI, or Tahoma — and redraws the run through it as Identity-H GIDs instead of dropping characters to '?'. If no system font is found, it falls through to the lossy WinAnsi write.

If FBidiMode is not bmNone, W input is reordered per UAX#9 (logical → visual order) before any of the above — required because PDF stores glyphs in visual order. Pure LTR text is returned unchanged, so this never affects plain Latin output.

Declarations

C
BOOL32 __stdcall pdfWriteTextA(PPDF IPDF, double PosX, double PosY, const char* AText);
BOOL32 __stdcall pdfWriteTextW(PPDF IPDF, double PosX, double PosY, const wchar_t* AText);
Delphi
function pdfWriteTextA(const IPDF: PPDF; PosX, PosY: Double; const AText: PAnsiChar): LongBool; stdcall; external 'LumasPdf.dll';
function pdfWriteTextW(const IPDF: PPDF; PosX, PosY: Double; const AText: PWideChar): LongBool; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle with an open page and selected font.
PosX, PosYDoubleBaseline origin, in the page's current coordinate system.
ATextstringText to draw. NULL returns FALSE immediately.

Return value — TRUE on success; FALSE on any missing precondition (no document/page/font, NULL/empty text) or invalid handle.

Remarks — "last text position" reports the END of the run. After a successful call, pdfGetLastTextPosX/Y reflect the position after the text — PosX + GetTextWidth(text) — not the starting position you passed in. This is deliberate behavior. An underline, if pdfSetTextUnderline is active, is emitted spanning exactly this computed width.

See also — pdfWriteTextEx, pdfGetTextWidth

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Text
Category

Text

Exported names

pdfWriteTextA pdfWriteTextW

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.