Syncfusion AI Assistant

How can I help you?

PdfFont

21 Apr 202615 minutes to read

Represents the base class for font objects.`

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Draw the text
page.graphics.drawString('Helvetica', font, {x: 0, y: 180, width: page.size.width, height: 40}, new PdfBrush({r: 0, g: 0, b: 255}), format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

Get height number

Gets the font height.

Get isBold boolean

Gets the boolean flag indicating whether the font has bold style or not.

Get isItalic boolean

Gets the boolean flag indicating whether the font has italic style or not.

Get isStrikeout boolean

Gets the boolean flag indicating whether the font has strike out style or not.

Get isUnderline boolean

Gets the boolean flag indicating whether the font has underline style or not.

Get size number

Gets the size of the PDF font.

Get style PdfFontStyle

Gets the style of the PDF font.

Set style void

Sets the style of the PDF font.

Parameter Type Description
value PdfFontStyle To font style.

Methods

_initializeInternals

Creates and assigns the internal font structures and resources.

Returns void

getLineWidth

Applies character and word spacing adjustments to the measured width.

Returns number

measureString

Measures the size of a given text string when rendered using this PDF font.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion');
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font with respect to the string format.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
format PdfStringFormat String format.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', format, 10, 10);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
format PdfStringFormat String format.
charactersFitted number Characters fitted.
linesFilled number Lines filled.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font with respect to the maximum line width.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', 50);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
width number width.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font with respect to the string format and maximum line width.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', 50, format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
width number width.
format PdfStringFormat String format.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', 50, format, 10, 10);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
width number width.
format PdfStringFormat String format.
charactersFitted number Characters fitted.
linesFilled number Lines filled.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font with respect to the layout area.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', {width: 100, height: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
layoutArea Size Layout area.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font with respect to the layout area and string format.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', {width: 100, height: 100}, format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
layoutArea Size Layout area.
format PdfStringFormat String format.

Returns Size

measureString

Measures the size of a given text string when rendered using this PDF font.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Gets the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Create a new PDF standard font
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Measure the size of the text
let size: Size = font.measureString('Syncfusion', format, {width: 0, height: 0}, 0, 0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
text string Text.
layoutArea Size Layout area.
format PdfStringFormat String format.
charactersFitted number Characters fitted.
linesFilled number Lines filled.

Returns Size