MuhammaraJS
MuhammaraJS copied to clipboard
Recipe example for buffer not working
In the readme, there's an example of how to use buffers:
const Recipe = require("muhammara").Recipe;
const pdfDoc = new Recipe(Buffer.from("new"), null, {
version: 1.6,
author: "John Doe",
title: "Hummus Recipe",
subject: "A brand new PDF",
});
const pdfBuffer = pdfDoc.createPage("letter-size").endPage().endPDF();
Executing this as-is produces this error in Node 20.9.0:
Error: TypeError: Unable to start parsing PDF file
at Recipe.read (my-project/node_modules/muhammara/lib/Recipe.js:197:13)
at Recipe._createWriter (my-project/node_modules/muhammara/lib/Recipe.js:85:12)
at new Recipe (my-project/node_modules/muhammara/lib/Recipe.js:73:10)
at Object.<anonymous> (my-project/test.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47
I've attempted to switch to prior versions (18.x and 14.x) with no luck. Looking for any advice on how to get started working with buffers instead of files as everything I've tried doesn't seem to work.
I'm facing the same issue so for short term solution I'm doing the below code
const tempFilePath = temp_pdf_${uuid()}.pdf
;
fs.writeFileSync(tempFilePath, buffer);
const pdfReader = hummus.createReader(tempFilePath);
Please test this: https://github.com/julianhille/MuhammaraJS/pull/375