Repository URL to install this package:
|
Version:
1.0.2 ▾
|
@fbinhouse/inhouse-pdf2-api-lib
/
README.md
|
|---|
Import this package in to Node.JS projects where you want to speak to the PDF 2.0 engine (based on puppeteer).
Make sure your ~/.npmrc points the @fbinhouse namespace to the private gemfury fbinhouse account.
npm i @fbinhouse/inhouse-pdf2-api-lib
import PDFAPI from '@fbinhouse/inhouse-pdf2-api-lib';
import fs from 'fs';
const apiKey = "xxx";
const pdf = new PDFAPI(apiKey);
const pdfOptions = {
retentionClass: "shortTerm" as const,
headerTemplate: "<h1>Header</h1>",
footerTemplate: "<h1>Footer</h1>",
outputName: "phil.pdf",
margin: {
top: "5px",
bottom: "5px",
left: "5px",
right: "5px",
},
htmlSourceFile: fs.readFileSync(__dirname + "/recall.html"),
};
(async () => {
try {
/*
const job = await pdf.generateNewPDF(pdfOptions);
console.log("JOB Response", job);
*/
const pdfData = await pdf.generateAndWaitForDownload(pdfOptions);
fs.writeFileSync(__dirname + '/out.pdf', pdfData);
} catch(e) {
console.log("Error");
console.log(e);
}
})();