38

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.

jamesh
  • 19,863
  • 14
  • 56
  • 96
Tim Tuckle
  • 1,372
  • 7
  • 21
  • 31
  • Bad Revolver - Have a look at @James F answer, this did the trick for me – Elitmiar Jan 28 '12 at 09:02
  • If you're seeing this only on some line-breaks, try adding `text-rendering: geometricPrecision;` to the `body` class in your CSS, as per: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1734 – Joshua Pinter Sep 21 '15 at 20:06
  • @Tim - please mark James F answer as correct by clicking the grayed out checkmark under the current vote count of 56. – a coder Mar 22 '16 at 17:30

7 Answers7

82

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

James F
  • 1,066
  • 9
  • 5
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
rjhilgefort
  • 453
  • 4
  • 12
  • 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-fonts` – a coder Mar 22 '16 at 17:31
4

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

apk --update add ttf-dejavu
Robert Strobl
  • 295
  • 2
  • 12
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.

hgp-it
  • 31
  • 4
  • 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) – ɹɐqʞɐ zoɹǝɟ Dec 20 '17 at 07:37
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.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
  • 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? :( – Tim Tuckle Jan 10 '11 at 21:26
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.

Kay Lucas
  • 589
  • 1
  • 3
  • 17
  • This is not true. If running EL7 you do not need the entire X11 system. Grab [wkhtmltopdf-amd](https://github.com/h4cc/wkhtmltopdf-amd64) , then `yum install libXrender libXext fontconfig urw-fonts` – a coder Mar 22 '16 at 17:33
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.

ʍǝɥʇɐɯ
  • 4,012
  • 7
  • 32
  • 53