Giter Club home page Giter Club logo

Comments (9)

mojavelinux avatar mojavelinux commented on May 28, 2024

It's highly dependent on which version of gs you have installed. Newer versions do a much better job. And, of course, we may need to tweak the parameters to get more out of it.

One thing to keep in mind is that you should specify an IMAGE_DPI environment variable when calling the script. I keep changing the default, but it's best to be explicit. I found that IMAGE_DPI=150 gives good results (balancing size and quality).

...also, the optimize-pdf script needs to be rewritten in Ruby so it can get packaged in the Gem. We might want to use rghost instead of invoking gs directly.

https://rubygems.org/gems/rghost

Feel free to play around with the script. I'm all ears for recommendations.

from asciidoctor-pdf.

thorstenkampe avatar thorstenkampe commented on May 28, 2024

Ghostscript is 9.06 (the latest one on Cygwin), which is about two years old. Setting IMAGE_DPI didn't affect the file size. I'm not a PDF-Ghostscript-DPI expert, so "playing around" with the settings in the script won't help much.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

That's probably the difference. I have Ghostscript 9.14. I remember when writing that script that major changes were made to image optimization around 9.10 and I did see a big difference when I upgraded.

I was able to compile Ghostscript at the time since a package wasn't available for my system back then. If that's possible for you, I encourage you to give it a try.

I looked for other solutions for optimizing PDF, but unfortunately nothing does the job quite like Ghostscript. Eventually, however, I am hoping that whatever logic is going on there can make its way into Prawn so that we can optimize when generating the PDF. Prawn has some optimization flags, but at the time they were corrupting my PDF.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

Btw, I had no idea what I was doing either when writing that script. But I learned through trial and error and this reference page:

http://ghostscript.com/doc/current/Ps2pdf.htm

from asciidoctor-pdf.

thorstenkampe avatar thorstenkampe commented on May 28, 2024

I tried the Windows version of 9.14 with the script. Now the resulting PDF is of the same size as the original one. At least the size doesn't double anymore. I guess I leave the PDF optimizations for now as they are.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

Actually, that's a good point...when to use optimize-pdf. The reason I was using it...the reason I created it...is because my original PDF was 20MB. In that case, I saw a major decrease in size. Below a certain size, you might end up with a larger PDF as you have observed. I'd say if the PDF is below 5MB, then just keep it as is. A good tip for the guide.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

The action here is that if the optimized file is not smaller than the original, don't overwrite the file. There's nothing I can do about Ghostscript not actually making the file smaller. There's no guarantee of that.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

There are two solutions to this problem. In the next release, you'll be able to activate the optimizer and control the quality using the optimize attribute. For example, -a optimize=screen may, in fact, decrease the size.

The other solution is to use hexapdf as documented in the README.

Beyond that, this is really outside the scope of what Asciidoctor PDF can do.

from asciidoctor-pdf.

mojavelinux avatar mojavelinux commented on May 28, 2024

I'm going to close as a duplicate since #535 will address this in part, and using hexapdf as an alternative has already been documented.

from asciidoctor-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.