PDF

Collection of PDF functions.

Methods

create

create(htmlBody: string | string[], htmlHeader?: string, htmlFooter?: string, options?: { pageFormat?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6', landscape?: Boolean, margin?: { top?: Number, right?: Number, bottom?: Number, left?: Number } }) 

Create a PDF document.

Parameters

htmlBody string | string[]

The HTML to convert to PDF. Can be a single string or an array of strings for multiple pages.

htmlHeader string

(optional) The HTML header to use as header template in the PDF.

htmlFooter string

(optional) The HTML footer to use as footer template in the PDF.

options { pageFormat?: 'A4' | 'Letter' | 'Legal' | 'Ledger' | 'Tabloid' | 'A0' | 'A1' | 'A2' | 'A3' | 'A5' | 'A6', landscape?: Boolean, margin?: { top?: Number, right?: Number, bottom?: Number, left?: Number } }

(optional) The additional PDF options.

Return type

string

Examples

// The HTML body is the only required parameter
PDF.create('Hello World!');

// You can also add multiple pages, header and footer templates and custom formatting and styling
PDF.create(
    [
        // Use multiple strings for multiple pages
        '<h1>Hello World!</h1>',
        '<p>Hello World Too!</p>',
        '<span>A third page</span>',
    ],
    '<div style="width: 100%; text-align: center">This is the header</div>',
    '<div style="width: 100%; margin-right: 25px; text-align: right">
    // Use pageNumbers and totalPages classes to display page numbers
    Page: <span class="pageNumber"></span>/<span class="totalPages"></span>
    </div>',
    // Set additional PDF options
    {
        pageFormat: 'Letter',
        margin: {bottom: 70, left: 25, right: 35, top: 30}
    }
);