PdfDestinationPageNumberField
6 Jul 20266 minutes to read
Represents an automatic field that shows the page number of a specified destination page within the document.
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Initialize standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13);
// Initialize brush.
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Create a destination page number field with the specified properties.
const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({ font: font, brush: brush });
// Add pages and set the destination to the final page and draw the field there.
for (let i = 0; i < 5; i++) {
const page: PdfPage = document.addPage();
if (i === 4) {
destinationPageField.page = page;
destinationPageField.draw(page.graphics, { x: 10, y: 10 });
}
}
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();Properties
Get numberStyle PdfNumberStyle
Gets the current number formatting style of the field.
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add new page to document
const page: PdfPage = document.addPage();
// Initialize standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
// Initialize solid brush
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Construct the field with specified properties.
const field: PdfPageNumberField = new PdfPageNumberField({ font: font, brush: brush, numberStyle: PdfNumberStyle.numeric });
// Gets the current number formatting style of the field
const style: PdfNumberStyle = field.numberStyle;
// Draw the field on page graphics
field.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save('Output.pdf');
// Destroy the document
document.destroy();Set numberStyle void
Sets the number formatting style of the field.
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add new page to document
const page: PdfPage = document.addPage();
// Initialize standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
// Initialize solid brush
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Construct the field with specified properties.
const field: PdfPageNumberField = new PdfPageNumberField({ font: font, brush: brush});
// Sets the number formatting style of the field.
field.numberStyle = PdfNumberStyle.numeric;
// Draw the field on page graphics
field.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save('Output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | PdfNumberStyle |
The number formatting style to apply. |
Get page PdfPage
Gets the currently assigned destination page.
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add new page to document
const page: PdfPage = document.addPage();
// Initialize standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13);
// Initialize brush.
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Initialize a string format.
const format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right);
// Create a destination page number field with the specified properties.
const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({font: font, brush: brush, stringFormat: format, numberStyle: PdfNumberStyle.numeric, page: page});
// Get the assigned destination page
const destinationPage: PdfPage = destinationPageField.page;
// Draw the destination page field.
destinationPageField.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();Set page void
Sets the destination page of the field.
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add new page to document
const page: PdfPage = document.addPage();
// Initialize standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 13);
// Initialize brush.
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Initialize a string format.
const format: PdfStringFormat = new PdfStringFormat(PdfTextAlignment.right);
// Create a destination page number field with the specified properties.
const destinationPageField: PdfDestinationPageNumberField = new PdfDestinationPageNumberField({font: font, brush: brush, stringFormat: format, numberStyle: PdfNumberStyle.numeric});
// Set destination and draw on the destination page.
destinationPageField.page = page;
// Draw the destination page field.
destinationPageField.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save(‘output.pdf’);
// Destroy the document.
document.destroy();
@param {PdfPage} value The destination page.
Parameters: value: [`PdfPage`](./pdfPage)
## Methods
### draw
Renders the element at the specified location on the given `PdfGraphics` surface.
```typescript
// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add a new page to document
const page: PdfPage = document.addPage();
// Create a page template with specified size.
const template: PdfPageTemplateElement = new PdfPageTemplateElement({ width: 100, height: 50 });
// Initialize a standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
// Create a solid brush for drawing text.
const brush: PdfBrush = new PdfBrush({ r: 0, g: 0, b: 0 });
// Create a date-time field with the configured font and brush.
const dateField: PdfGraphicsElement = new PdfDateTimeField({ font: font, brush: brush });
// Render the date field onto the template at an offset.
dateField.draw(template.graphics, { x: 20, y: 20 });
// Assign the template to the document bottom with center alignment.
document.template.bottom = {template: template, alignment: PdfTemplateHorizontalAlignment.center};
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();
| Parameter | Type | Description |
|---|---|---|
| graphics | PdfGraphics |
The graphics surface to render on. |
| location | Point |
The position for rendering. |
Returns void