This module provides functionality to create PDF documents using pdfmake.
It includes a default font configuration with Roboto and a function to create PDFs from document definitions.
It is designed to be used in a secure environment, ensuring that only allowed fonts are registered.
IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
- Description:
- This module provides functionality to create PDF documents using pdfmake. It includes a default font configuration with Roboto and a function to create PDFs from document definitions. It is designed to be used in a secure environment, ensuring that only allowed fonts are registered. IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
Methods
(static) create(documentDefinition) → {Promise.<Buffer>}
- Description:
- Creates a PDF document from a document definition object.
Example
const pdf = require('pdf');
const docDefinition = {
pageSize: 'LETTER',
pageMargins: [40, 60, 40, 60],
header: { text: 'Gingee Weekly Report', alignment: 'center', margin: [0, 20, 0, 0] },
content: [
{ text: 'Hello, World!', fontSize: 15 }
]
};
const pdfBuffer = await pdf.create(docDefinition);
const fileName = `report-${Date.now()}.pdf`;
$g.response.headers['Content-Disposition'] = `attachment; filename="${fileName}"`;
$g.response.send(pdfBuffer, 200, 'application/pdf');
Parameters:
Name | Type | Description |
---|---|---|
documentDefinition |
object | A standard pdfmake document definition object. |
Throws:
-
If there is an issue creating the PDF document.
- Type
- Error
Returns:
A promise that resolves with the PDF data as a Buffer.
- Type
- Promise.<Buffer>