Skip to content
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

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

Open
hahazexia opened this issue Nov 14, 2024 · 5 comments
Open

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

hahazexia opened this issue Nov 14, 2024 · 5 comments

Comments

@hahazexia
Copy link

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
Copy link
Owner

fschutt commented Nov 14, 2024

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
Copy link
Owner

fschutt commented Nov 14, 2024

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).

@josephg
Copy link

josephg commented Feb 5, 2025

I'm running into the same problem, running on 0.7.0 because thats the latest in cargo.

Any chance you could publish 0.8?

@fschutt
Copy link
Owner

fschutt commented Feb 5, 2025

Still blocked on yeslogic/allsorts#110.

In the meantime, ideally fork this repo temporarily or use:

[dependencies]
printpdf = { git = "https://github.com/fschutt/printpdf", rev = "ebe45a6" }

There are also still problems with layering and HTML rendering, but it should work overall.

@fschutt
Copy link
Owner

fschutt commented Feb 5, 2025

Also, I kind of want to add optional JPEG encoding, so that this problem doesn't come up again. PDF supports a built-in JPEG2000 decoding filter, but right now the image is embedded uncompressed, which is why the PDF is so large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants