| Category | Font selection |
|---|---|
| Exported names | pdfSetFontA, pdfSetFontW |
| Note | style-bitmask mismatch above fixed 2026-07-12; two accepted-but-unused parameters remain (see Remarks) |
Purpose — Select (creating on first use) a font by name, style, and size for subsequent text output.
Description — the font resolution chain. pdfSetFont never truly fails for a non-empty name; it degrades through five tiers and always lands somewhere:
- Standard-14 match —
Name(after style-suffixing) matches one of the 14 base PDF fonts (Helvetica/Times/Courier/Symbol/ZapfDingbats families, including common aliases like"Arial"→ Helvetica,"Times New Roman"→ Times) → uses that standard font, no embedding needed. - Exact system TrueType match —
FindSystemFontPath(Name, Style)finds an installed font file matching both name and style. - Regular-variant system match — same lookup with
Style=0, if the styled variant wasn't found (so a request for "Arial Bold" when only plain Arial is installed still resolves to the Arial file — then synthesizes bold/italic at draw time: stroke-mode render for bold, sheared text matrix for oblique, tagged-SynBold/-SynItalon the internal font entry). - Alternate font list — if steps 2–3 found nothing, tries each name registered via
pdfSetAltFonts, in order, until one resolves to a real system font. (This makes the alt-font list a genuine substitution input — not a write-only store, unlike several other "list" setters in this SDK.) - Bundled embedded fallback — 20 fonts compiled directly into the DLL (Arial/Times New Roman/Courier New/Symbol/Wingdings/Calibri/Tahoma family members), consulted only if nothing above resolved.
- Last resort — if even the bundled fallback has nothing, the engine emits a font resource using the literal requested name (with a
-Bold/-Italic/-BoldObliquesuffix as appropriate) as/BaseFont, with no embedded program and no/Widthsarray. The PDF is still valid andpdfSetFontstill reports success — but text drawn with this font relies entirely on the viewer having (or substituting) a matching face, and width measurement falls back to the coarse char-count estimate documented forpdfGetTextWidth.
Declarations
int32_t __stdcall pdfSetFontA(PPDF IPDF, const char* Name, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
int32_t __stdcall pdfSetFontW(PPDF IPDF, const wchar_t* Name, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
function pdfSetFontA(const IPDF: PPDF; const Name: PAnsiChar; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';
function pdfSetFontW(const IPDF: PPDF; const Name: PWideChar; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';
Parameters
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle with an open document. |
Name | string | Font family/PostScript name. pdfSetFontW's wide→narrow conversion is a raw per-character truncating cast (AnsiChar(Ord(WideChar))), not a codepage-aware transcode — matters only if the name itself contains non-ASCII characters (rare for font names, but not impossible for some localized family names). |
Style | TFStyle | Only bit 0 (Bold) and bit 1 (Italic) have any effect; the fsBold/fsItalic named constants correctly set those bits (fixed 2026-07-12 — see the chapter-level note). |
Size | Double | Point size. |
Embed | BOOL32 | Accepted but not read by this implementation — see Remarks. |
CP | TCodepage | Accepted but not read by this implementation — see Remarks. |
Return value — 1-based font handle (> 0) on success; 0 if Name is NULL or no document is open. Per the resolution chain above, this essentially never fails for a valid handle and non-empty name.
Remarks — two more accepted-but-unused parameters. Embed and CP are part of the exported signature but are not passed through to TLumasPdfDoc.SetFont at all — whether a font ends up embedded is decided entirely by the resolution chain (standard-14 never embeds; a resolved TrueType file is always embedded; the last-resort literal-name fallback never embeds), not by this flag. CP (a requested codepage for narrow-string decoding) is likewise inert here.
See also — pdfSetFontEx, pdfChangeFontStyle
C# (P/Invoke)
public static extern int pdfSetFontA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string Name, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
public static extern int pdfSetFontW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string Name, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
Setters
pdfSetFontA
pdfSetFontW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.