Class PdfFontSettings
The PdfFontSettings class provides a convenient way to manage settings for TrueType fonts.
Inheritance
Namespace: Syncfusion.Pdf.Graphics.Fonts
Assembly: Syncfusion.Pdf.UWP.dll
Syntax
public class PdfFontSettings : Object
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Load the TrueType font from the local *.ttf file.
FileStream fontStream = new FileStream("Arial.ttf", FileMode.Open, FileAccess.Read);
// Initialize the PdfFontSettings
PdfFontSettings fontSettings = new PdfFontSettings(10, PdfFontStyle.Bold, true, true, true);
PdfFont pdfFont = new PdfTrueTypeFont(fontStream, fontSettings);
//Draw the text.
graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As PdfDocument = New PdfDocument
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Use the fontStream installed in the machine.
Dim fontStream As FileStream = New FileStream("Arial.ttf", FileMode.Open, FileAccess.Read)
Dim fontSettings As PdfFontSettings = New PdfFontSettings(10, PdfFontStyle.Bold, true, true, true)
Dim pdfFont As PdfFont = New PdfTrueTypeFont(fontStream, fontSettings)
'Draw the text.
graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(true)
Constructors
PdfFontSettings(Single, PdfFontStyle, Boolean, Boolean, Boolean)
Initializes a new instance of the PdfFontSettings class with the specified font style, font size, embed and subset options.
Declaration
public PdfFontSettings(float fontSize, PdfFontStyle style, bool embed, bool subset, bool useFloatingFactorForMeasure)
Parameters
Type | Name | Description |
---|---|---|
System.Single | fontSize | The font size, in points, to use when rendering text with this font. |
PdfFontStyle | style | The style of the font |
System.Boolean | embed | A boolean value that specifies whether to embed the font with the PDF document. |
System.Boolean | subset | A boolean value that specifies whether to subset the font to only include the characters used in the document. |
System.Boolean | useFloatingFactorForMeasure | "A boolean value that specifies whether to use a floating-point value type to measure width and render." |
Remarks
If the embed parameter is true, the font stream data will be embedded in the PDF document. This ensures that the font will be available for viewing and printing, even if the original font is not installed on the user's computer. If the subset parameter is true, only the characters used in the document will be included in the embedded font. This can reduce the size of the PDF document, but may also make it more difficult to edit the document in the future.
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Load the TrueType font from the local *.ttf file.
FileStream fontStream = new FileStream("Arial.ttf", FileMode.Open, FileAccess.Read);
// Initialize the PdfFontSettings
PdfFontSettings fontSettings = new PdfFontSettings(10, PdfFontStyle.Bold, true, true, true);
PdfFont pdfFont = new PdfTrueTypeFont(fontStream, fontSettings);
//Draw the text.
graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, new PointF(0, 0));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As PdfDocument = New PdfDocument
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Use the fontStream installed in the machine.
Dim fontStream As FileStream = New FileStream("Arial.ttf", FileMode.Open, FileAccess.Read)
Dim fontSettings As PdfFontSettings = New PdfFontSettings(10, PdfFontStyle.Bold, true, true, true)
Dim pdfFont As PdfFont = New PdfTrueTypeFont(fontStream, fontSettings)
'Draw the text.
graphics.DrawString("Hello World!!!", pdfFont, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(true)