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

Allow hexapdf to be installed #111

Open
lurch opened this issue Oct 14, 2019 · 11 comments
Open

Allow hexapdf to be installed #111

lurch opened this issue Oct 14, 2019 · 11 comments

Comments

@lurch
Copy link

lurch commented Oct 14, 2019

Would it be possible to add hexapdf to this Docker image please? Or would licensing conflicts prevent that?
EDIT: Would it be possible to allow users (at their own risk) to install hexapdf inside the Docker container please?

I tried gem install hexapdf inside the container, and got:

Fetching: cmdparse-3.0.4.gem (100%)
Successfully installed cmdparse-3.0.4
Fetching: geom2d-0.2.0.gem (100%)
Successfully installed geom2d-0.2.0
Fetching: hexapdf-0.10.0.gem (100%)
Successfully installed hexapdf-0.10.0
ERROR:  While executing gem ... (Gem::DocumentError)
    RDoc is not installed: cannot load such file -- rdoc/rdoc

I know nothing about Ruby, so I (naively) tried running gem install rdoc and that gives an error too:

Fetching: rdoc-6.2.0.gem (100%)
Successfully installed rdoc-6.2.0
ERROR:  While executing gem ... (NoMethodError)
    undefined method `reset' for RDoc::TopLevel:Class

😢

@mojavelinux
Copy link
Member

My position is absolutely not. AGPL is an extremely viral and invasive language and is just asking for trouble.

The latest release of Asciidoctor PDF supports optimization out of the box using the -a optimize flag. The only requirement is that the image have ghostscript (gs).

@lurch
Copy link
Author

lurch commented Oct 15, 2019

The latest release of Asciidoctor PDF supports optimization out of the box using the -a optimize flag.

Hmmmm... (testing this outside the Docker container, since that doesn't contain gs)

$ asciidoctor-pdf --version
Asciidoctor PDF 1.5.0.beta.6 using Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)
$ asciidoctor-pdf -r asciidoctor-mathematical -v -a pdf-theme=my-theme.yml -o my-book-default.pdf my-book.adoc
$ asciidoctor-pdf -r asciidoctor-mathematical -v -a pdf-theme=my-theme.yml -a optimize -o my-book-optimize.pdf my-book.adoc
$ hexapdf optimize --compress-pages --force my-book-default.pdf my-book-default-hexapdf.pdf
$ hexapdf optimize --compress-pages --force my-book-optimize.pdf my-book-optimize-hexapdf.pdf
$ ls -lh *.pdf
-rw-rw-r-- 1 andrew andrew 6.9M Oct 15 10:47 my-book-default.pdf
-rw-rw-r-- 1 andrew andrew  17M Oct 15 10:48 my-book-optimize.pdf
-rw-rw-r-- 1 andrew andrew 1.3M Oct 15 10:51 my-book-default-hexapdf.pdf
-rw-rw-r-- 1 andrew andrew  12M Oct 15 10:52 my-book-optimize-hexapdf.pdf

I've edited this PR's title to (hopefully) be less controversial 😉

@lurch lurch changed the title Missing hexapdf Allow hexapdf to be installed Oct 15, 2019
@mojavelinux
Copy link
Member

This is the game of optimizing a PDF. Some optimizers make it better. Some optimizers make it worse. It highly depends on what objects are in the PDF.

You might try lowering the quality that ghostscript uses instead of using the default:

$ asciidoctor-pdf -a optimize=screen -o my-book-optimize.pdf my-book.adoc

If there are other settings we can enable in Ghostscript to reduce the size, I'm open to adding support for them. See https://github.com/asciidoctor/asciidoctor-pdf/blob/master/lib/asciidoctor/pdf/optimizer.rb.

But the hexapdf license is still a problem, regardless of how much better it works over Ghostscript.

I think this container should at least provide Ghostscript. It's an essential tool for working with PDF documents.

@lurch
Copy link
Author

lurch commented Oct 16, 2019

Just as a data-point, using -a optimize=screen then creates a PDF of 1.6 MB, but unfortunately it reduces the quality of the images too much.

I think this container should at least provide Ghostscript. It's an essential tool for working with PDF documents.

I'll create a separate issue for that 👍

@mojavelinux
Copy link
Member

I recommend playing around with Ghostscript directly until you can figure out the settings that optimize the PDF without reducing the quality. It should be possible, though it will likely require a lot of trial and error.

To be honest, I really don't know why the default quality is not reducing the size of the PDF. Perhaps that's a bug in Ghostscript.

@lurch
Copy link
Author

lurch commented Oct 16, 2019

I recommend playing around with Ghostscript directly until you can figure out the settings that optimize the PDF without reducing the quality.

Despite your dislike of it's licence, hexapdf is working fine for me, so I'm going to stick with that for now rather than wasting time messing around with ghostscript 😉

@mojavelinux
Copy link
Member

mojavelinux commented Oct 16, 2019 via email

@mojavelinux
Copy link
Member

Just as a data-point, using -a optimize=screen then creates a PDF of 1.6 MB, but unfortunately it reduces the quality of the images too much.

You might try "ebook" instead of "screen".

@mojavelinux
Copy link
Member

mojavelinux commented Oct 17, 2019

I've looked into this more and realized that the AGPL might not be a problem after all in a Docker container. In fact, there's likely already AGPL software in the image. And, much to my surprise, Ghostscript is also AGPL. (What is it with PDF software being AGPL?!?)

So if we're just talking about installing the gem so that hexapdf command is available, or installing Ghostscript so the gs command is available (which the Asciidoctor PDF optimizer uses), then I'm okay with that, revising my earlier statement.

Side note: The idea of calling hexapdf as a command (and not via the API) might actually allow us to use it in the Asciidoctor PDF optimizer, if available. I'll have to study that a bit more.

@lurch
Copy link
Author

lurch commented Oct 17, 2019

You might try "ebook" instead of "screen".

That produces a 2.4MB PDF which still has slight reduction in image quality, but not as bad as "screen". So for the time being I'll stick with the hexapdf solution.

@mojavelinux
Copy link
Member

Good to know, though. Thanks for checking.

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

2 participants