Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:

PDF 2.0 API Lib package

Import this package in to Node.JS projects where you want to speak to the PDF 2.0 engine (based on puppeteer).

Install

Make sure your ~/.npmrc points the @fbinhouse namespace to the private gemfury fbinhouse account.

npm i @fbinhouse/inhouse-pdf2-api-lib

Example usage

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