wkhtmltopdf generates from PDF format on Ubuntu without X Server
Asked Answered
T

3

9


Is it possible to set format of PDF to generate in wkhtmltopdf?
From my PC wkhtmltopdf generates format "PDF-1.4"

enter image description here

But remote Ubuntu 14.04 server that is generating pdf with a 'virtual' X server using xvfb giving format PDF-0:

enter image description here


The only problem is opening generated pdf file in Chrome :)
Chrome cannot open PDF-0.

Thanks

Tannate answered 28/12, 2015 at 12:13 Comment(5)
wkhtmltopdf only sets the creator field properly since version 0.12.1 (specifically since this commit). So I am suspecting you must be running an older version on your remote server. Any chance you can update? - Still, I believe the root cause is actually inside QPrinter, so your problem may also stem from the different QT versions you are running. Can you post the very first line of your resulting PDF as it is shown in a text editor? It encodes the PDF-version.Mytilene
The versions running on my local machine and on server are the same. 0.12.2.4 exactlyTannate
Which leads us to the conclusion that your problem is verly likely rooted inside QT (or even somewhere further down the chain). Can you update your QT libs on the server and try again?Mytilene
Could you create a short answer for your question so that I can give a bounty. It ended up that on server installed wrong version. My fault.Tannate
I wouldn't consider that a "fault" on your side. As outlined in my answer below, it should be wkhtmltopdf's duty to nag you about having a tool old QT version...Mytilene
F
2

It looks like the resulting PDF from xvfb might not be 100% correct. There are some problems with the meta data. It's missing the creator for example. Also PDF-0 does not appear to be a valid PDF version. There might be other problems with the document. This would be a possible reason why the generated file does not appear in Chrome.

A good way to examine the document would be using Acrobat's preflight tool. It will inspect the document for potential problems, and that could give provide a clue on what's going on. The tool is located under "Print Production" in Acrobat. The profile to run is called "Report PDF syntax issues". I'm sure there are other tools out there that can also explain what is wrong with the document.

This section should provide a resolution to the problem. As mentioned in the comments below, updating the QT version from 4.8.6 to something newer should resolve the issue. The working setup appears to be running 5.3.2, while the non working one is under QT 4.8.6.

Fallen answered 5/1, 2016 at 15:12 Comment(9)
Thank you. Yes it is definitely problem with xvfb generating pdf. I did in fact examine of pdf with Acrobat and the result images are is question. Could you help to find the reason why xvfb generating wrong pdf whereas in my local computer PDF generation is good.Tannate
I can give it a try. Can you please give me some more details about your setup, or update your OP with that? On your local machine, you are running wkhtmltopdf to generate PDF files. What's your local running? Then on a remote machine running Ubuntu, you use wkhtmltopdf to generate PDF files. You use xvfb to connect remotely to it. Is this assumption correct? Do you have a chance to try logging to the server locally, just to eliminate xvfb out of the picture? Please correct me if my assumptions about your setup are wrong.Fallen
I've used this configuration to run wkhtmltopdf without X Server on server pc.Tannate
Did you try to run wkhtmltopdf locally on the server, without X Server? Did it work? I'm trying to figure out if logging in remotely with xvfb somehow messes up the process.Fallen
Sorry if I made unclear question. I am not logging to server with xvfb. wkhtmltopdf needs it in order to generate PDF. So, basically PDF generation is not working well in PC without monitor (video card) :)Tannate
Thanks for the clarification. This is quite the strange issue. Do you have a way of testing wkhtmltopdf alone, to see if the problem lies within xvfb or wkhtmltopdf? Also, you could try generating the PDF with a really simple web page, to make sure something in the page you are using isn't throwing it off. Are you getting any errors\warnings? The PDF that comes out is definitely problematic, so I'd hope you get at least a warning from any of the tools.Fallen
Could not get any logging info from wkhtmltopdf.Tannate
Why on earth do you suspect the erroneous PDF is xvbf's fault? This would imply xvfb behaves differently towards its clients than any other X-Server. That might in fact be the case, but I believe it to be highly unlikely - given the plentiful other possible sources of error in this setup.Mytilene
I'm trying to pick a direction and identify the variables in the setup. The next thing to try as @Mytilene mentioned is updating the QT version from 4.8.6 to something newer. I see that you are running 5.3.2 in the working setup.Fallen
D
0

May i recommend phantomjs as an alternative (headless tool, no server x needed at all) to xkhtmltopdf.

HTML to PDF rendering is very straight forward (e.g. http://phantomjs.org/screen-capture.html )

Darb answered 11/1, 2016 at 22:57 Comment(0)
M
0

Bounty answer:

Apparently QT 4 and QT 5 behave differently when printing to a PDF. Thus, your problem can be solved by upgrading the QT libs on your server.

You may consider filing a bug against wkhtmltopdf since your described behavior obviously renders it incompatible with QT 4.

See also original comment here.

Mytilene answered 12/1, 2016 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.