cantoo-scribe / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
136 stars 27 forks source link

Error on embedPng #33

Closed thantos closed 11 months ago

thantos commented 1 year ago

What were you trying to do?

embedPng

How did you attempt to do it?

pdfDoc.embedPng using esm

What actually happened?

UPNG.decode is not a function

What did you expect to happen?

no error

How can we reproduce the issue?

Run using ESM

Version

1.19.14

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

Worked in 1.17

Sharcoux commented 1 year ago

Can you provide the exact code you're trying to run and the exact and complete error log?

thantos commented 1 year ago
    TypeError: UPNG.decode is not a function

      27 |       embedImage(pdfDoc, await pdfDoc.embedJpg(pdf.contents));
      28 |     } else if (pdf.contentType === "image/png") {
    > 29 |       embedImage(pdfDoc, await pdfDoc.embedPng(pdf.contents));
         |                                       ^
      30 |     } else {
      31 |       throw new Error(`Unsupported content type: ${pdf.contentType}`);
      32 |     }

      at new PNG (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/src/utils/png.ts:51:23)
      at Function.PNG.load (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/src/utils/png.ts:41:42)
      at Function.<anonymous> (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/src/core/embedders/PngEmbedder.ts:12:21)
      at ../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:169:75
      at __awaiter (../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:165:16)
      at Function.for (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/es/core/embedders/PngEmbedder.js:17:16)
      at PDFDocument.<anonymous> (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/src/api/PDFDocument.ts:1100:43)
      at ../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:169:75
      at __awaiter (../../node_modules/.pnpm/tslib@2.6.2/node_modules/tslib/tslib.js:165:16)
      at PDFDocument.embedPng (../../node_modules/.pnpm/@cantoo+pdf-lib@1.19.14/node_modules/@cantoo/pdf-lib/es/api/PDFDocument.js:957:16)
thantos commented 1 year ago

Confirmed that the same code works on 1.17

Sharcoux commented 1 year ago

@thantos, can you log UPNG in the code that is being executed? Just before embedImage(pdfDoc, await pdfDoc.embedPng(pdf.contents));?

Sharcoux commented 1 year ago

I'll be closing this if I get no answer.