14

I am using the DOMPDF library to create an invoice in PDF. This document can be in French, Russian or English, but I am having trouble printing Russian characters.

First, I tried to use UTF-8 encoding and placed the meta tag in the head of the HTML page to be converted:

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

But that didn't work.

Then I inserted this meta tag inside the BODY tag, and it helped solve the problem with French characters.

But Russian characters still don't work. I have also tried to convert Russian characters into HTML entities, but that too does not work.

I use R&OS CPDF class, not PDFLib as a backend.

Can anyone help?

random
  • 9,774
  • 10
  • 66
  • 83

7 Answers7

15

if you will use DejaVu font you can see cyrillic characters

The DejaVu TrueType fonts have been pre-installed to give dompdf decent Unicode character coverage by default. To use the DejaVu fonts reference the font in your stylesheet, e.g. body { font-family: DejaVu Sans; } (for DejaVu Sans).

DOMPDF include DejaVu font be default

    $html = "<html><head><style>body { font-family: DejaVu Sans }</style>".
        "<body>А вот и кириллица</body>".
        "</head></html>";

    $dompdf = new \DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    echo file_put_contents('cyrillic.pdf', $dompdf->output());

You can also set change def for font by default in dompdf_config.inc.php

def("DOMPDF_DEFAULT_FONT", "DejaVu Sans");
nfort
  • 12,234
  • 3
  • 13
  • 13
8

Problem is with fonts default dompdf uses (that is it doesn't have all unicode characters, whick are by now over 5000). Usually arialuni.ttf is what you need. You can download localized russian version at http://chernev.ru/dompdf.rar {broken link}

Updated link: https://code.google.com/p/ipwn/downloads/detail?name=arialuni.ttf

CGSmith105
  • 490
  • 4
  • 17
Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42
2

In your html, use this style :

<style type="text/css">
* {
  /*font-family: Helvetica, sans-serif;*/
  font-family: "DejaVu Sans", sans-serif;
}
</style>
B.Asselin
  • 978
  • 10
  • 19
0

If none of the other answers help, upgrading Dompdf to version 7.0.0 helped me. Here is my code to generate:

// generate pdf.
$dompdf_options = apply_filters( 'yith_wcwl_dompdf_options', array() );
$dompdf         = new Dompdf\Dompdf( $options );
$dompdf->set_option('defaultFont', 'dejavu sans');
$dompdf->loadHtml( $template );
$dompdf->setPaper( 'A4', apply_filters( 'yith_wcwl_dompdf_orientation', 'portrait' ) );
$dompdf->render();
$dompdf->stream( $wishlist->get_formatted_name() );
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
-1

For me the 4 steps above didn't resolve the issue. Besides that, dompdf converts created pdf to ANSI (ISO) You need to disable this on the options page http://domain.com/admin/settings/print/pdf

Tick the checkbox Use dompdf's Unicode Mode. This will force to create files in UTF-8/Unicode.

Please note that web settings override settings in dompdf_config.inc.php by default.

-1

Noted that problem could be in css-reset usage, particularly font:inherit;

dmpol18
  • 161
  • 1
  • 8
-1

Download arialuni.ttf Run php load_font.php 'Arial' arialuni.ttf in dompdf directory, set font to arial It works ;)

qmic
  • 1
  • 1