Custom Fonts for DOMPDF

纵然是瞬间 提交于 2019-11-28 17:32:52

问题


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.

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

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.

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

?>    

回答1:


  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;



回答2:


you can add css font :

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

and than

div.ClJ{
    font-family: new_font; 
}



回答3:


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

1- Download ejaz.php from here

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

no need of root or command/terminal access

Thanks!



来源:https://stackoverflow.com/questions/12581156/custom-fonts-for-dompdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!