I would like the below to read image files and turn them into a PDF. The files are stored on the disk, and the filename are stored in a SQLite database.
var fs = require('fs');
var pdf_doc = new jsPDF();
pdf_doc.text(20, 20, 'Hello, world.');
db.all("SELECT * FROM media", function(err, rows) {
rows.forEach(function(row) {
var file_content = read_image_file(row.url);
add_image_to_pdf_doc(file_content);
});
});
function read_image_file(image_url) {
var img_data = fs.readFileSync("./public/uploads/"+image_url);
return img_data;
}
function add_image_to_pdf_doc(img_data) {
pdf_doc.addImage(img_data, 'JPEG', 15, 40, 180, 160);
}
pdf_doc
seems to be empty ("Uncaught TypeError: undefined is not a function") and I can't get my head around why nor how to solve this.
Aucun commentaire:
Enregistrer un commentaire