php DOMPDF 的自定义字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12581156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:51:32  来源:igfitidea点击:

Custom Fonts for DOMPDF

phppdf-generationdompdfcustom-font

提问by pinaldesai

I'm Using DOM PDF 0.6.0 Beta 2. I want to use custom fonts (Fonts: 'Segeo Print', 'Lucida Handwriting','Airplanes in the Night Sky') in PDF file.

我正在使用 DOM PDF 0.6.0 Beta 2。我想在 PDF 文件中使用自定义字体(字体:'Segeo Print'、'Lucida Handwriting'、'Airplanes in the Night Sky')。

I followed the guidelines to install and use fonts in my PHP Code, which is given here http://code.google.com/p/dompdf/wiki/CPDFUnicode

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

But I'm not able to get desire fonts in my PDF. You can find my code in this post. Please Let me know how I can resolve this issue.

但我无法在我的 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));

?>    

回答by Ueli

  1. go to your DOMPDF folder
  2. copy your font's as .ttf (TrueType Font) or .otf (OpenType Font) into the DOMPDF's root
  3. open your command line and run
    php load_font.php your_fonts_name ./your-normal.ttf ./your-bold.ttf ./your-bold-italic.ttf
  4. DOMPDF now created Adobe Font Metrics and copied it to lib/fonts/* - you can now use it with
    font-family: your_fonts_name;
  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 现在创建了 Adob​​e Font Metrics 并将其复制到 lib/fonts/* - 您现在可以将它与
    font-family: your_fonts_name;

回答by chokrijobs

you can add css font :

您可以添加 css 字体:

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

and than

然后

div.ClJ{
    font-family: new_font; 
}

回答by Ejaz47

If you want to install custom fonts to server without command basedinterface then you can do the following web based model to install the custom fonts

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

1- Download ejaz.php from here

1- 从这里下载 ejaz.php

2- Put this file to root of dompdf and follow the instruction written in it

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

no need of root or command/terminal access

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

Thanks!

谢谢!