-
Notifications
You must be signed in to change notification settings - Fork 1.9k
bad kerning for fonts in output PDF #45
Comments
I don't really have a clue here, as it looks like something internal to Webkit. Can you try if using a WOFF font works? In my test with Gentium, it does look marginally better. |
Can you check if you compile it yourself, it works better for you? |
Compiled it myself using the static shell script (wkhtmltopdf version 0.12.0 2d438a3) on a CentOS 6 box and the kerning is still rather obnoxious: see attached screenshot. Of particular note is the "o" in Total. When compiled on my Fedora machine, the problem is significantly reduced. |
This kerning issue has been going on for some time especially flagrant with smaller font sizes. |
I can see that this issue does occur, but until I get a clear idea on what is the root cause I'm afraid I won't be able to do anything much on this. It could be due to either one or more of the following:
Can we collect information on what works, and what doesn't? @benfavre: you said that it works better on phantomjs -- can you post screenshots? phantomjs uses QPA for running headless, but it is implemented by patching QT in wkhtmltopdf. |
For what it's worth, this doesn't happen on OS X. Here's a PDF rendered on OS X from the test.html document mentioned above. However, as you might notice, the OS X binaries are currently producing PDFs that are rasterized (text is not selectable). More info available on this at phantomjs issue 10373. |
@ashkulz Sorry if I was confusing on the selectable text issue on OS X. This non-selectable text issue on OS X is still an issue (text is not selectable - not fixed). This has been persistent for as long as I know of. |
@ashkulz: The version of But: I just ran After this, I tried transferring the i386 binary compiled on the Debian i386 machine to the Fedora machine and generate the PDF there. The resulting PDF was identical (sans creation date...) with the one from the So, where I compile doesn't seem to matter, but where I run it do. When running I generated a new minimal HTML test file to emphasize the difference. These two PDFs are generated using the same binary but on different computers. Century Schoolbook L on Fedora seems to render absolutely perfectly. Nimbus Sans L rendering seems a tiny bit wonky even on Fedora in the screenshot, but it's not that bad if one investigates several zoom levels, in my eyes. The PDFs are linked below if anyone wants to test themselves. Fedora on the left, Debian on the right
In the old bug report on Google Code, I had the exact same problems on Fedora and Debian, both using the statically compiled download of wkhtmltopdf 0.10.0 rc2 i386 from the project page. I know I have tried 0.11.0 rc1 as well on the Debian machine without any difference, but I don't know if I also tested that version on Fedora. Perhaps very relevant: I noted that bold+italic Century Schoolbook L rendered the same with both 0.10.0 rc2 and current 0.12.1 on Fedora, both with good results! From this I tried generating a new test suite on Fedora and Debian respectively, with these results: Fedora on the left, Debian on the right Debian text overlayed as green (75% opacity) on top of the Fedora rendering So, yeah, there is something to be said here. Perhaps someone with more knowledge of the internals can get some information from this. The kerning data for normal text seems to get calculated from incorrect metrics on Debian, but not on Fedora (at least not as bad), though it works with italic and bold+italic. |
@dandersson: that's a very long and detailed post! Offhand, the only reason could be differences in the freetype and/or fontconfig libraries -- those are linked dynamically and apparently the ones in Fedora perform much better than the ones in Debian/Ubuntu. It could be either due to patches, build configuration or runtime configuration -- to track it down is a very thankless task. However, does using WOFF fonts on Debian give you better results? If that is the case (and hopefully if the display is same on both Debian and Fedora) maybe we can recommend using them for perfect display until we are able to nail down the reason for the difference. |
@ashkulz: I'll check how WOFF fonts are handled on my system later (it could take up to a couple of days before I have the chance to, though), unless someone else experience the same behavior on a Debian related distribution and has the time to investigate directly. One should also test the behavior of bold non-italic fonts; perhaps they are related to the underlying rendering library's confusion of metrics. |
@ashkulz I compiled a binary from the
When I get some time I'm going to give phantomjs a try and see if the issue is fully resolved there. If it is, I'll see if I can track down the differences. |
@npinchot: let us discuss in the PR directly, not in this thread. @dandersson: it looks like a known issue in debian, acknowledged in their wiki. Can you see if the changes mentioned in the wiki or this thread help you out, in addition to trying out WOFF? |
@ashkulz: Yes, with a font configuration file with these contents as per the Debian wiki entry, the result on Debian Sid is also good! I'd actually say it is even better than on Fedora, but the difference is not major, and certainly not related to As further information in case anyone is looking for the solution to the same problem: the Debian wiki says that the configuration file should be named
…but not even this is really true, at least not on my machine, since So, it seems that the problem with the "original" 2009 bug was underlying libraries that currently reside in different patched states across different distributions. Also, something must have changed in WOFF on Debian Sid, with and without font configuration changes, gives the following results: Updated font configuration on the left, vanilla on the right Vanilla font configuration PDF overlayed on PDF with updated configuration
In conclusion, the problems for which I opened this issue are resolved in the latest code revisions from what I can see. Perhaps there are some users who followed the old issue #72 on Google Code that are still having problems. In that case I guess they will have to bring additional information here, or open a completely new issue. |
@dandersson: thanks for the confirmation! The underlying QT was upgraded to the latest 4.8 release (4.8.5) for 0.12.0, which would have fixed any issues at the QT end (if any). I really appreciate your detailed (and screenshot-ful) comments -- I wish all bug reports were like that 👍 |
Also, @trvrnrth made a change for font kerning in wkhtmltopdf/qt@091befc -- that may well have done the trick -- it is even in the release notes for 0.12.0 :) |
Pardon commenting on a closed thread, but I wanted to confirm that adding the contents posted by @dandersson to a file in /etc/fonts/conf.d/ also did the trick for my CentOS rendering issues; no need for base64-encoded fonts or every other workaround I was trying. Thanks so much! |
I'll try to see that this gets documented on the website; added a tag to track that. |
Binaries for Linux/Windows (32/64-bit) of the latest development snapshot are available, please test whether they work for you (i.e. no regressions). Mac OS X binaries should be available in a day or so. |
Mac OS X binaries are available now as well. |
Hi all, sorry for posting in a closed thread. I'm one of those folks following the old #72 issue. I've just downloaded the latest development snapshot binaries (for Win32 and Win64, 0.12.1-773cad3.) and I've just checked that this issue still remains in such builds. These are the outputs of wkhtmltopdf (the .pdf output as rendered by PDF-XChange Viewer) and Chrome (the source .xhtml file as rendered by Chrome). This is a detail of the wkhtmltopdf resulting .pdf file, showing evident flaws. I've compared this output to those obtained by 0.10 rc2 and 0.11 rc2 binaries and they look identical. Perhaps this issue has not been solved yet on Windows boxes? |
@emece67: try using |
Generally speaking the output of Fonts is handled at the system level.
|
I am not sure whether this is applicable to wkhtmltopdf, but I recently had a kerning issue in Windows when Word was invoked from a service via COM. This issue was resolved by selecting a printer, namely "Microsoft XPS Document Writer", instead of relying on the default one. I've not seen the internals of wkhtmltopdf, but I do wonder if that could help here. Surely Webkit has some sort of a printer setting; perhaps it will have the desired effect? I was skeptical about this myself, thinking "what could that possibly have to do with save-to-PDF", but it does in Word, so maybe it also does in Webkit? |
I have the same Problem like AndressonPeter. Does everyone have an idea, how i can fix that problem? |
@chherren try to avoid small font sizes as those seem to get the worst merging of chars but so far i haven't been able to eliminate the issue completely. |
the solution that @nouknouk gives, worked for me too!! and I had to zoom 0.8 for CentOS (AWS Linux), working on Windows 7 @ashkulz any way to get a fix from the wkhtmltopdf side? at least a "FAQ" or like? I found the solution after many days with try/error and searching, as I'm working with a wrapper for Laravel too! (https://github.com/barryvdh/laravel-snappy) btw, thanks for the library! =) |
I was having this problem and followed the instructions of creating a I found the real solution was to upgrade freetype to 2.7 and all problems were fixed. I also have a box with freetype 2.4 installed that wasn't having problems but 2.7 has much better kerning so I'd advise going for the newest version you can. |
I don't know if this is still relevant, but I solved the kerning issue on Windows 10 by setting the DPI to at least 200. |
@nouknouk I wish I could cuddle you! |
@nouknouk Amazing! I fixed the bad kerning with the config both on Debian Jessie and CentOS 7. Cool. |
The Debian page seems to have changed, so here's the XML mentioned in @nouknouk's answer:
It fixes the same issue with PDF rendering in PhantomJS, too. I was running an AWS Elastic Beanstalk machine, and used |
@KKSzymanowski Thank you for your comment:
It worked for me too. Definitely a problem, don't know why 96dpi is the default. |
Hi all, sorry for posting in a closed thread. I tried everything that has been posted here but it seems my output doesn't match with my output version from Windows. I'm on CentOS. I created the file 05-wkhtmltopdf.conf but with or without it it doesn't change anything. Am I missing something? UPDATE : changed the file to be a symbolic link, but it's still not working |
@SoTDarksoul try to update 51-local.conf it will work |
@s5 I'm having the same issue, but I can't seem to find the font in svg format. Could you tell me where do you get it please? UPDATE: Nevermind, I got the ttf files from google font repo and converted them using an online tool. |
See: #2022 |
@vinhluan how did you use the SVG file exactly to make it work |
Found a solution to fix the kerning issue when using WKHTMLToPDF on AWS Lambda (Serverless) https://www.internalpointers.com/post/fixing-ugly-fonts-chrome-chromium-debian-xfce.
|
This works on Azure App Service (Basic Tier or higher) as well 👍 |
This is the old Issue #72 from Google Code, first reported in 2009. It still occurs with the dev branch of 0.12.0, tested with commit d6541fe .
What steps will reproduce the problem?
Generate PDF from any HTML input with wkhtmltopdf via e.g.
View it. Tested with Evince, Xpdf and Chrome's built-in PDF reader with similar results.
What is the expected output? What do you see instead?
Expected: A PDF rendering similar to the one seen of the HTML document in a browser, specifically concerning the letter-spacing.
Result: The kerning is way off. Sometimes too expanded, sometimes too condensed. See attached sample rendering of (from left to right):
What version of the product are you using? On what operating system?
Dev branch of 0.12.0, tested with commit d6541fe . Debian Sid, i386. Using the binary that resulted after building the Git revision with:
I have tested earlier versions of Wkhtmlpdf on Fedora (amd64) with identical results.
Please provide any additional information below.
I include the sample document and rendering below, but it happens with everything I throw to Wkhtmltopdf, so I don't think there are any specific "clues" in the minimal HTML code.
strace
outputgrep
:ed for file I/OThe text was updated successfully, but these errors were encountered: