I used this module on Nodejs : https://github.com/bpampuch/pdfmake
Here is my code to create it :
const fonts = {
Roboto: {
normal: './fonts/Roboto-Regular.ttf',
bold: './fonts/Roboto-Medium.ttf',
italics: './fonts/Roboto-Italic.ttf',
bolditalics: './fonts/Roboto-Italic.ttf'
}
};
let PdfPrinter = require('pdfmake/src/printer');
let printer = new PdfPrinter(fonts);
let fs = require('fs');
module.exports.generateFile = function (data,callback) {
let fileName = "Logins_" + data[0]["userLogin"] + ".pdf";
let filePath = __dirname + "/files/" + fileName;
let logins = [ ['userLogin', 'softwarePassword', 'softwareName'] ];
for (let obj of data) {
let arr = [];
for(let x in obj){
arr.push(obj[x]);
}
logins.push(arr);
}
let docDefinition = {
content: [
{
table: {
// headers are automatically repeated if the table spans over multiple pages
// you can declare how many rows should be treated as headers
headerRows: 1,
widths: [ '*', 'auto', 100, '*' ],
body: logins
}
}
]
};
try {
let chunks = [];
let result;
let doc = printer.createPdfKitDocument(docDefinition);
doc.pipe(fs.createWriteStream(filePath));
doc.end();
callback(null,fileName,filePath)
} catch (err){
callback(err);
}
};
I got this screen :
Any ideas guys ? In the callback, I use res.download with the filename and the filepath. I tried everything