Table of Contents

Class PdfTrueTypeFont

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

Represents TrueType font.

public class PdfTrueTypeFont : PdfFont, IDisposable
Inheritance
PdfTrueTypeFont
Implements
Inherited Members

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, float)

Initializes a new instance of the PdfTrueTypeFont class with prototype and it's size

public PdfTrueTypeFont(PdfTrueTypeFont prototype, float size)

Parameters

prototype PdfTrueTypeFont

The PdfTrutypeFont using as a prototype.

size float

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(Stream, PdfFontSettings)

Initializes a new instance of the PdfTrueTypeFont class with the specified font stream and font settings options.

public PdfTrueTypeFont(Stream fontStream, PdfFontSettings fontSettings)

Parameters

fontStream Stream

A Stream object that represents the font stream data.

fontSettings PdfFontSettings

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, bool, PdfFontStyle, float)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(Stream fontStream, bool embed, PdfFontStyle style, float size)

Parameters

fontStream Stream
embed bool

Embedded.

style PdfFontStyle

The style.

size float

The size.

PdfTrueTypeFont(Stream, float)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(Stream fontStream, float size)

Parameters

fontStream Stream
size float

The size.

PdfTrueTypeFont(Stream, float, PdfFontStyle)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(Stream fontStream, float size, PdfFontStyle style)

Parameters

fontStream Stream
size float

The size.

style PdfFontStyle

The style.

PdfTrueTypeFont(Stream, float, bool, bool)

Initializes a new instance of the PdfTrueTypeFont class with the specified font stream, font size, and embedding options.

public PdfTrueTypeFont(Stream fontStream, float size, bool embed, bool subset)

Parameters

fontStream Stream

A Stream object that represents the font stream data.

size float
embed bool

A boolean value that specifies whether to embed the font with the PDF document.

subset bool

A boolean value that specifies whether to subset the font to only include the characters used in the document.

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)

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.

PdfTrueTypeFont(string, bool, PdfFontStyle, float)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(string fontFile, bool embed, PdfFontStyle style, float size)

Parameters

fontFile string

The font file.

embed bool

Embedded.

style PdfFontStyle

The style.

size float

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;         
//Create a new PDF true type font instance.
PdfFont font = new PdfTrueTypeFont("Arial.ttf",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        
'Create a new PDF true type font instance.
Dim font As PdfFont = New PdfTrueTypeFont("Arial.ttf",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(string, float)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(string fontFile, float size)

Parameters

fontFile string

The font file.

size float

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;         
//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, float, PdfFontStyle)

Initializes a new instance of the PdfTrueTypeFont class.

public PdfTrueTypeFont(string fontFile, float size, PdfFontStyle style)

Parameters

fontFile string

The font file.

size float

The size.

style PdfFontStyle

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;         
//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.

protected static object s_rtlRenderLock

Field Value

object

Properties

Unicode

Gets a value indicating whether this PdfTrueTypeFont is Unicode enabled (Read only).

public bool Unicode { get; }

Property Value

bool

true if Unicode; otherwise, false.

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.

public void Dispose()

Remarks

Don't dispose the font until the corresponding document is closed.

EqualsToFont(PdfFont)

Checks whether fonts are equals.

protected override bool EqualsToFont(PdfFont font)

Parameters

font PdfFont

Font to compare.

Returns

bool

True if fonts are equal, False otherwise.

~PdfTrueTypeFont()

Releases unmanaged resources and performs other cleanup operations before the PdfTrueTypeFont is reclaimed by garbage collection.

protected ~PdfTrueTypeFont()

GetCharWidth(char, PdfStringFormat)

Returns width of the char.

protected override float GetCharWidth(char charCode, PdfStringFormat format)

Parameters

charCode char

Char symbol.

format PdfStringFormat

String format.

Returns

float

Width of the symbol.

GetLineWidth(string, PdfStringFormat)

Returns width of the line.

protected override float GetLineWidth(string line, PdfStringFormat format)

Parameters

line string

Text line.

format PdfStringFormat

String format.

Returns

float

Width of the line.