-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerator.js
More file actions
33 lines (27 loc) · 773 Bytes
/
generator.js
File metadata and controls
33 lines (27 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import PdfMakePrinter from 'pdfmake/src/printer';
const fonts = {
Roboto: {
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italics: 'fonts/Roboto-Italic.ttf',
bolditalics: 'fonts/Roboto-MediumItalic.ttf'
}
};
const generatePdf = (docDefinition, callback) => {
try {
const printer = new PdfMakePrinter(fonts);
const doc = printer.createPdfKitDocument(docDefinition);
const chunks = [];
doc.on('data', (chunk) => {
chunks.push(chunk);
});
doc.on('end', () => {
const result = Buffer.concat(chunks);
callback(`data:application/pdf;base64,${result.toString('base64')}`);
});
doc.end();
} catch (err) {
throw (err);
}
};
export default generatePdf;