问题
I'm using wkhtmltopdf to download a webpage as pdf.
But the css property letter-spacing seems doesn't work
font-size:20px; letter-spacing:0px;
font-size:20px; letter-spacing:1px;
The spacing is very large for 1px...
I tried with 2 differents font-family
回答1:
Its a known issue. https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1575 . No fix for it. Only to avoid using letter-spacing
回答2:
Issue every one face with letter spacing, perfect solution is here.
import pdfkit
#SnippetBucket.com code for pdfkit
path_wkthmltopdf = r'/var/www/aukcnydom/wkhtmltox/bin/wkhtmltopdf'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
#more better and more accurate code for DPI set
config.default_options = {
'page_size': 'A4',
'print_media_type': True,
'dpi': 96
}
pdfkit.from_string(mark_safe(unicode(self.document)),settings.MEDIA_ROOT +"/"+ path, options=options, css=style, configuration=config)
Than in css. Add your letter-spacing.
p{letter-spacing: 0.4mm !important; text-align: justify ; font-kerning: normal; text-rendering: optimize-speed;}
/* SNIPPETBUCKET.COM, CSS CODE WITH LETTER SPACING */
This way simply resolve your issue and work perfectly letter spacing.
Note: I had given sample, you may apply applicable changes with your code.
回答3:
I had the same problem, I set the dpi to 96 (in wkhtmltopdf options) and worked, not sure why though.
回答4:
letter-spacing is broken in wkhtmltopdf.
But i found other ways around for kerning:
1. You may set position for every letter. Kerning is used for headings so there are not so much letters usually.
2. You may alter the font file and set the custom kerning you want. Usually it would be enough to alter latin letters. I've tested this and it worked well. Used FontForge (http://fontforge.github.io/) for this. But may be there is a more convenient software.
回答5:
I had the same issue and I have solved it by
sudo wget http://pastebin.com/raw.php?i=AmfYN3er -O /etc/fonts/conf.d/10-wkhtmltopdf.conf
http://www.jeremydaly.com/how-to-install-wkhtmltopdf-on-amazon-linux/
回答6:
Using wkhtmltopdf 0.12.4 or 0.12.5 on Windows you can use --dpi 300
on the wkhtmltopdf
command line, to almost solve the issue. If you zoom a lot you may still notice some letters have negligible differences in spacing, but the letters no longer overlap. And with --dpi 600
makes it almost perfect. The rendered pdf file size was not increased in my scenarios.
回答7:
We faced the same problem. One workaround is to set the dpi
flag to 96
.
As setting the DPI to such a low value (print usually uses at least 300) resulted in blurry images, we tried to use SVG font files, which did the trick.
来源:https://stackoverflow.com/questions/34241932/letter-spacing-is-too-large-with-wkhtmltopdf