Google Webfonts in PDF format generated by DOMPDF

I am using two websites per page which I convert to PDF using dompdf. I have this in the title:

<link href='http://fonts.googleapis.com/css?family=Signika:600|Roboto+Condensed' rel='stylesheet' type='text/css'>

      

Then I use them in CSS rules like

body {
  font-family: "Roboto Condensed", sans-serif;
  [ ... ]
}
h1 {
  font-family:'Signika', Arial, Helvetica, sans-serif;
  [ ... ]
}

      

Now when I create the PDF, h1 is displayed with the font "Signika", but the "Roboto Condensed" is replaced with Helvetica or another standard sans serif font.

If I open the preview file (ie a php page, which I then include in the PDF script generation), "Roboto Condensed" displays as expected, but does not end up in the PDF. But, as I wrote, "Signika" is in the PDF file, and this is somehow strange to me. By the way, I have also tried to incorporate a rule font-face directly in the CSS rules for the p

, div

, li

, and so on, but it will not change anything.

Any suggestions how I could fix this?


EDIT / Addition:

Thinking about it, the difference between the two fonts is that Roboto Condensed has a space in its name. I wonder if this might be causing the problem (i.e. Dompdf cannot handle such a font name)? But I cannot change this while I am getting the fonts from google server.

+3


source to share


1 answer


I found a solution myself:

As I added to my question in edit, the reason was that the name of the Roboto Condensed font family contains a space, which homepdf apparently doesn't like.

I downloaded the font, created three versions of it with the font generator on Fontsquirrel, and put them on my server along with this stylesheet:



@font-face {
    font-family: 'roboto_condensedregular';
    src: url('robotocondensed-regular-webfont.woff2') format('woff2'),
         url('robotocondensed-regular-webfont.woff') format('woff'),
         url('RobotoCondensed-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

      

Then in my CSS rules I used this new font name roboto_condensedregular

infont-family: roboto_condensedregular, sans-serif;

Now it works, also in PDF format.

+1


source







All Articles