Skip to content

Latest commit

 

History

History
113 lines (78 loc) · 4.68 KB

create.md

File metadata and controls

113 lines (78 loc) · 4.68 KB

PDF Creation - Buffer Format

Parameters

Properties Definition
html (IHTMLProps) Html file or string, data to fill the variables and can have also handlebars options.
pdf (IPDFProps) Puppeteer pdf format and options

Returns

Return Type
Returns 3 functions that retrieves different pdf formats, toBuffer(), toStream() and toFile() Promise<HTMLTwoPDFResult>

Examples

Creating pdf and returning a Buffer file:

import { HTMLTwoPDF } from 'htmltwopdf';

type PDFTestData {
    title: string;
    subtitle: string;
}

const document = {
    html: '{{ title }} - {{ subtitle }}', // Can be also a html file
    data: { title: 'Test PDF', subtitle: 'htmltwopdf' }, // Here goes the data to be filled on your handlebars template.
};

const pdf = new HTMLTwoPDF();
const newPdf = await pdf.create<PDFTestData>({ document });

const bufferPdf = newPdf.toBuffer();

PDF Creation - Stream Format

Parameters

Properties Definition
html (IHTMLProps) Html file or string, data to fill the variables and can have also handlebars options.
pdf (IPDFProps) Puppeteer pdf format and options

Returns

Return Type
Returns 3 functions that retrieves different pdf formats, toBuffer(), toStream() and toFile() Promise<HTMLTwoPDFResult>

Examples

Creating pdf and returning a Stream file:

import { HTMLTwoPDF } from 'htmltwopdf';

type PDFTestData {
    title: string;
    subtitle: string;
}

const document = {
    html: '{{ title }} - {{ subtitle }}', // Can be also a html file
    data: { title: 'Test PDF', subtitle: 'htmltwopdf' }, // Here goes the data to be filled on your handlebars template.
};

const pdf = new HTMLTwoPDF();
const newPdf = await pdf.create<PDFTestData>({ document });

const streamPdf = newPdf.toStream();

PDF Creation - File Format

Parameters

Properties Definition
html (IHTMLProps) Html file or string, data to fill the variables and can have also handlebars options.
pdf (IPDFProps) Puppeteer pdf format and options

Returns

Return Type
Returns 3 functions that retrieves different pdf formats, toBuffer(), toStream() and toFile() Promise<HTMLTwoPDFResult>

Examples

Creating pdf and saving a .pdf file:

import { HTMLTwoPDF } from 'htmltwopdf';

type PDFTestData {
    title: string;
    subtitle: string;
}

const document = {
    html: '{{ title }} - {{ subtitle }}', // Can be also a html file
    data: { title: 'Test PDF', subtitle: 'htmltwopdf' }, // Here goes the data to be filled on your handlebars template.
};

const pdf = new HTMLTwoPDF();
const newPdf = await pdf.create<PDFTestData>({ document });

newPdf.toFile('./your_path');