API referenceFonts

pdfReplaceFont

Replace an already-registered document font (by its PDFFont

CategoryFont substitution
NoteNameIsFamilyName 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

C
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);
Delphi
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

ParameterTypeDescription
IPDFPPDFInstance handle.
PDFFontPointerA PFNT handle from pdfEnumDocFonts identifying the font entry to replace.
NamestringNew font name to resolve (system font search, then standard-14 fallback).
StyleIntegerAccepted but not itself passed to the resolver — the resolution uses the document's current global style (FCurrentFontStyle, set by pdfChangeFontStyle/Ex), not this parameter.
NameIsFamilyNameBOOL32Accepted 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 alsopdfReplaceFontEx

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
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);
Area
Fonts
Category

Core

Exported names

pdfReplaceFontA pdfReplaceFontW

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.