Skip to content

Find some way to reduce the file size #2

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

Closed
foosel opened this issue May 14, 2024 · 1 comment
Closed

Find some way to reduce the file size #2

foosel opened this issue May 14, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@foosel
Copy link
Owner

foosel commented May 14, 2024

Problem

The files its creates are hugh! A 2.4Mb file comes out as 23.2Mb...Maybe a files compression thing, and also not very high on the list given the size of todays harddrives, but nonetheless...

Solution

Apparently that's a known and so far unsolved issue with pdf-lib, see for example Hopding/pdf-lib#1338.

A first test on the command line with

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
    -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH \
    -sOutputFile=output.pdf input.pdf

showed very promising results however, reducing a generated PDF from 55MB to 5.7MB.

It might be possible to get ghostscript to work via wasm and use that to optimize the PDF, as demonstrated by laurentmmeyer/ghostscript-pdf-compress.wasm. The downside of that is having to download the ghostscript wasm build, which is around 18MB. But compression could be made optional with a checkbox and things only loaded if necessary.

@foosel foosel added the enhancement New feature or request label May 14, 2024
foosel added a commit that referenced this issue May 16, 2024
Also add some basic deduplication to reduce file size.

Closes #11
See also #2
@foosel foosel closed this as completed in 9e0da72 May 16, 2024
@foosel
Copy link
Owner Author

foosel commented May 16, 2024

It turns out that just switching the card images from PNG to JPG already sufficed.

I actually also got Ghostscript to work in WebAssembly, but that turned out to be unusably slow with larger PDFs, so this approach was abandoned (and frankly, also a bit overengineered and backwards).

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

No branches or pull requests

1 participant