You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This approach has been working reliably for a long time, but after switching to the new fork, I've encountered a problem with certain encrypted PDF files that have been decrypted. For most files, the deep clone works fine. However, when dealing with specific decrypted PDFs, the PDFDocument.catalog in the cloned document is set to PDFInvalidObject instead of the expected PDFCatalog and when I try to do await copiedPdfDoc.save();, I get the following error:
TypeError: this.catalog.Pages is not a function
at PDFDocument.computePages [as populate]
at Cache.access (Cache.js:11:1)
at PDFDocument.getPages (PDFDocument.js:478:1)
at PDFDocument.getPageCount (PDFDocument.js:462:1)
at PDFDocument.save (PDFDocument.js:1147:1)
Create a deep clone of the document using the code provided above.
Try to save the copied pdf document.
What actually happened?
TypeError: this.catalog.Pages is not a function
at PDFDocument.computePages [as populate]
at Cache.access (Cache.js:11:1)
at PDFDocument.getPages (PDFDocument.js:478:1)
at PDFDocument.getPageCount (PDFDocument.js:462:1)
at PDFDocument.save (PDFDocument.js:1147:1)
What did you expect to happen?
The PDF to be saved properly.
How can we reproduce the issue?
Use the steps above.
Version
2.2.3
What environment are you running pdf-lib in?
Browser
Checklist
My report includes a Short, Self Contained, Correct (Compilable) Example.
I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
After further investigation, it looks like the file gets corrupted upon saving and therefore can't be loaded again correctly even in other PDF viewers. I am using decrypting the file with '' as password in the first place.
The text was updated successfully, but these errors were encountered:
Talha345
changed the title
Error while creating a deep clone of encrypted PDFDocument object.
Error while creating a deep clone of decrypted PDFDocument object.
Aug 24, 2024
What were you trying to do?
I create a deep clone of the PDFDocument object before applying any changes to it using the following code:
const copiedPdfDoc = await PDFDocument.load(await pdfDoc.save());
This approach has been working reliably for a long time, but after switching to the new fork, I've encountered a problem with certain encrypted PDF files that have been decrypted. For most files, the deep clone works fine. However, when dealing with specific decrypted PDFs, the
PDFDocument.catalog
in the cloned document is set toPDFInvalidObject
instead of the expectedPDFCatalog
and when I try to doawait copiedPdfDoc.save();
, I get the following error:Document for which the issue occurs:
g-1145.pdf
How did you attempt to do it?
What actually happened?
What did you expect to happen?
The PDF to be saved properly.
How can we reproduce the issue?
Use the steps above.
Version
2.2.3
What environment are you running pdf-lib in?
Browser
Checklist
Additional Notes
After further investigation, it looks like the file gets corrupted upon saving and therefore can't be loaded again correctly even in other PDF viewers. I am using decrypting the file with '' as password in the first place.
The text was updated successfully, but these errors were encountered: