PdfFont
12 Sep 20257 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 = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
// Create a new PDF string format
let format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right, PdfVerticalAlignment.bottom);
// Draw the text
page.graphics.drawString('Helvetica', font, [0, 180, page.size[0], 40], undefined, new PdfBrush([0, 0, 255]), format);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
height number
Gets the font height.
isBold boolean
Gets the boolean flag indicating whether the font has bold style or not.
isItalic boolean
Gets the boolean flag indicating whether the font has italic style or not.
isStrikeout boolean
Gets the boolean flag indicating whether the font has strike out style or not.
isUnderline boolean
Gets the boolean flag indicating whether the font has underline style or not.
size number
Gets the size of the PDF font.
style PdfFontStyle
Gets the style of the PDF font.
Methods
measureString
Measures the size of a given text string when rendered using this PDF font.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font with respect to the string format.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| format | PdfStringFormat |
String format. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| format | PdfStringFormat |
String format. |
| charactersFitted | number |
Characters fitted. |
| linesFilled | number |
Lines filled. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font with respect to the maximum line width.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| width | number |
width. |
Returns number[]
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.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| width | number |
width. |
| format | PdfStringFormat |
String format. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| width | number |
width. |
| format | PdfStringFormat |
String format. |
| charactersFitted | number |
Characters fitted. |
| linesFilled | number |
Lines filled. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font with respect to the layout area.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| layoutArea | number[] |
Layout area. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font with respect to the layout area and string format.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| layoutArea | number[] |
Layout area. |
| format | PdfStringFormat |
String format. |
Returns number[]
measureString
Measures the size of a given text string when rendered using this PDF font.
| Parameter | Type | Description |
|---|---|---|
| text | string |
Text. |
| layoutArea | number[] |
Layout area. |
| format | PdfStringFormat |
String format. |
| charactersFitted | number |
Characters fitted. |
| linesFilled | number |
Lines filled. |
Returns number[]