Squared characters issue on wkhtmltopdf
Asked Answered
F

7

39

I've installed wkhtmltopdf on Centos 5.5. (Since there was library issues, it's been 4 days). It's partly working now. I said partly because, all pdfs which was created by wkhtmltopdf include squares instead of text?

What can I do? I've searched google, but I couldn't find anything.

Appreciate your help.

Ferule answered 7/1, 2011 at 16:33 Comment(3)
Bad Revolver - Have a look at @James F answer, this did the trick for meCourtenay
If you're seeing this only on some line-breaks, try adding text-rendering: geometricPrecision; to the body class in your CSS, as per: github.com/wkhtmltopdf/wkhtmltopdf/issues/1734Forceps
@Tim - please mark James F answer as correct by clicking the grayed out checkmark under the current vote count of 56.Whimper
M
82

When I had the black squares issue I was able to solve it without installing X11 by installing the urw-fonts package.

Mcclenon answered 30/12, 2011 at 14:48 Comment(10)
The solution from James F solved my problem. Had exact the same problem, when I execute the wkhtmltophp on the command line all fonts where 100%. But not if I try and execute it from PHP using the command. I run Centos 6 and installed URL fonts yum install urw-fonts and then it worked ;-) Thank you JamesCourtenay
Awesome solution James. Tim, please accept it as an answer as it clearly works.Cristionna
Excellent Answer. @Tim Tuckle: please accept this as the answer.Socratic
Thank you! Worked like a charm in CentOS 6.5. @Tim Tuckle, please do accept the answer.Eyeglass
Tnx! Solved my problem on CentOS 7.1Castroprauxel
Thanks! Solved my issue. sudo yum install urw-fontsMonosome
Solved my problem with wkhtmltopdf-amd running on RHEL7. Thanks!Whimper
Awesome job! That was the solution on my end.Tracheotomy
Is there a ubuntu/debian equivalent to urw-fonts? -- this problem exists on ubuntu as well.Smutty
This is THE answer!Infamy
T
18

I was able to solve this problem using the following resource:

http://code.google.com/p/wkhtmltopdf/wiki/static

In short, you probably don't need to install the entire x11 library and all its dependencies. Just installing urw-fonts should do the trick. The above resource even mentions CentOS as having this problem.

Run this command on your server:

sudo yum install urw-fonts libXext openssl-devel
Therefrom answered 8/1, 2013 at 21:4 Comment(1)
Basically the same answer as James F. After downloaded the static binary I had to install the following deps to get it working on RHEL7: yum install libXrender libXext fontconfig urw-fontsWhimper
B
6

In case someone faces the same issue on Alpine. This solved the problem for me:

apk --update add ttf-dejavu
Byrnie answered 7/7, 2019 at 19:17 Comment(1)
Thanks ! I could not get the segmentation fault error !Combo
C
3

I am using CentOS 7 with wkhtmltox 12.4 and found that none of the suggestions thus far fixed my block-text in output PDFs.

For me, the final solution was to install dejavu-sans-fonts.

Ctesiphon answered 6/12, 2017 at 12:12 Comment(1)
thanks mate , this one worked me after try so many damn number of suggestions/fixes/workarounds all over the internet so far. im on centos 7 and using wkhtmltopdf 0.12.2.1 (with patched qt)Audra
V
0

I'm going to guess this is a font issue, or perhaps an encoding issue.

What encoding does your HTML use? (This is easier to check so I listed it first) If it's something funky, you might have to translate it prior to feeding it to wkhtmltopdf. Reporting a bug might help too in this case.

Does wkhtmltopdf know how to find your fonts? If wkhtmltopdf can't find your system's fonts, then it's got a serious problem and might fall back on the "Unknown Character" character (the empty box).

Also, if your text contains characters that don't actually exist in the requested font, you'll get the unknown character character. If you're supposed to be using "Courier New" and the text is all Arabic... the font courier doesn't contain those characters. Browsers have various fall-back positions they can use, but a PDF renderer will just do what it's told to the best of its ability. And in this case, that's the unknown character character.

Simple Test: can wkhtmltopdf successfully convert a "hello world.html" to PDF on your system?

<html><body>Hello World</body></html>

If that works, you need to figure out where along the line between "brain dead" and "your real html" Things Go Awry.

Volnak answered 8/1, 2011 at 0:29 Comment(1)
Yes, I tested as you have told the test.html. Even that one is displayed in squares. But all are filled with black. I tested wkhtmltopdf-i386 and wkhtmltopdf-amd64. I am afraid, my problem is so complicated. What do you think? :(Ferule
K
0

I think you need to try to install the X11 packages, wkhtmltopdf uses that for fonts etc. The symptoms you describe are exactly what the program would do with those packages missing.

Kentish answered 13/2, 2011 at 20:21 Comment(1)
This is not true. If running EL7 you do not need the entire X11 system. Grab wkhtmltopdf-amd , then yum install libXrender libXext fontconfig urw-fontsWhimper
A
0

The standalone wkhtmltopdf does not need an x-server - try it and see if that alleviates the problem. I have it working on CentOS with no graphics/x-server and it works absolutely fine.

Absently answered 28/3, 2011 at 22:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.