Custom Font Issues

832 views
Skip to first unread message

Matt Olson

unread,
Jul 28, 2014, 5:41:36 PM7/28/14
to dom...@googlegroups.com
I am making a custom deign application for the web at Viva Concepts. I have everything working great on this now, but the custom fonts. Specifically, there are 4 signature fonts that the person can pick from (Google Fonts: Stalemate, Mr De Haviland, Mrs Saint Delafield and Herr Con Muellerhoff). 

I have tried this with html2pdf, which uses TCPDF as it's backend and I get a "TCPDF ERROR: Could not include font definition file: 'stalemate'" (see the post on stack overflow). When I set this font as default, it works fine, but all the text is now Stalemate instead of just one sentence. This is a differnt PDF library, so then I moved over to DOMPDF, which I already use throughout the site. 

I made a sample html page that has the html code I want to make into a pdf and then have a separate page that runs the pdf converter code. Here is the link to those pages:


When I use DOMPDF the font 'stalemate' does not show up. It does not seem to error out and produces a PDF, but it makes the text invisible. I can copy the text from the pdf that is made and paste it into a text document, so the text is there, just not showing up.

In making the fonts I have used all 3 ways of making the font files, not of which made a difference. Though with php-font-lib this should handle it automatically now. I can see that the fonts are made and added to the dompdf_font_family_cache file as well, but still no luck.

I have been checking through forums and banging my head to figure this out for weeks now, with no luck.

The following is the php code that I have in the PDF Converter Page:

<?php

require_once
'dompdf/dompdf_config.inc.php';

$url = 'http://mattodesigns.com/PDFs/sample.html';

$source = file_get_contents($url);
$html
  = str_replace(array("\r", "\n", "\t"), '', $source);

$dompdf = new DOMPDF();
$dompdf
->set_paper('viva insert');
$dompdf
->load_html($html);
$dompdf
->render();
$pdf
= $dompdf->output();
$dompdf->stream("first_PDF_file.pdf", array("Attachment" => false));

?>


Really need some help on this to sort it out.

BrianS

unread,
Jul 28, 2014, 7:00:37 PM7/28/14
to dom...@googlegroups.com
Are you running with the latest version of dompdf? I was able to convert the document you posted without issue.

When I view the document in Firefox I see text, just not what's expected. In Adobe Reader I see nothing, but as you say the text is there.

A couple of suggestions, though I don't know if any will help:

  1. Remove the line with the str_replace() from your code ... shouldn't need it.
  2. In your HTML you shouldn't need to @font-face declaration since you're already getting it from Google. Try taking that out.
  3. If you want to use a local copy of the font file remember that path references depend on how you load the document into dompdf. I'd load the file directly, e.g. $dompdf->load_html_file('http://mattodesigns.com/PDFs/sample.html');.
  4. Reset your fonts, you could have a corrupt font or font metrics file. Easiest path for this is to delete the files in dompdf/lib/fonts and replace with fresh copies. If you're comfortable editing you can remove the stalemate font files and metrics and edit the dompdf_font_family_cache file. Also remember to clear out the font cached (e.g. files in dompdf/lib/fonts that end in .ufm.php)
Message has been deleted

Matt Olson

unread,
Jul 30, 2014, 1:06:06 PM7/30/14
to dom...@googlegroups.com
Hey Brian, Thanks for the response.

I did the suggestions you stated and still no luck. It is converting it to a PDF, the fonts that have stalemate in the css just are not showing up, they are invisible to sight on the PDF, but the text is actually there. I just wasn't sure if I was doing something wrong or not. I can't tell what the version of dompdf I have, but I downloaded the latest version from github last week. In TCPDF I have the font working by using setfont(), but not sure if there is something I have to do like that with dompdf.

BrianS

unread,
Jul 30, 2014, 11:37:48 PM7/30/14
to dom...@googlegroups.com
dompdf relies solely on the CSS for setting the font (loading a font, as you know, can also be done through CSS or by using load_font.php). You are obviously setting the font correctly because dompdf is attempting to use the font. It's just not loading correctly. I don't have time right now to dissect the PDF, so a few more trouble-shooting ideas:
  1. Have you tried with font subsetting disabled?
  2. Can you open the font file saved to dompdf/lib/fonts (i.e. the stalemate TTF file) on your local computer? Perhaps the font itself is corrupted.
  3. Have you tried a different custom font (such as from Google Fonts)?
  4. Have you grabbed a fresh copy of dompdf from github and removed your current copy. There have been instances in the past of random file corruption with the dompdf files.

Matt Olson

unread,
Jul 31, 2014, 6:59:59 PM7/31/14
to dom...@googlegroups.com
Hey Brian, Thanks for you help. I tried enabling and disabling the subsetting, tried different custom fonts like Lato, Grabbed a fresh copy of the latest version of DOMPDF. Still no luck. I have updated the html page, which is not at mattodesigns.com/PDFs/insert-sample.html which more closely represents one of the items that I am using this for. Everything works perfect with positioning and such but the custom font itself. I did also try and load the same font locally on my comp and works great, no issues. mattodesigns.com/PDFs/dompdfconverter.php

I have also been trying out TCPDF and you can see the conversion of the same page here at mattodesigns.com/PDFs/insert-tcpdfconverter.php. You can see that it converts the font perfectly, but the styles are all whack. I would prefer to use DOMPDF as that is what I am using on the rest of the site at this point. I am willing to compensate for your time if this is something you think you can handle.

BrianS

unread,
Aug 3, 2014, 9:12:19 PM8/3/14
to dom...@googlegroups.com
I'm at a loss right now. Unless you can find some additional information on what's going wrong I'm not sure I can take you much further. Are you not getting any PHP errors or anything like that? If you enable debugging what does the dompdf log look like?
Reply all
Reply to author
Forward
0 new messages