-
-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request]: PDF should decrease in file size after calling removePage
#140
Comments
Hello @jdbaculard! The That being said, I can certainly see how it would be desirable to actually delete a page's objects from the document, in addition to removing its reference from the page tree. I think it would make sense to add a new method, But, in the meantime, there is a workaround: You can copy the pages you want to keep into a document object. For example, if you want to keep pages 1, 4, and 75: const originalDoc = await PDFDocument.load(...)
const modifiedDoc = await PDFDocument.create()
const pages = await modifiedDoc.copyPages(originalDoc, [0, 3, 74])
pages.forEach(page => modifiedDoc.addPage(page))
const pdfBytes = await pdfDoc.save()
I hope this helps. Please let me know if you have any additional questions! |
Thank you for your reply. Can I test the deletePage in beta method? Congratulations for your work. |
@jdbaculard Have you tried the page copying approach using the beta version? The current version (0.6.4) has an API flaw that results in duplicate objects being created (hence the large document size). But this has been fixed in the beta version. For example, in 0.6.4 the logo will be copied 2000 times. But in v1.0.0-beta.3 the logo will only be copied once. The beta version does not currently have a |
Great ! it's works ! |
@Hopding Grand way of removing pages 👍 Just one thing I noticed (can raise an issue if that's preferred), but after creating the new document it seems to be missing a couple of entries in its catalog that the original document had (such as AcroForm, StructTreeRoot, etc). Presumably document creation leaves that part up to you? So if I wanted to copy across extra catalog entries from the original, that's allowed? |
Reopening this to track it as a feature request. @sdfereday Just realized that my comment on #159 (comment) isn't applicable as it doesn't delete unused page objects. |
removePage
Hey guys, just wanted to voice my support for this feature. This would help us out a lot. Thanks for your great work on this! |
Added this to the roadmap for tracking: #998. |
Hi
I use PDF-LIB with nodeJS. I've got a PDF File with 2000 pages for 13MB.
I remove 1900 pages (with pdfDoc.removePage(10),pdfDoc.removePage(11),pdfDoc.removePage(12), ...). It's working. it's great but the file size remains the same while only 100 pages remain in the modified file.
Why ?
Any solution please ? Thanks
The text was updated successfully, but these errors were encountered: