HelpBot Assistant

How can I help you?

PdfDocument

6 Feb 20263 minutes to read

Represents a PDF document and can be used to create a new PDF document from the scratch.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a new page to the document
let page1 : PdfPage = document.pages.add();
// set the font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// create black brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(0, 0));
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

Properties

Get pageSettings PdfPageSettings

Gets the document’s page setting.
// sets the right margin of the page
document.pageSettings.margins.right = 0;
// set the page size.
document.pageSettings.size = new SizeF(500, 500);
// change the page orientation to landscape
document.pageSettings.orientation = PdfPageOrientation.Landscape;
// apply 90 degree rotation on the page
document.pageSettings.rotate = PdfPageRotateAngle.RotateAngle90;

// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
// set the specified Point
let point : PointF = new PointF(page1.getClientSize().width - 200, page1.getClientSize().height - 200);
// draw the text
page1.graphics.drawString(‘Hello World’, font, blackBrush, point);
// save the document
document.save(‘output.pdf’);
// destroy the document
document.destroy();



### Set pageSettings `void`

Sets the document's page setting.
```typescript
// create a new PDF document
let document : PdfDocument = new PdfDocument();
// sets the right margin of the page
document.pageSettings.margins.right = 0;
// set the page size.
document.pageSettings.size = new SizeF(500, 500);
// change the page orientation to landscape
document.pageSettings.orientation = PdfPageOrientation.Landscape;
// apply 90 degree rotation on the page
document.pageSettings.rotate = PdfPageRotateAngle.RotateAngle90;

// add a pages to the document
let page1 : PdfPage = document.pages.add();
// set font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// set brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
// set the specified Point
let point : PointF = new PointF(page1.getClientSize().width - 200, page1.getClientSize().height - 200);
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, point);
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

Parameters: value: PdfPageSettings

Get pages PdfDocumentPageCollection

Represents the collection of pages in the PDF document.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
//
// get the collection of pages in the document
let pageCollection : PdfDocumentPageCollection  = document.pages;
//
// add pages
let page1 : PdfPage = pageCollection.add();
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

Get viewerPreferences PdfViewerPreferences

Gets viewer preferences for presenting the PDF document in a viewer.

// Create a new PDF document
let document : PdfDocument = new PdfDocument();
// Gets viewer preferences
let viewerPreferences : PdfViewerPreferences = document.viewerPreferences;
// Destroy the document
document.destroy();

Methods

destroy

disposes the current instance of PdfDocument class.

// create a new PDF document
let document : PdfDocument = new PdfDocument();
// add a new page to the document
let page1 : PdfPage = document.pages.add();
// set the font
let font : PdfStandardFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
// create black brush
let blackBrush : PdfSolidBrush = new PdfSolidBrush(new PdfColor(0, 0, 0));
// draw the text
page1.graphics.drawString('Hello World', font, blackBrush, new PointF(0, 0));
// save the document
document.save('output.pdf');
// destroy the document
document.destroy();

Returns void

save

Saves the document to the specified filename.

Returns Promise

save

Saves the document to the specified filename.

Parameter Type Description
filename string Specifies the file name to save the output pdf document.

Returns void