zakird / wkhtmltopdf_binary_gem

Ruby gem containing easily installable access to wkhtmltopdf application
https://rubygems.org/gems/wkhtmltopdf-binary
Apache License 2.0
184 stars 346 forks source link

Added RaspberryPi 3 support by adding binary and detection for Linux armhf #39

Closed Kostadin closed 3 years ago

Kostadin commented 7 years ago

The wkhtmltopdf_linux_armhf binary version is 0.12.3-dev (with patched QT).

The binary was downloaded from here: https://github.com/wkhtmltopdf/wkhtmltopdf/files/720814/wkhtmltopdf.zip

The link for the binary was from the discussion here: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1868

Tested on RaspberryPi 3 running Raspbian 8.0 with JRuby 1.7.19, Java 1.8.0_65.

Version bump recommended.

unixmonkey commented 7 years ago

Nice. I have a few RPis I could give this a spin on.

Do you know if the detection command is available across distributions?

I found this post which recommends

dpkg --print-architecture

But that supposes you are on a debian-like distribution.

Opening this up to all the different architectures makes me a little bit worried about adding more bloat to this already large gem. I wonder if we could compress the binaries and either unpack them on gem install, or unpack them first time they are used.

Kostadin commented 7 years ago

The current detection method for Linux/armhf should work on all Linux distributions that have the readelf and grep utilities and support /proc/self/exe. Additional testing is welcome!

I avoided "dpkg --print-architecture" because in order to use that you need dpkg. It is included by default in Debian-like distributions but other distributions use different package managers.

As for opening up to more architectures, I think this https://github.com/zakird/wkhtmltopdf_binary_gem/issues/28 should be addressed. Windows should not be ignored. Raspberry Pi should not be ignored either. Both have significant number of users.

Wkhtmltopdf is great. Ruby is great. Having them both run on as many popular OSes and architectures would be ideal. The sizes of the binaries are indeed a concern. The current binaries are around 40 MB each.

Unzipping on gem install and on first use sounds reasonable. Downloading them and then unzipping them would probably save even more space and network bandwidth. It might complicate some deployment setups so it needs to be implemented carefully.

I think the gemspec's platform value was meant for cases just like these. http://guides.rubygems.org/specification-reference/#platform=

This would require publishing multiple versions of the gem. It can probably work fine for native rubies for which the platform string is something like "x86_64-linux" but it won't solve the problem for JRuby's case where Ruby runs on top of the JVM. In those cases the platform strings are like "universal-java-1.7" or "universal-java-1.8" so Bundler won't be able to figure it out on its own without further complications. For the time being it seems the easiest option for detection of the platform is the RbConfig::CONFIG hash combined with further queries as is the case for armhf.

For the issue at hand, it is better to support Linux/armhf than not to support it. You cannot ignore more than 10 million Raspberry Pi units.

GGGunrunner commented 7 years ago

Great work!

Not sure if it's ok to post in this branch - but can this be done to wkhtmltoimage aswell?

It segfaults like crazy

root@:# wkhtmltoimage https://google.com out.png Segmentation fault root@:# export DISPLAY=:0 root@:# wkhtmltoimage https://google.com out.png Invalid MIT-MAGIC-COOKIE-1 keyQXcbConnection: Could not connect to display :0 Aborted

ckarrie commented 7 years ago

Thanks for the great app and RPI3 support.

Unfortunately, i don't get the binary to work on my RPi3, it's Debian stretch (no Ruby or Java installed) - installed from https://wiki.debian.org/RaspberryPi3 (section Preview image)

My steps:

Any ideas? Do i need Ruby or Java installed?

dpkg --print-architecture reports arm64

EDIT:

root@rpi3:# wkhtmltopdf /var/lib/gems/2.3.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf_linux_x86: 1: /var/lib/gems/2.3.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf_linux_x86: Syntax error: "(" unexpected root@rpi3:# wkhtmltopdf -V /var/lib/gems/2.3.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf_linux_x86: 1: /var/lib/gems/2.3.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf_linux_x86: Syntax error: "(" unexpected

Kostadin commented 7 years ago

The added binary is for armhf, not for arm64. The binary is tested and confirmed to work on Debian 8 (jessie) for armhf on Raspberry Pi 3. Debian 9 (stretch) was realeased way after this pull request was made so there is no support for it currently. If you can't use Debian 8, try finding wkhtmltopdf compiled for arm64.

ashkulz commented 6 years ago

Would appreciate someone testing and giving feedback on the raspbian build available from

https://builds.wkhtmltopdf.org/0.12.5-dev/wkhtmltox_0.12.5-0.20180430.129.dev~1744d93~raspbian.stretch_armhf.deb

pedrofurtado commented 3 years ago

@unixmonkey Maybe we can close this PR for a while, because it handles an old version of wkhtmltopdf, not supported by gem anymore (0.12.3) 👍