julianhille / MuhammaraJS

Muhammara a node module with c/cpp bindings to modify PDF with js for node or electron (based/replacement on/of galkhana/hummusjs)
Other
205 stars 43 forks source link

Cannot destructure property 'width' of 'this.metadata[this.pageNumber]' as it is undefined. #294

Closed xLEpEX closed 1 year ago

xLEpEX commented 1 year ago

Hello,

I'm trying to apply an overlay to my PDF and getting the error: "TypeError: Cannot destructure property 'width' of 'this.metadata[this.pageNumber]' as it is undefined."

I'm Loading the PDF, from a Buffer and im not sure if i missing something

` const overlayPDFByte = fs.readFileSync('./src/overlay.pdf') const generatedPDFByte = Buffer.concat(chunks);

const OverlayPDFDoc = new Recipe(overlayPDFByte);
const generatedPDFDoc = new Recipe(generatedPDFByte, {

});

generatedPDFDoc.overlay('./src/overlay.pdf', 0, 0, {fitHeight: true, fitWidth: true}).endPDF((cb) => {
    fs.writeFile("file2.pdf", cb, (err) => {
        if (err) throw err;
        console.log("PDF Created");
    });
});

`

julianhille commented 1 year ago

can you add the sample files. It seems like Recipe is unable to find the page it needs to add the overlay at some point. Maybe it has no pages?

you could also examine a bit by:

const OverlayPDFDoc = new Recipe(overlayPDFByte);
console.log(OverlayPDFDoc.pageNumber)
console.log(OverlayPDFDoc.metadata)
xLEpEX commented 1 year ago

https://stackblitz.com/edit/node-imkbyf?file=index.ts I'm not sure, could it be possible that I'm on the wrong version. Thiere is no method / property with the name pageNumber / metadata

I'm using the version 3.8.0

image

TEST PDF FILE.pdf

xLEpEX commented 1 year ago

What is also a little bit stage is, that I'm not getting a byte stream back on .endPDF() instead it's returning a Recipe object on every method

julianhille commented 1 year ago

you need to make sure to start editing and finalize a page:

generatedPDFDoc.editPage(1).overlay('./src/overlay.pdf', 0, 0, {fitHeight: true, fitWidth: true}).endPage().endPDF(....')

you may also have a look at the test overlay file https://github.com/julianhille/MuhammaraJS/blob/develop/tests/recipe/overlay.js#L14

kimmanwky commented 10 months ago

@xLEpEX how do you fix the metadata issue? I'm migrating from hummus-recipe, and using metadata properties too. Where do I get similar info?

julianhille commented 10 months ago

Fyi: the recipe object is mostly a complete copy of recipe module so it should basically be a drop in replacement. Please let me know when things do not work so I could change it or add it to the readme.