Authors: Franz Lacherbauer (@frnzetti) and Frank Schiemann (@aquastars) for Das Büro am Draht GmbH 2021
License: Permission to use is granted under the terms of the MIT License.
this module provides all the basic function for PDF development an creation using handlebars templates, puppeteer and serverless.
It coveres 2 usecases for PDF generation
-
PDFs with predifined JSON data
-
PDFs with data being fetched within the lambda function using a fetchCallback
const handler = require('@bad-opensource/lambda-pdf-core')(
{ version,
templates = {},
helpers,
mocks,
schema,
patchDataBeforeRendering,
config,
fetchCb }
);
-
Version: NPM Version
-
templates: handlebars templates to be used for this PDFs
-
helpers: handlebars custom helper functions
-
mocks: mockdata to be used in develop mode
-
schema: data schema for validation before rendering
-
patchDataBeforeRendering (optional): custom transformation function enabling last DOM transformations (patchData callback)
-
config: basic configurations like margins and fallbacks
-
fetchCb: fetch data callback (optional)
module.html = async event => pipe(warmUp, parse, validate, patchData, returnHtml)(event);
module.pdf = async event => pipe(warmUp, parse, validate, patchData, returnPdf)(event);
module.debug = async event => pipe(warmUp, parse, validate, patchData, returnDebug)(event);
module.fetchHtml = async event => pipe(warmUp, fetchData, validate, patchData, returnHtml)(event);
module.fetchPdf = async event => pipe(warmUp, fetchData, validate, patchData, returnPdf)(event);
module.fetchDebug = async event => pipe(warmUp, fetchData, validate, patchData, returnDebug)(event);
-
*html methods return HTML files for debugging in the browser
-
*pdf methods return PDF files
-
*debug methods return the transformated renderdata JSON for debugging
-
*check lambda function handler which renders the the currently deployed package version
-
warmUp: Internal method waiting for the lambda instance to be up and running
-
parse: Pass through handling of the given input data (event) or
-
fetchData: CallBack function for fetching data
-
validate: Validation of the given data using a provided schema
-
patchData: CallBack function (optional) for last HTML DOM manipulations (e.g. patching of image sources) before the final rendering