wkhtmltopdf troubles (Ubuntu 12.04 64b)

(4 posts) (2 voices)

Tags:

No tags yet.

  1. eellis, Member

    So after dredging multiple sites apparently the packaged version of wkhtmltopdf for my distro is insufficient for mydbr when there is no X server installed.

    eellis@mymachine:~$ wkhtmltopdf http://google.com google.pdf wkhtmltopdf: cannot connect to X server

    When trying to run the output of a mydbr error, I get more interesting output:

    eellis@mymachine:~$ wkhtmltopdf -q --header-html http://mymachine.lan/user/export_header_pdf.php --margin-top 20 --header-spacing 8 /tmp/464971164.html - The switch --header-html, is not support using unpatched qt, and will be ignored.The switch --header-spacing, is not support using unpatched qt, and will be ignored.wkhtmltopdf: cannot connect to X server

    Huh.. what's that referencing? Let's check:

    eellis@mymachine:~$ wkhtmltopdf --help Name: wkhtmltopdf 0.9.9

    Synopsis: wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file>

    Description: Converts one or more HTML pages into a PDF document, *not* using wkhtmltopdf patched qt.

    General Options: --collate Collate when printing multiple copies --copies <number> Number of copies to print into the pdf file (default 1) --extended-help Display more extensive help, detailing less common command switches -h, --help Display help -O, --orientation <orientation> Set orientation to Landscape or Portrait -s, --page-size <size> Set paper size to: A4, Letter, etc. --password <password> HTTP Authentication password -p, --proxy <proxy> Use a proxy -q, --quiet Be less verbose --username <username> HTTP Authentication username -V, --version Output version information an exit

    Reduced Functionality: This version of wkhtmltopdf has been compiled against a version of QT without the wkhtmltopdf patches. Therefore some features are missing, if you need these features please use the static version.

    Currently the list of features only supported with patch QT includes:

    * Printing more then one HTML document into a PDF file. * Running without an X11 server. * Adding a document outline to the PDF file. * Adding headers and footers to the PDF file. * Generating a table of contents. * Adding links in the generated PDF file. * Printing using the screen media-type. * Disabling the smart shrink feature of webkit.

    Contact: If you experience bugs or want to request new features please visit <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems or comments please feel free to contact me: see <http://www.madalgo.au.dk/~jakobt/#about>

    We run all of our webservers headless, and are very comfortable with the command line, so the X server requirement is pretty disappointing.

    I have found a method to compile a QT linked version of wkhtmltopdf (which appears to be the requirement) on my distro at (https://gist.github.com/Zauberfisch/8773593), but it requires an absurd amount of stuff to be installed, an X server among others. I will probably have a build machine specifically for this and see if I can get that to work so I can distribute the resulting binary to all of my production machines.

    In version 4, there doesn't appear to be a way to remove the option for PDF exports from the menu list that I've seen. If there is, can I get a link to the pertinent documentation?

    Might I suggest that some thought be given to tcpdf as a potential replacement for wkhtmltopdf? I apologize if it has already been considered and dismissed, but more options (and potentially this could be distributed with the mydbr code) would be welcome.

    Thanks for your time.

  2. myDBR Team, Key Master

    Hi,
    what you could try is to use xvfb instead of full X. That should be bit easier.

    http://fedir.github.io/web/blog/2013/09/25/install-wkhtmltopdf-on-ubuntu/

    As for the TCPDF, while being a very capable library (we do use it for other purposes), it has limitations that are hard to fix (limited CSS support for example).

    --
    myDBR Team

  3. eellis, Member

    This does seem to resolve the problem, but it's still pretty dependency heavy:
    eellis@test-trident:~$ sudo apt-get install xvfb [sudo] password for eellis: Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libfontenc1 libgl1-mesa-dri libllvm3.0 libxfont1 libxkbfile1 x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils xserver-common Suggested packages: libglide3 xfs xserver The following NEW packages will be installed: libfontenc1 libgl1-mesa-dri libllvm3.0 libxfont1 libxkbfile1 x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils xserver-common xvfb 0 upgraded, 11 newly installed, 0 to remove and 110 not upgraded.

    Thank you for your response concerning tcpdf. We haven't run up on those problems, but we don't do near as much heavy lifting with it as you do.

  4. myDBR Team, Key Master

    It does have some dependencies, yes.

    TCPDF is, as said, a good precision tool. Lightweight and quite powerful when you handcraft PDF's yourself. When you know what it is not capable of, you can, in most cases, find an alternate way of doing things.

    wkhtmltopdf on the other hand, uses WebKit browser engine (engine behind Safari & Chrome). It provides excellent support for web standards and is therefore more suitable for "convert *everything* without workarounds" type of scenario.

    --
    myDBR Team


Reply

You must log in to post.