dompdf special characters

后端 未结 5 770
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 15:21

I\'m having successful html-to-pdf conversions, but not with special characters.

Below is just a special character I\'m trying to display, which displays in browsers

相关标签:
5条回答
  • 2020-12-11 15:56

    You must use another character set. For example dejavu Sans Mono. Add your code

    <style>
    *{
        font-family:"DeJaVu Sans Mono",monospace;
    }
    </style>
    

    I also mentioned it in this video.

    0 讨论(0)
  • 2020-12-11 15:57

    DOMPDF Latin Turkish (Türkçe) char problem, my solution %100 Work.

    Server requirenment control:

    Char 'dejavu sans mono' (Turkish support) OR:

    Step 1: dompdf_config.inc.php edit to

    mb_internal_encoding('UTF-8');
    def("DOMPDF_UNICODE_ENABLED", true);
    

    Step 2: lib/fonts/dompdf_font_family_cache.dist.php edit to add code:

    'futural' => 
      array (
        'normal' => DOMPDF_FONT_DIR . 'FUTURAL',
        'bold' => DOMPDF_FONT_DIR . 'FUTURAL',
        'italic' => DOMPDF_FONT_DIR . 'FUTURAL',
        'bold_italic' => DOMPDF_FONT_DIR . 'FUTURAL',
      ),
    

    Step 3: doqnload font files to copy lib/fonts folder. Download font files Link http://www.2shared.com/file/k6hdky_b/fonts.html

    Step 4: Your code Edit example:

    require_once("dompdf_config.inc.php");
    $html='<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        html{padding:-30px;}
        body { font-family: futural; }
    </style>
    </head><body>';
    $html.='ı İ Ş ş ç Ç ö Ö ü Ü ğ Ğ ÿ þ ð ê ß ã Ù Ñ È »  ¿ İsa Şahintürk';
    $html.='</body></html>';
    if ( isset( $html ) ) {
        if ( get_magic_quotes_gpc() )
        $html = stripslashes($html);
        $old_limit = ini_set("memory_limit", "16M");
        $dompdf = new DOMPDF();
        $dompdf->load_html($html,'UTF-8');
        $dompdf->set_paper('a4', 'portrait');// or landscape
        $dompdf->render();
        $dompdf->stream("limitless.pdf");
    exit(0);
    }
    

    End Finish PDF > exampleenter image description here http://limitsizbilgi.com/pdf/dompdf-chartest.pdf

    0 讨论(0)
  • 2020-12-11 16:01

    I have experienced problems with DOMPDF when converting an UTF-8 html page. I simply solved the problem by adding

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    

    Between < head > tag. Maybe it could be an alternative if you set it with your encoding type.

    IMPORTANT NOTE from comments below: don't use stream() and output() methods on the same pdf instance. If you do this wont work.

    0 讨论(0)
  • 2020-12-11 16:01

    Anything prior to 0.6.x has limited support for characters outside iso-8859-1 encoding. The Euro is supported in 0.5.x by using the appropriate Windows ANSI character code (&#0128;), but otherwise you have to jump through some PDF encoding hoops.

    The 0.6.0 release has better support for "special" characters. The default encoding is based on Windows ANSI (one of the few recognized by the PDF 1.3 spec). You can enable better character support by loading a Unicode-based font and enabling Unicode in dompdf and specifying that encoding in your document.

    The following should work in dompdf 0.6.0 or greater:

    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
      <p>€</p>
    </body>
    </html>

    (or to be lazy just use the euro entity &euro; in your test)

    There is a document outlining the steps needed to enable Unicode support in DOMPDF. Plus read this answer for an overview of how to load fonts.

    0 讨论(0)
  • 2020-12-11 16:05

    after trying all solutions on the net. I could solve without modifying the dompdf. the problem was on the html content. I just had to add the correct and appropriate HTML structure and setting the font of course . Tested on v0.6.0 and v0.6.1. here I leave the code

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    
    <head>
      <meta http-equiv="Content-Type" content="charset=utf-8" />
      <style type="text/css">
        * {
          font-family: "DejaVu Sans Mono", monospace;
        }
      </style>
    </head>
    
    <body>your content ćčžšđ...</body>
    
    </html>
    
    0 讨论(0)
提交回复
热议问题