API referenceText

pdfDrawHTMLText

Word-wrap and draw an HTML-subset fragment (see the chapter

CategoryHTML text
Exported namespdfDrawHTMLTextA, pdfDrawHTMLTextW, pdfDrawHTMLText

Purpose — Word-wrap and draw an HTML-subset fragment (see the chapter note) at (PosX, PosY), wrapped to Width.

Description — Parses HTML into styled runs, greedily wraps them to Width (Width <= 0 disables wrapping — a single unbroken line per paragraph), and draws each line via pdfWriteText/ pdfWriteTextMatrix internally (matrix form only for the sibling pdfDrawHTMLMatrix/BoxMatrix variants, not this one). Text flows downward from PosY (top-anchored, first baseline at PosY - Size).

Declarations

C
int32_t __stdcall pdfDrawHTMLText(PPDF IPDF, double PosX, double PosY, double Width, double Size, int32_t Align, const char* HTML);
int32_t __stdcall pdfDrawHTMLTextA(PPDF IPDF, double PosX, double PosY, double Width, double Size, int32_t Align, const char* HTML);
int32_t __stdcall pdfDrawHTMLTextW(PPDF IPDF, double PosX, double PosY, double Width, double Size, int32_t Align, const wchar_t* HTML);
Delphi
function pdfDrawHTMLTextA(const IPDF: PPDF; PosX, PosY, Width, Size: Double; Align: Integer; HTML: PAnsiChar): Integer; stdcall; external 'LumasPdf.dll';
function pdfDrawHTMLTextW(const IPDF: PPDF; PosX, PosY, Width, Size: Double; Align: Integer; HTML: PWideChar): Integer; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle with an open page.
PosX, PosYDoubleTop-left anchor; text flows down and (per Align) left/center/right within Width.
WidthDoubleWrap width; <= 0 disables wrapping.
SizeDoubleFont size; <= 0 defaults to 12.
AlignInteger0=left, 1=center, 2=right (only meaningful when Width > 0).
HTMLstringHTML-subset fragment — see the chapter note for the supported tags.

Return value — Number of lines drawn (>= 0) on success; -1 if no page is open, no font is available, or the handle is invalid.

Remarks — There is no height/clip parameter on this entry point — text always draws in full regardless of how far down the page it runs. For a height-clipped variant, see the separate pdfDrawHTMLBox (not in this chapter's scope, same underlying engine with a MaxHeight clip).

See alsopdfGetHTMLTextWidth, pdfGetHTMLTextHeight

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfDrawHTMLTextW(IntPtr IPDF, double PosX, double PosY, double Width, double Size, int Align, IntPtr HTML);
public static extern int pdfDrawHTMLText(IntPtr IPDF, double PosX, double PosY, double Width, double Size, int Align, IntPtr HTML);
public static extern int pdfDrawHTMLTextA(IntPtr IPDF, double PosX, double PosY, double Width, double Size, int Align, IntPtr HTML);
Area
Text
Category

Vector Graphics

Exported names

pdfDrawHTMLTextW pdfDrawHTMLText pdfDrawHTMLTextA

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.