I am using DomPDF, and some of the special characters are printed as a question-mark ("?").

An example was the checkmark ( ✓ ).

After some research, an article on stackoverflow showed the answer:
http://stackoverflow.com/questions/5136067/dompdf-special-characters

The main problem is the default font.

At the moment, the default CSS file in entity-print only sets a single font:
font-family: sans-serif;

Instead, it needs to have something like this; this below worked for me, but other font-families are of course possible:

font-family: Verdana, Tahoma, "DejaVu Sans", sans-serif;

Then the characters showed up in the PDF.

It probably would be good to have something like this in the default CSS, or at least a comment in there that depending on the font/font-family that is used, you may not see some special-characters. However, since many people probably just try the default CSS, it should contain a working solution.

(Other note, I also changed the meta-tag in the template to this, but that seemed less of a problem)

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  ...
</head>
) 
CommentFileSizeAuthor
#4 2851057-4.patch268 bytesbenjy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hoporr created an issue. See original summary.

benjy’s picture

Which font does it end up using to render the tick? Is it possible to reproduce this on the /debug url? If so, we could add a test.

hoporr’s picture

This is what I ended up using in the CSS, and the checkmarks showed up. Not sure which of these four the PDF generator actually uses, but apparently "sans-serif" by itself in the default style sheet can be ruled out :)

body {
  font-family: Verdana, Tahoma, "DejaVu Sans", sans-serif;
  
  font-size: 10px;
  color: black;
}
benjy’s picture

Status: Active » Needs review
FileSize
268 bytes

It seems to be DejaVu Sans packaged with Dompdf that has the good unicode support. Updated the fonts in the attached patch.

benjy’s picture

Status: Needs review » Fixed

Committed and pushed.

  • benjy committed 14eb7d1 on 8.x-2.x
    Issue #2851057 by benjy, hoporr: DomPDF, special characters
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sajidmanzoor’s picture

Hello
I am having the same issue with Chinese language.
I have tried the attached patch, added meta to page and added fonts to CSS but Chinese content is still not printing.
Please suggest a solution. I am using
Drupal 8.2.x

kaipipek’s picture

I have problems printing Japanese (partly Chinese) characters as well. They are printed as either rectangles or question marks.