| Category | Font substitution |
|---|---|
| Note | NameIsFamilyName accepted but unused |
Purpose — Replace an already-registered document font (by its PDFFont enumeration handle, from pdfEnumDocFonts) with a different font, resolved by name.
Description — a real resolve-and-swap, not a blind rename. Resolves Name via ResolvePdfBaseFont using the current global style (FCurrentFontStyle); if that resolves to a standard-14 name, the entry becomes a clean non-embedded Type 1 reference. Otherwise, it searches installed system fonts for Name and — if found — loads that font file and swaps in its real font program (so the replacement is embeddable via /FontFile2, not just a /BaseFont string change); if no matching system font exists, it falls back to a rename-only (/BaseFont := Name, unembedded). Any existing width/metrics snapshot the caller holds via PDFFont is refreshed in place.
Declarations
int32_t __stdcall pdfReplaceFontA(PPDF IPDF, void* PDFFont, const char* Name, int32_t Style, BOOL32 NameIsFamilyName);
int32_t __stdcall pdfReplaceFontW(PPDF IPDF, void* PDFFont, const wchar_t* Name, int32_t Style, BOOL32 NameIsFamilyName);
function pdfReplaceFontA(const IPDF: PPDF; const PDFFont: Pointer; const Name: PAnsiChar; Style: Integer; NameIsFamilyName: LongBool): Integer; stdcall; external 'LumasPdf.dll';
function pdfReplaceFontW(const IPDF: PPDF; const PDFFont: Pointer; const Name: PWideChar; Style: Integer; NameIsFamilyName: LongBool): Integer; stdcall; external 'LumasPdf.dll';
Parameters
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle. |
PDFFont | Pointer | A PFNT handle from pdfEnumDocFonts identifying the font entry to replace. |
Name | string | New font name to resolve (system font search, then standard-14 fallback). |
Style | Integer | Accepted but not itself passed to the resolver — the resolution uses the document's current global style (FCurrentFontStyle, set by pdfChangeFontStyle/Ex), not this parameter. |
NameIsFamilyName | BOOL32 | Accepted for ABI compatibility; not read by this implementation — there is no separate family-vs-full-name handling path. |
Return value — The entry's handle on success; 0 if PDFFont doesn't match a known font enumeration or Name is empty.
See also — pdfReplaceFontEx
C# (P/Invoke)
public static extern int pdfReplaceFontA(IntPtr IPDF, IntPtr PDFFont, [MarshalAs(UnmanagedType.LPStr)] string Name, int Style, [MarshalAs(UnmanagedType.Bool)] bool NameIsFamilyName);
public static extern int pdfReplaceFontW(IntPtr IPDF, IntPtr PDFFont, [MarshalAs(UnmanagedType.LPWStr)] string Name, int Style, [MarshalAs(UnmanagedType.Bool)] bool NameIsFamilyName);
Core
pdfReplaceFontA
pdfReplaceFontW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.