Class: PDFBuilder

PDFBuilder(options)

Builds the PDF

Constructor

new PDFBuilder(options)

Parameters:
Name Type Description
options Object

The options used to build the PDF

Properties
Name Type Default Description
title string

The title of the document

includePageNumber boolean true

Document includes page numbers

documentFont string Helvetica

The default font style for document

documentBoldFont string Helvetica-Bold

The default bold font style for document

headingFont string options.documentBoldFont

The font style of the page heading

headingFontSize number 16

The heading font size

headingLineGap number 18

The heading line gap

subHeadingFont string options.documentBoldFont

The font style of the subheading

subHeadingFontSize number 14

The subheading font size

subHeadingLineGap number 12

The subheading line gap

layout portrait | landscape portrait

The page layout style

margin Margin

Margin of the page

size letter

The size of the generated PDF

metadata metadata

Additional data stored on the object.

Source:

Methods

addHeading(text)

Add a heading to the PDF document.

Parameters:
Name Type Description
text string

The heading to add

Source:

addPage()

Add a new page to the PDF document.

Source:

addPageIfNeeded(currentPage, pageCount) → {boolean}

Adds a new page to the PDF document if close to the end of the content area.

Parameters:
Name Type Description
currentPage number

The current page of the document

pageCount number

The number of pages

Source:
Returns:

Was a new page added

Type
boolean

addSubHeading(text)

Add a sub heading to the PDF document.

Parameters:
Name Type Description
text String

The subheading text to add

Source:

addTable(table)

Add a table to the PDF document.

Parameters:
Name Type Description
table PDFTable

The table to add to the PDF

Source:

contentHeight() → {number}

Returns the height of the page inside the page margins.

Source:
Returns:
Type
number

contentWidth() → {number}

Returns the width of the page inside the page margins.

Source:
Returns:

The width of the page inside the page margins

Type
number

generateBlob() → {Promise}

Closes the document and generates blob URL that can be saved to disk.

Source:
Returns:

Resolves when the PDF has been generated

Type
Promise
Example
let pdfBuilder = new PDFBuilder();
let saveAs = require('file-saver');
pdfBuilder.generateBlob().then(function(blob) {
  saveAs(blob, 'document.pdf');
});

generateBlobURL() → {Promise}

Closes the document and generates blob URL that can be loaded by a web browser.

Source:
Returns:

Resolves when the PDF Url has been generated

Type
Promise
Example
let pdfBuilder = new PDFBuilder();
pdfBuilder.generateBlobURL().then(function(url) {
  $('iframe')[0].src = url;
});

pageLeft() → {number}

Returns the position of the left edge of the page based on left margin.

Source:
Returns:

The position of the left edge of the page

Type
number

Returns the position of the right edge of the page based on the width and right margin.

Source:
Returns:

The position of the right edge of the page

Type
number

resetPosition()

Sets the current print position to the top-left of the document + margins.

Source: