TCPDF ERROR: cannot contain font definition file: 'stalemate'

I have an html that uses some script fonts that need to be converted to pdf. Everything works for me on this, except when I try to include script fonts in pdf, it gives the following error:

TCPDF ERROR: Could not include font definition file: 'stalemate'

Original font from the Google Fonts library. Following the instructions I found, I renamed the font so that it was all lowercase, and then made the matrix files using the ttf2ufm utility. Then I took these files and used the makefont.php utility to make the necessary font files included in the TCPDF font folder (stalemate.z, stalemate.ctg.z and stalemate.php). I also tried putting them in a specific folder and pointing to this as well.

It looks like I have all the right files in all the right places and still get the above error. If I put out the style for this font in html, the PDFs are just fine.

I made a small test page at http://mattodesigns.com/pdfconverter.php which take the html from http://mattodesigns.com/sample.html and convert it to pdf. Below is the php code:

<?php
require_once 'html2pdf_v4.03/html2pdf.class.php';

$url = 'http://mattodesigns.com/sample.html';
$source = file_get_contents($url);
$html   = str_replace(array("\r", "\n", "\t"), '', $source);
$orientation    = 'P';
$format     = 'A4';
$margins = array(0,0,0,0);

$html2pdf = new HTML2PDF($orientation, $format, 'en', true, 'UTF-8', $margins);
$html2pdf->addFont('stalemate', '', 'stalemate.php');
$html2pdf->WriteHTML($html);
$html2pdf->Output('first_PDF_file.pdf');

?>

The HTML that it pulls out is:

<html>
<head>
<style>
    @font-face {font-family: "stalemate"; font-weight: 400; src: url(/fonts/stalemate.otf) format("opentype");}
</style>
</head>

<body>
<h1>Make Sure this is working</h1>
<p style="font-family: 'stalemate', cursive ;">This is your first PDF File</p>
</body>
</html>

Any ideas on this would be great.

+4
source share

Source: https://habr.com/ru/post/1548682/


All Articles