 |
PdfFont Class |
Represents a font in a pdf document. Five ways to create one:
- CreateStandardFont(PdfStandardFont, Single) — one of the 14 built-in
PDF fonts (Helvetica, Times, Courier, Symbol, ZapfDingbats). Fastest, smallest output,
but not embedded — rejected by PDF/A.
- CreateCJKFont(PdfStandardCJKFont, Single) — one of the 7 standard
CJK fonts. Also not embedded; shipped with PDF/A-compliant readers.
- CreateFromFile(String, Single) / CreateFromStream(Stream, Single)
/ CreateFromBytes(Byte, Single) — loads a TrueType (.ttf) or OpenType
(.otf) font from the filesystem or memory. The font is subset-embedded into the
output PDF, which is required for PDF/A output from scratch.
- CreateFromSystemFont(String, Single) — resolves a font installed on
the host system by family name. The font is subset-embedded, just like the file /
stream / bytes overloads.
Inheritance HierarchySystemObject
SelectPdf.UniversalPdfFont
Namespace: SelectPdf.UniversalAssembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.4
SyntaxThe PdfFont type exposes the following members.
Properties
Methods| | Name | Description |
|---|
 | Clone |
Creates a clone of this font, associated with the specified pdf document.
|
   | CreateCJKFont |
Creates a PdfFont from a standard Korean / Japanese / Chinese (CJK) font family.
Like CreateStandardFont(PdfStandardFont, Single), these fonts are
referenced by name (not embedded) — they ship with PDF/A-compliant readers, so the
output is expected to render on any conforming viewer.
|
  | CreateFromBytes |
Loads a TrueType / OpenType font from an in-memory byte array and creates a
PdfFont. Convenience wrapper around
CreateFromStream(Stream, Single); the font is subset-embedded into
the output.
|
   | CreateFromFile |
Loads a TrueType (.ttf) or OpenType (.otf) font from a file path and creates a
PdfFont. The font is subset-embedded into the output document — the
subset only contains glyphs that are actually used, keeping file size small.
This is the path to use for PDF/A and PDF/X output from scratch.
|
  | CreateFromStream |
Loads a TrueType / OpenType font from a Stream and creates a
PdfFont. The stream must be positioned at the start of the font
data and is read synchronously in full. The font is subset-embedded into the
output.
|
  | CreateFromSystemFont(PdfSystemFont) |
Resolves the system font described by systemFont and creates a
PdfFont. Equivalent to
CreateFromSystemFont(String, Single, PdfFontStyle) with the
descriptor's family / size / style.
|
   | CreateFromSystemFont(String, Single) |
Resolves a font installed on the host system by family name and creates a
PdfFont. Loads the actual TrueType / OpenType file via
PdfSystemFonts and subset-embeds it into the output document.
|
  | CreateFromSystemFont(String, Single, PdfFontStyle) |
Resolves a system font by family name + style and creates a PdfFont.
The font is subset-embedded into the output document.
|
   | CreateStandardFont |
Creates a PdfFont from a standard PDF font family and size.
|
 | GetCharWidth |
Gets the width of the specified character in points.
|
  | GetSystemFont |
Gets the system font this font was created from, or null when it did not come
from one.
|
 | GetTextSize |
Gets the size (width and height) in points of the specified string when rendered
with this font.
|
 | GetTextWidth |
Gets the width in points of the specified string.
|
Top
Remarks
Example
PdfFont font = PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 12f);
PdfDocument document = new PdfDocument();
document.Fonts.Add(font);
PdfFont title = PdfFont.CreateFromFile(@"C:\Windows\Fonts\arial.ttf", 22f);
float width = title.GetTextWidth("Hello world");
Dim font As PdfFont = PdfFont.CreateStandardFont(PdfStandardFont.Helvetica, 12.0F)
Dim document As New PdfDocument()
document.Fonts.Add(font)
Dim title As PdfFont = PdfFont.CreateFromFile("C:\Windows\Fonts\arial.ttf", 22.0F)
Dim width As Single = title.GetTextWidth("Hello world")
See Also