cantoo-scribe / pdf-lib

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

How to compress PDF files? #73

Open KevenDev opened 1 month ago

KevenDev commented 1 month ago

Describe your idea

How to compress PDF files?I’m using PDFLib to manipulate PDF files in my project, and I’m wondering if there’s any functionality within the library to reduce the file size of the PDFs. Specifically, I’m looking for ways to compress or optimize the PDFs (e.g., images, fonts, etc.) without compromising too much on quality

How could this be implemented?

To reduce the size of PDFs using PDFLib, you would typically focus on optimizing various elements within the PDF, such as images, fonts, and metadata. However, PDFLib does not natively provide a built-in function to compress or reduce the file size directly. But you can take some steps manually to optimize a PDF's structure.

What problem are you trying to solve?

I'm currently working on a project where I manipulate PDFs using PDFLib, but I'm encountering an issue with the size of the resulting PDF files. The generated PDFs tend to be larger than expected, even after removing metadata and disabling object streams. My goal is to reduce the file size, making it more efficient for storage and sharing.

Why does this matter to you?

This is important for me because reducing the size of PDFs directly impacts the performance and usability of the application I'm developing. Large PDFs can slow down loading times, increase storage costs, and make it difficult for users to share files, especially in environments with limited bandwidth. By optimizing PDF file sizes, I can provide a better user experience, improve efficiency, and reduce resource consumption. Having a built-in solution within PDFLib would streamline this process, avoiding the need for external tools or complex workarounds.

Would others find this helpful?

yes, exists open issues in Hopding/pdf-lib

Are you interested in implementing your proposal?

Yes

Why are you submitting a proposal?

I'm submitting this proposal because I believe that adding native support for PDF compression or optimization in PDFLib would be highly beneficial for developers who rely on the library for PDF generation and manipulation. Currently, file sizes can become an issue, especially when dealing with documents that include images or embedded fonts. A built-in feature for reducing PDF size would improve both performance and user experience, and would eliminate the need for integrating external libraries or applying manual workarounds.

Additional Notes

No response

KevenDev commented 3 weeks ago

@Sharcoux

Sharcoux commented 3 weeks ago

I'm not sure we'll have time to handle this. If someone wants to propose a PR that would be awesome. We will review and merge.