API referenceFonts

pdfLoadFontEx

Load a font directly from a file path — TrueType (.ttf/

CategoryFont loading
NoteIndex/Embed/CP all accepted but unused (see Remarks); can genuinely fail

Purpose — Load a font directly from a file path — TrueType (.ttf/ .ttc/OpenType) or Type 1 (.pfb/.pfa), auto-detected by extension.

Description — genuinely loads the file's bytes (contrast with pdfReplaceFontEx). .pfb/.pfa extensions route to a dedicated Type 1 loader; anything else attempts TrueType parsing. Caches by filename, so loading the same path twice reuses the already-parsed font data. This call can fail (unlike pdfSetFont's never-fails chain) — a missing file or unparseable font data raises a real font-error (E_FONT_ERROR) and returns 0.

Declarations

C
int32_t __stdcall pdfLoadFontExA(PPDF IPDF, const char* FontFile, uint32_t Index, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
int32_t __stdcall pdfLoadFontExW(PPDF IPDF, const wchar_t* FontFile, uint32_t Index, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
Delphi
function pdfLoadFontExA(const IPDF: PPDF; const FontFile: PAnsiChar; Index: Cardinal; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';
function pdfLoadFontExW(const IPDF: PPDF; const FontFile: PWideChar; Index: Cardinal; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle with an open document.
FontFilestringPath to a TrueType or Type 1 font file.
IndexCardinalAccepted but not read — intended (per the ABI shape) for selecting a face within a TrueType Collection (.ttc), but this build's loader always uses the first/only face; a specific-index face within a .ttc cannot be selected through this call.
StyleTFStyleAccepted for ABI compatibility; not used to select among variants (the file has one font program).
SizeDoubleInitial point size.
EmbedBOOL32Accepted but not read — TrueType loads are always embedded; Type 1 loads follow their own dedicated path (see the loader for that format, not detailed here).
CPTCodepageAccepted but not read.

Return value — 1-based font handle on success; 0 if the file doesn't exist or can't be parsed as a supported font format.

See alsopdfLoadFont, pdfReplaceFontEx (which, by contrast, does not load an arbitrary file's bytes)

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfLoadFontExA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FontFile, uint Index, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
public static extern int pdfLoadFontExW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string FontFile, uint Index, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
Area
Fonts
Category

Core

Exported names

pdfLoadFontExA pdfLoadFontExW

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.