“Font_Glyph_Outline” Error when using WebFonts with DOMPDF

做~自己de王妃 提交于 2019-12-24 22:32:15

问题


I'm trying to implement DOMPDF, everything is working (thanks to multiple Stack users) but I'm now having trouble rendering WebFonts when.

According to the examples on the Google Code project for DOMPDF it is possible to use webfonts: http://pxd.me/dompdf/www/examples.php#css_at_font_face.html,html

I've ref'd the font in the page as I would a HTML page:

<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300' rel='stylesheet' type='text/css'>

and I've ref'd the font in the CSS:

body{
    font-family: 'Roboto Condensed', sans-serif;
}

but DOM PDF reports:

Class 'Font_Glyph_Outline' not found

Can any more DOMPDF guru's come to my aid?


回答1:


Unfortunately I can't yet comment :( But have you tried setting 'DOMPDF_ENABLE_FONTSUBSETTING' to false in the dompdf_config.inc.php file? That may (or may not) resolve your issue. Other than that I have no idea.

Interesting read though regarding something similar DOMPDF issues




回答2:


There are two issues that need to be addressed in your question. The more pressing is the PHP error which, as @tom-metcalfe pointed out, has yet to be resolved. The two pieces of information that may help resolve that are: dompdf version, PHP version.

If you do resolve that error you'll need to address another issue: dompdf only understands named font weights in the at-font CSS. If you're OK maintaining the CSS yourself you can work around this issue.

You need to work based off the True Type Font (TTF) version of the CSS since dompdf can currently only embed TTF. The Google Web Fonts at-font service offers up the most appropriate format based on the visiting browser. To get the TTF version of the stylesheet visit the URL in a browser that requires TTF for web fonts. I used lynx on my server (TTF must be the fallback for unknown browsers). Use the stylesheet from Google to create your customized CSS, e.g.:

@font-face {
  font-family: 'Roboto Condensed Light';
  font-style: normal;
  font-weight: normal;
  src: local('Roboto Condensed Light'), local('RobotoCondensed-Light'), url(http://themes.googleusercontent.com/static/fonts/robotocondensed/v7/b9QBgL0iMZfDSpmcXcE8nL3QFSXBldIn45k5A7iXhnc.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto Condensed';
  font-style: normal;
  font-weight: normal;
  src: local('Roboto Condensed Regular'), local('RobotoCondensed-Regular'), url(http://themes.googleusercontent.com/static/fonts/robotocondensed/v7/Zd2E9abXLFGSr9G3YK2MsDR-eWpsHSw83BRsAQElGgc.ttf) format('truetype');
}
@font-face {
  font-family: 'Roboto Condensed';
  font-style: normal;
  font-weight: bold;
  src: local('Roboto Condensed Bold'), local('RobotoCondensed-Bold'), url(http://themes.googleusercontent.com/static/fonts/robotocondensed/v7/b9QBgL0iMZfDSpmcXcE8nDokq8qT6AIiNJ07Vf_NrVA.ttf) format('truetype');
}

Notice that the font-weight declarations were modified to use the named weights and that the "light" variant of the font is given its own family name. Since dompdf doesn't have full support of numeric weights you'll have to do it this way.

I don't know how stable these font URLs are. They appear to be some kind of hash so it's possible they may go away at some point when a new version is released. To be safe you may want to host the files yourself.



来源:https://stackoverflow.com/questions/17682119/font-glyph-outline-error-when-using-webfonts-with-dompdf

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