fschutt / printpdf

A fully-featured PDF library for Rust, WASM-ready
https://fschutt.github.io/printpdf/
MIT License
829 stars 98 forks source link

PDF file size is huge, image is 759kb, and PDF file is 10MB #197

Open hahazexia opened 1 week ago

hahazexia commented 1 week ago

I followed the official example and used the add_to_layer method to add a local image file to the page of a PDF file, but the final generated PDF file is particularly large! The size increased by 10 times. This is very strange. Do you have any ideas on how to solve this problem?

The original image file is 759 KB, and the final generated PDF file has become 10.3 MB.

here is my code https://github.com/hahazexia/img2pdf

image

image

fschutt commented 1 week ago

Use release mode? Images are uncompressed in debug mode. Image compression is on by default in 0.8, I think I only needed it when I was debugging images in the early days of this library.

fschutt commented 1 week ago

Well it's 5.2 MB with --release. Good, but not that much better. Technically we could use the JPXDecode filter (used to natively embed JPEGs into PDF), which would probably bring it close to the original (but at the loss of quality).