PdfCreationDateField

6 Jul 20264 minutes to read

Represents an automatic field that displays the creation date of the document.

// Create a new document.
const document: PdfDocument = new PdfDocument();
// Add new page to document.
const page = document.addPage();
// Define document creation date.
const creationDate: Date = new Date('2026-05-08T12:00:00');
// Set document information.
document.setDocumentInformation({title: 'Creation Date Sample', creationDate: creationDate});
// Initialize the standard font.
const font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.helvetica, 12);
// Initialize the brush.
const brush: PdfBrush = new PdfBrush({ r: 255, g: 0, b: 0 });
// Create the creation date field.
const dateField: PdfCreationDateField = new PdfCreationDateField({ font: font, brush: brush });
// Draw the creation date field.
dateField.draw(page.graphics, { x: 20, y: 10 });
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();

Properties

Get dateFormatString string

Gets the date format string currently used to render the creation date.

// Create a new PDF document.
const document: PdfDocument = new PdfDocument();
// Add a page to document.
const page: PdfPage = document.addPage();
// Define document creation date.
const creationDate: Date = new Date('2026-05-08T12:00:00');
// Set document information.
document.setDocumentInformation({title: 'Creation Date Sample', creationDate: creationDate});
// Create a creation date field.
const field: PdfCreationDateField = new PdfCreationDateField({dateFormat: 'yyyy/MM/dd'});
// Get the date format string
const stringFormat: string = field.dateFormatString;
// Draw the field on the page.
field.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();

Set dateFormatString void

Sets the date format string used to render the creation date.

// Create a new PDF document.
const document: PdfDocument = new PdfDocument();
// Add a page to document.
const page: PdfPage = document.addPage();
// Define document creation date.
const creationDate: Date = new Date('2026-05-08T12:00:00');
// Set document information.
document.setDocumentInformation({title: 'Creation Date Sample', creationDate: creationDate});
// Create a creation date field.
const field: PdfCreationDateField = new PdfCreationDateField();
// Set the date format string.
field.dateFormatString = 'yyyy/MM/dd';
// Draw the field on the page.
field.draw(page.graphics, { x: 10, y: 10 });
// Save the document.
document.save('output.pdf');
// Destroy the document.
document.destroy();
Parameter Type Description
value string The date format string to apply.

Methods

draw

Renders the element at the specified location on the given PdfGraphics surface.

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