Hopding / pdf-lib

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

removePage function does not fully remove the page #1588

Open vne-celum opened 6 months ago

vne-celum commented 6 months ago

What were you trying to do?

Remove the first page from a PDF and then copy all its pages to the main PDF.

How did you attempt to do it?

sourcePdf.removePage(0);

const copiedPages= await mainPdf.copyPages(sourcePdf, sourcePdf.getPageIndices());
copiedPages.forEach(page => mainPdf.addPage(page));

What actually happened?

The removed page was copied and the last page of the document was not. From what I noticed this is because getPageIndices works correctly, but inside the copyPages function we call getPages and this still holds a reference to the removed page.

What did you expect to happen?

copyPages/getPages functions are not holding and working with a removed page

How can we reproduce the issue?

https://jsfiddle.net/2mpk8otf/

Link where you can see that getPages still hold reference to the old page after removal, while getPageCount and getPageIndices work correctly.

Version

1.17

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response