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();
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();
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');