DOMPDF的自定义字体

时间:2012-09-25 10:34:49

标签: php pdf-generation dompdf custom-font

我正在使用DOM PDF 0.6.0 Beta 2.我想在PDF文件中使用自定义字体(字体:'Segeo Print','Lucida Handwriting','夜空中的飞机')。

我遵循指南在我的PHP代码中安装和使用字体,这里给出了http://code.google.com/p/dompdf/wiki/CPDFUnicode

但是我无法在PDF中获得欲望字体。你可以在这篇文章中找到我的代码。请让我知道如何解决这个问题。

<?php     
    require_once("dompdf_config.inc.php");

   $html = "<html>
                <head>   
                    <meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
                    <style>
                        *{font-size:15px;}  
                        div.ClJ{font: nightsky;}   
                    </style>      
                </head>
                <body>            
                   <div class='ClJ'>This text is in DIV Element</div><br /><br />
                </body>
          </html>";

    $dompdf = new DOMPDF();    
    $dompdf->load_html($html);
    $dompdf->render();
    $pdf = $dompdf->output();
    $dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

?>    

3 个答案:

答案 0 :(得分:28)

  1. 转到您的DOMPDF文件夹
  2. 将您的字体复制为.ttf(TrueType字体)或.otf(OpenType字体)到DOMPDF的根目录
  3. 打开命令行并运行
    php load_font.php your_fonts_name ./your-normal.ttf ./your-bold.ttf ./your-bold-italic.ttf
  4. DOMPDF现在创建了Adobe Font Metrics并将其复制到lib / fonts / * - 您现在可以将其与
    font-family: your_fonts_name;
    一起使用

答案 1 :(得分:9)

你可以添加css字体:

@font-face {
    font-family: new_font;
    src: url('my_font.ttf');
}

而不是

div.ClJ{
    font-family: new_font; 
}

答案 2 :(得分:0)

如果您想在没有基于命令的界面的情况下将自定义字体安装到服务器 然后,您可以执行以下基于Web的模型来安装自定义字体

1-从here

下载ejaz.php

2-将此文件放入dompdf的根目录并按照其中的说明进行操作

不需要root或命令/终端访问

谢谢!