Functions:generatePDF - bettyblocks/cli GitHub Wiki
With the generatePDF helper you can generate PDF files. This helper uses Prince version 15.1.
The generatePDF helper expects the following arguments: the HTML content, the model name, the property name you want to upload a file for (this should be a file property), and a filename. It returns a promise which, once resolved, results in the file reference as a string. This file reference can be used to assign it to a new/existing record.
interface GeneratePDFOptions {
html: string;
fileName: string;
modelName: string;
propertyName: string;
}
const generatePDF = async ({
html,
fileName,
modelName,
propertyName
}: GeneratePDFOptions): Promise<string>
It is also possible to inject variables into your HTML. To do this you can use the Map option to create variables and then use them in the HTML template to interpolate values like this: {{variable_name}}
Example function:
import templayed from './templayed';
const generatePdf = async ({
html,
fileName,
model: { name: modelName },
property: [{ name: propertyName }],
variables,
}) => {
const variableMap = variables.reduce(
(previousValue, { key, value }) => ({
...previousValue,
[key]: value,
}),
{},
);
const htmlTemplate = templayed(html)(variableMap);
const reference = await generatePDF({
html: htmlTemplate,
fileName,
modelName,
propertyName,
});
return {
reference,
};
};
export default generatePdf;