Plugin Contributor
Ewout
(@pomegranate)
Hi Nick,
Making changes in the dompdf fonts folder is not necessary and makes updating the plugin a pain, so I do not recommend this.
There’s a tutorial on how to use your own fonts in the documentation: Using custom fonts. One important difference is that the example uses local server paths instead of URLs. A lot of servers have limited or blocked access to remote urls (even when it points to the same server, it can’t tell that), and ultimately DOMPDF needs the files locally on the server. (and therefor the browser preview doesn’t tell you much about whether the font is correctly downloaded or not).
Another difference is that you haven’t modified the font-family name. This will probably cause DOMPDF to use the Open Sans that it has already downloaded/converted to UFM.
Try using “David” instead (and another name for the russian font), and use that for the body too.
Hope that helps!
Ewout
Thread Starter
Nick
(@nickkkarp)
Hi Ewout,
Thanks a lot for the quick answer.
I changed URL to local path and the font name and it partially solved my problem. Now I see all the languages in PDF. BUT Hebrew words/phrases are reversed in PDF (for example, instead of “כרטיס אשראי” I get “יארשא סיטרכ”). In HTML the order is correct.
Thank you,
Nick.
Plugin Contributor
Ewout
(@pomegranate)
Hello Nick,
I’m sorry, I did not realize that Hebrew is RTL :o(
Unfortunately RTL is not supported by the DOMPDF, so I’m afraid I can’t help you here…
I hope you can still use the plugin for your Russian site!
Ewout
Hi Nick ,
if you want to fix Hebrew words/phrases reversed problem in PDF you can use this code in this file
woocommerce-pdf-invoices-packing-slips/lib/dompdf/include/text_renderer.cls.php
before this line
$this->_canvas->text($x, $y, $text
add this code
if (strtolower($style->direction) == 'rtl' && !mb_detect_encoding($text, array("ASCII"))) {
preg_match_all('/./us', $text, $ar);
$text = join('',array_reverse($ar[0]));
// if there are numbers in the string
// so the next line reverse the number back
// treat also numbers with dot (decimal) and email
$text = preg_replace_callback('/\d+-\d+|\d+|\d+\.\d+|\S+@\S+/', function (array $m) { return strrev($m[0]); }, $text);
}
this will fix reversed letters
Thread Starter
Nick
(@nickkkarp)
Ewout, Thank you! I really like your plugin, and I’m very sorry to hear that DOMPDF doesn’t support RTL 🙁
t3rep.com, Thank you for your suggestion, but it doesn’t work for me. It will work only if in generated HTML all my Hebrew phrases are inside |direction = “rtl” | style. I don’t have it because I have Hebrew text combined with Russian.
And if I remove the first condition in “if”, all my non-ASCII texts are inverted to RTL, Hebrew (now it looks good) and Russian as well (now is it reversed).
Only if I could write a condition like
if (“all chars in $text are Hebrew (UTF-8 range 0590-05FF)”){
then reverse
}
it could work…
Thread Starter
Nick
(@nickkkarp)
The solution that seems working for me:
if (!mb_detect_encoding($text, array(“ASCII”)) && preg_match(“/^\p{Hebrew}+/u”,$text)){
preg_match_all(‘/./us’, $text, $ar);
$text = join(”,array_reverse($ar[0]));
// if there are numbers in the string
// so the next line reverse the number back
// treat also numbers with dot (decimal) and email
$text = preg_replace_callback(‘/\d+-\d+|\d+|\d+\.\d+|\S+@\S+/’, function (array $m) { return strrev($m[0]); }, $text);
}
It reverses only pure Hebrew strings.
Thank you Ewout and t3rep.com for your kind help!
Nick.