Squared characters issue on wkhtmltopdf

▼魔方 西西 提交于 2019-11-28 21:05:50

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

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

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.

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.

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.

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.

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

apk --update add ttf-dejavu
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!