| Category | Font loading |
|---|---|
| Note | Index/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
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);
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
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle with an open document. |
FontFile | string | Path to a TrueType or Type 1 font file. |
Index | Cardinal | Accepted 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. |
Style | TFStyle | Accepted for ABI compatibility; not used to select among variants (the file has one font program). |
Size | Double | Initial point size. |
Embed | BOOL32 | Accepted 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). |
CP | TCodepage | Accepted 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 also — pdfLoadFont, pdfReplaceFontEx (which, by contrast, does not load an arbitrary file's bytes)
C# (P/Invoke)
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);
Core
pdfLoadFontExA
pdfLoadFontExW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.