TCPDF错误:无法包含字体定义文件:'stalemate'

时间:2014-07-16 18:57:12

标签: php tcpdf html2pdf

我的html使用了一些需要转换为pdf的脚本字体。我已经完成了所有工作,除非我尝试在pdf中包含脚本字体,否则会出现以下错误:

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

原始字体来自Google Fonts库。根据我发现的说明,我将字体重命名为全部小写,然后使用ttf2ufm实用程序制作矩阵文件。然后,我接受了这些文件,并使用makefont.php实用程序将字体所需的文件包含在TCPDF字体文件夹中(stalemate.z,stalemate.ctg.z和stalemate.php)。我也尝试将它们放在一个特定的文件夹中并将调用指向它。

好像我在所有正确的位置都拥有所有正确的文件,但仍然会出现上述错误。如果我在html上取出该字体的样式,文档PDF就可以了。

我在http://mattodesigns.com/pdfconverter.php创建了一个较小的测试页面,它从http://mattodesigns.com/sample.html获取html并将其转换为pdf。以下是php代码:

<?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');

?>

它提取的HTML代码是:

<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>

对此的任何想法都会很棒。

0 个答案:

没有答案