0

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?

Deej
  • 105
  • 1
  • 1
  • 9

2 Answers2

0

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

Tom Metcalfe
  • 308
  • 1
  • 3
  • 12
  • Yeahh I've tried that :( to no avail. Thanks all the same Tom :) ... PS. Setting author tag didn't work either :/ – Deej Jul 16 '13 at 16:53
  • Have you tried testing multiple fonts ?? And that's weird, if you're creating your dompdf object as follows "$dompdf = new DOMPDF();" with the included library and call "$dompdf->add_info('Author', 'Tom'); it should work! – Tom Metcalfe Jul 16 '13 at 16:57
  • A bit more information on the environment you're coding in may be helpful. For example are you using a framework ? I use DOMPDF in zend and had to configure it quite a bit before it worked properly. – Tom Metcalfe Jul 16 '13 at 16:59
  • Apologies for the late reply, been O.O.O a few days. Yeah I'm using CakePHP, took some faffing to turn it into a helper but got there in the end. @BrianS seems to be on to something. – Deej Jul 23 '13 at 18:59
0

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.

BrianS
  • 13,284
  • 15
  • 62
  • 125
  • Thanks Brian, not at the office now so I can't try, but I did wonder if it had something to do with .ttf ... I wondered what webfonts actually served, I'll have a look tomorrow. Like you say though, I might scrap the hosted ones and just serve them myself. – Deej Jul 23 '13 at 19:01
  • Ok @BrianS I finally got chance to spend some time on this project, and the style changes didn't work unfortunately, even referencing the truetype. `Class 'Font_Glyph_Outline' not found` Still being thrown :( – Deej Sep 17 '13 at 12:33
  • A little late, but I started working on this issue again. I still need to spend a little time with your specific issue, but the error you encountered is do to bad ordering of class definitions. You can find a solution to the issue here: https://github.com/dompdf/dompdf/issues/585#issuecomment-19325100 – BrianS Jan 13 '14 at 15:59