Class PdfTrueTypeFont
Represents TrueType font.
Implements
Inherited Members
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfTrueTypeFont : PdfFont, IPdfWrapper, IPdfCache, IDisposable
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(sFont);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(sFont)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Constructors
PdfTrueTypeFont(PdfTrueTypeFont, Single)
Initializes a new instance of the PdfTrueTypeFont class with prototype and it's size
Declaration
public PdfTrueTypeFont(PdfTrueTypeFont prototype, float size)
Parameters
Type | Name | Description |
---|---|---|
PdfTrueTypeFont | prototype | The PdfTrutypeFont using as a prototype. |
System.Single | size | The size of the font. |
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;
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(new PdfTrueTypeFont(new Font("Arial",12,FontStyle.Regular)), 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(New PdfTrueTypeFont(New Font("Arial",12,FontStyle.Regular)), 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font)
Initializes a new instance of the PdfTrueTypeFont class with specified Font
Declaration
public PdfTrueTypeFont(Font font)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(sFont);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(sFont)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font, PdfFontSettings)
Initializes a new instance of the PdfTrueTypeFont class with the specified font stream and font settings options.
Declaration
public PdfTrueTypeFont(Font font, PdfFontSettings fontSettings)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string. |
PdfFontSettings | fontSettings | The option to manage settings for TrueType fonts. |
Remarks
The system font style is used to determine the font style of the PdfTrueTypeFont 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;
//Use the font installed in the machine
Font font = new Font("Arial", 14);
// Initialize the PdfFontSettings
PdfFontSettings fontSettings = new PdfFontSettings(10, PdfFontStyle.Bold, true, true, true);
PdfFont pdfFont = new PdfTrueTypeFont(font, 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 font installed in the machine.
Dim font As Font = New Font("Arial", 14)
'Initialize the PdfFontSettings.
Dim fontSettings As PdfFontSettings = New PdfFontSettings(10, PdfFontStyle.Bold, true, true, true)
Dim pdfFont As PdfFont = New PdfTrueTypeFont(font, 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)
PdfTrueTypeFont(Font, Boolean)
Initializes a new instance of the PdfTrueTypeFont class with font and Boolean flag to set the Unicode of the PDF font
Declaration
public PdfTrueTypeFont(Font font, bool unicode)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string |
System.Boolean | unicode | The boolean flag represents the support of unicode text |
Remarks
This Constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create a truetype font
PdfFont font = new PdfTrueTypeFont(new Font("Arial", 14),true);
//Draw the text.
graphics.DrawString("Hello World!!!", font, 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 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
'Create a truetype font
Dim font As PdfFont = New PdfTrueTypeFont(New Font("Arial", 14), True)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font, FontStyle, Single, Boolean, Boolean)
Initializes a new instance of the PdfTrueTypeFont class with font,font style,size,Boolean flag to set Unicode and Boolean flag to embed the font into the PDF
Declaration
public PdfTrueTypeFont(Font font, FontStyle style, float size, bool unicode, bool embed)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string |
System.Drawing.FontStyle | style | The style of the font. |
System.Single | size | The size of the font. |
System.Boolean | unicode | The boolean flag represents the support of unicode text |
System.Boolean | embed | The boolean flag represents to embed the font into the pdf |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(sFont, FontStyle.Regular, 12, true, true);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(sFont, FontStyle.Regular, 12, True, True)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font, Single)
Initializes a new instance of the PdfTrueTypeFont class with font and it's size
Declaration
public PdfTrueTypeFont(Font font, float size)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string |
System.Single | size | The size of the font. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(sFont, 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(sFont, 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font, Single, Boolean)
Initializes a new instance of the PdfTrueTypeFont class with font, size and Boolean flag to set Unicode.
Declaration
public PdfTrueTypeFont(Font font, float size, bool unicode)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | The system font that defines the text format of the string |
System.Single | size | The size of the font. |
System.Boolean | unicode | The boolean flag represents the support of unicode text |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create a truetype font
PdfFont font = new PdfTrueTypeFont(new Font("Arial", 14),12,true);
//Draw the text.
graphics.DrawString("Hello World!!!", font, 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 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
'Create a truetype font
Dim font As PdfFont = New PdfTrueTypeFont(New Font("Arial", 14), 12, True)
'Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Font, Single, Boolean, Boolean)
Initializes a new instance of the PdfTrueTypeFont class with the specified Font object, font size, and embedding options.
Declaration
public PdfTrueTypeFont(Font font, float size, bool embed, bool subset)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Font | font | A Font object that represents the font to use. |
System.Single | size | |
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. |
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(sFont, 12, true, false);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(sFont, 12, true, false)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Stream, PdfFontSettings)
Initializes a new instance of the PdfTrueTypeFont class with the specified font stream and font settings options.
Declaration
public PdfTrueTypeFont(Stream fontStream, PdfFontSettings fontSettings)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | A Stream object that represents the font stream data. |
PdfFontSettings | fontSettings | The option to manage settings for TrueType fonts. |
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)
PdfTrueTypeFont(Stream, Boolean, PdfFontStyle, Single)
Initializes a new instance of the PdfTrueTypeFont class.
Declaration
public PdfTrueTypeFont(Stream fontStream, bool embed, PdfFontStyle style, float size)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | |
System.Boolean | embed | Embedded. |
PdfFontStyle | style | The style. |
System.Single | size | The size. |
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;
//Read a font file stream.
Stream fontStream = new MemoryStream(File.ReadAllBytes("arial.ttf"));
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(fontStream, false, PdfFontStyle.Regular, 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Read a font file stream.
Dim fontStream As Stream = New MemoryStream(File.ReadAllBytes("arial.ttf"))
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(fontStream, false, PdfFontStyle.Regular, 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Stream, Single)
Initializes a new instance of the PdfTrueTypeFont class.
Declaration
public PdfTrueTypeFont(Stream fontStream, float size)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | The font stream. |
System.Single | size | The size of the font. |
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;
//Read a font file stream.
Stream fontStream = new MemoryStream(File.ReadAllBytes("arial.ttf"));
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(fontStream, 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Read a font file stream.
Dim fontStream As Stream = New MemoryStream(File.ReadAllBytes("arial.ttf"))
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(fontStream, 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Stream, Single, PdfFontStyle)
Initializes a new instance of the PdfTrueTypeFont class.
Declaration
public PdfTrueTypeFont(Stream fontStream, float size, PdfFontStyle style)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | |
System.Single | size | The size. |
PdfFontStyle | style | The style. |
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;
//Read a font file stream.
Stream fontStream = new MemoryStream(File.ReadAllBytes("arial.ttf"));
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(fontStream, 12, PdfFontStyle.Regular);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Read a font file stream.
Dim fontStream As Stream = New MemoryStream(File.ReadAllBytes("arial.ttf"))
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(fontStream, 12, PdfFontStyle.Regular)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(Stream, Single, Boolean, Boolean)
Initializes a new instance of the PdfTrueTypeFont class with the specified font stream, font size, and embedding options.
Declaration
public PdfTrueTypeFont(Stream fontStream, float size, bool embed, bool subset)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fontStream | A Stream object that represents the font stream data. |
System.Single | size | |
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. |
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;
//Read a font file stream.
Stream fontStream = new MemoryStream(File.ReadAllBytes("arial.ttf"));
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont(fontStream, 12, true, false);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Read a font file stream.
Dim fontStream As Stream = New MemoryStream(File.ReadAllBytes("arial.ttf"))
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont(fontStream, 12, true, false)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(String, Single)
Initializes a new instance of the PdfTrueTypeFont class with the path of the font file which has the extension of .ttf and it's size
Declaration
public PdfTrueTypeFont(string fontFile, float size)
Parameters
Type | Name | Description |
---|---|---|
System.String | fontFile | The font file path which has the extension of .ttf. |
System.Single | size | The size of the font. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont("arial.ttf", 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont("arial.ttf", 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
PdfTrueTypeFont(String, Single, PdfFontStyle)
Initializes a new instance of the PdfTrueTypeFont class with the path of the font file which has the extension of .ttf, size and font style
Declaration
public PdfTrueTypeFont(string fontFile, float size, PdfFontStyle style)
Parameters
Type | Name | Description |
---|---|---|
System.String | fontFile | The font file path. |
System.Single | size | The size of the font. |
PdfFontStyle | style | The style of the font. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
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;
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont("arial.ttf", 12, PdfFontStyle.Regular);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont("arial.ttf", 12, PdfFontStyle.Regular)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Fields
s_rtlRenderLock
Create Instance of the rtl render lock.
Declaration
protected static object s_rtlRenderLock
Field Value
Type |
---|
System.Object |
Properties
Unicode
Gets a value indicating whether this PdfTrueTypeFont is Unicode enabled (Read only).
Declaration
public bool Unicode { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
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;
//Create new system font.
Font sFont = new Font("Arial", 12, FontStyle.Regular);
//Create a new PDF true type font instance.
PdfTrueTypeFont font = new PdfTrueTypeFont(sFont, 12, true);
//Check unicode support.
bool isUnicode = font.Unicode;
//Draw string to PDF page.
graphics.DrawString("Unicode Font = " + isUnicode, font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As 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
'Create new system font.
Dim sFont As New Font("Arial", 12, FontStyle.Regular)
'Create a new PDF true type font instance.
Dim font As PdfTrueTypeFont = New PdfTrueTypeFont(sFont, 12, True)
'Check unicode support.
Dim isUnicode As Boolean = font.Unicode
'Draw string to PDF page.
graphics.DrawString("Unicode Font = " + isUnicode, font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Methods
Dispose()
Releases all resources of the font.
Declaration
public void Dispose()
Remarks
Don't dispose the font until the corresponding document is closed.
EqualsToFont(PdfFont)
Checks whether fonts are equals.
Declaration
protected override bool EqualsToFont(PdfFont font)
Parameters
Type | Name | Description |
---|---|---|
PdfFont | font | Font to compare. |
Returns
Type | Description |
---|---|
System.Boolean | True if fonts are equal, False otherwise. |
Overrides
Finalize()
Releases unmanaged resources and performs other cleanup operations before the PdfTrueTypeFont is reclaimed by garbage collection.
Declaration
protected void Finalize()
GetCharWidth(Char, PdfStringFormat)
Returns width of the char.
Declaration
protected override float GetCharWidth(char charCode, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Char | charCode | Char symbol. |
PdfStringFormat | format | String format. |
Returns
Type | Description |
---|---|
System.Single | Width of the symbol. |
Overrides
GetLineWidth(String, PdfStringFormat)
Returns width of the line.
Declaration
protected override float GetLineWidth(string line, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.String | line | Text line. |
PdfStringFormat | format | String format. |
Returns
Type | Description |
---|---|
System.Single | Width of the line. |