问题
We're using wkhtmltopdf to render a PDF from an HTML page however fonts such as Verdana and Georgia aren't being displayed properly. We installed the TrueType fonts on our server using these instructions. Fonts are being set inline using style tags: style="font-family: verdana, geneva;"
Any suggestions on what we can try next to get these fonts to display would be appreciated.
回答1:
Try Arman H.'s solution posted over on this question: Google Web Fonts and PDF generation from HTML with wkhtmltopdf
Base64 encoding the fonts into your css has worked like a charm for us.
回答2:
have you set up the fonts in your css correctly?
e.g.
@font-face {
font-family: 'Verdana';
src: url('verdana-webfont.eot');
src: url('verdana-webfont.eot?#iefix') format('embedded-opentype'),
url('verdana-webfont.woff') format('woff'),
url('verdana-webfont.ttf') format('truetype'),
url('verdana-webfont.svg#Verdana') format('svg');
font-weight: normal;
font-style: normal;
}
回答3:
I am not sure if this works for this problem but I solved my problems by installing true type fonts. After that wkhtmltopdf was able to display these fonts.
Ubuntu (18.04)
apt install fonts-droid-fallback ttf-dejavu fonts-freefont-ttf fonts-liberation ttf-ubuntu-font-family
Alpine Linux (3.9)
apk add ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family
来源:https://stackoverflow.com/questions/14467820/wkhtmltopdf-not-displaying-truetype-fonts