UTF-8 Problem

3,249 views
Skip to first unread message

Shamharoth

unread,
Mar 22, 2010, 11:57:25 AM3/22/10
to dompdf
Hi
I am trying to convert HTML to PDF over C++ (with pipe to php) and
everytime I try to convert a UTF8 text I get questionsmarks except of
my local umlaute (the typical german "äöüß") and so on when I try to
convert signs like "€" they will be changed with "?", too.
The data which the C++-program sends to the php-script over the pipe
are normal (I made a output to the console and the answer I got (the
normal console print is the UTF8 signs "ąčęėįšųūž" ... so the
communication between my program and the script is ok.

So my question: How can I create a UTF-8 - PDF?

I tried the stabil version and so on I tried it with the newest Beta.

thanking you in anticipation

ramon castro perez

unread,
Mar 22, 2010, 12:31:03 PM3/22/10
to dom...@googlegroups.com
With PHP I use the function: "utf8-decode()"

2010/3/22 Shamharoth <shamh...@googlemail.com>

--
You received this message because you are subscribed to the Google Groups "dompdf" group.
To post to this group, send email to dom...@googlegroups.com.
To unsubscribe from this group, send email to dompdf+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dompdf?hl=en.




--
Ramón Castro
http://ramoncastro.es

BrianS

unread,
Mar 22, 2010, 1:15:55 PM3/22/10
to dompdf

Even with the upcoming release there are some limitation in character
support. The standard character encoding options in PDF only support a
limited number of characters out of the box. DOMPDF currently only
supports one of these encodings, which is a subset of Windows ANSI. If
you attempt to use the core PDF fonts you'll run into the problem you
noted.

The current recommended method to work around this limitation in
DOMPDF is to "install" a font and enable Unicode support.

Shamharoth

unread,
Mar 23, 2010, 4:01:16 AM3/23/10
to dompdf
At first thx for your answers

> With PHP I use the function: "utf8-decode()"

I tried the function utf8_decode() but my the first part of the
teststring was deleted
(teststring:
>öäü߀ÄÖÜ<br>
>&ouml;&auml;&uuml;&szlig;&Auml;&Ouml;&Uuml;<br>
>ąčęėįšųūž
the &ouml; are a html-code für ö and so on)

> Even with the upcoming release there are some limitation in character
> support. The standard character encoding options in PDF only support a
> limited number of characters out of the box. DOMPDF currently only
> supports one of these encodings, which is a subset of Windows ANSI. If
> you attempt to use the core PDF fonts you'll run into the problem you
> noted.
>
> The current recommended method to work around this limitation in
> DOMPDF is to "install" a font and enable Unicode support.

Ok so I have to install a unicode-font.... do you know one, which I
can use (maybe with web-address ^^)?

BrianS

unread,
Mar 23, 2010, 10:16:00 AM3/23/10
to dompdf

The font doesn't have to fully support Unicode, it only needs to
support he characters you need. DOMPDF works in Unicode because that's
how you can define extended character encodings in PDF documents. So
you should be able to use any of your system fonts. If you're not
comfortable setting up the ttf2ufm on your system you can try out the
web-based font prep tool:
http://groups.google.com/group/dompdf/browse_thread/thread/9f7bc0162b04d5cf

Shamharoth

unread,
Mar 24, 2010, 5:29:31 AM3/24/10
to dompdf
thx for answer. I tried to generate a czech font (I downloaded the
font from here: http://www.kwintessential.co.uk/fonts/czech/download.html
- Font 4) but when I generate a new PDF with
ščřžýáíé
I got everytime
¹èø¾ýáíé
so there is a problem with the "inverted roof".
So I tried it with the font package from Martin Všetička for dompdf
( http://www.martinvseticka.eu/index.php?sekce=browse&page=159 ) but
the pdf is everytime the same.
What did I make wrong?

Shamharoth

unread,
Mar 24, 2010, 6:27:52 AM3/24/10
to dompdf
now I tried it with meta-tag
<meta http-equiv="Content-Type" content="text/
html;charset=ISO-8859-2" />
and when I try to generate a page, I get this message:
Catchable fatal error: Argument 1 passed to Frame_Decorator::copy()
must be an instance of DOMNode, boolean given, called in /**my_path**/
dev-czech/include/text_frame_decorator.cls.php on line 132 and defined
in /**my_path**/dev-czech/include/frame_decorator.cls.php on line 118

And so on if I decode the string (utf8_decode) before rendering all
signes with an inverted roof would be changed with questionmarks.

Message has been deleted
Message has been deleted

Shamharoth

unread,
Mar 24, 2010, 9:18:58 AM3/24/10
to dompdf
me again ....
I post again because I can't see the light at the end of the
tunnel :/

now I tried to use a font from fontspace (http://www.fontspace.com/red-
hat-inc/liberation-sans) which normally supports symbols like 'č'.
I checked it online (it's possible to try the font by typing words in
one of the textboxes) and I tried it with the gnome font viewer.
Everytime it's possible to display the letters.
So i converted local with the load_font.php - script (with no
failures).
(./php ./load_font.php liberation /..../LiberationSans-
Regular.ttf /..../LiberationSans-Bold.ttf /..../Desktop/LiberationSans-
Italic.ttf /...../LiberationSans-BoldItalic.ttf)

Then I changed the defaultfont (define("DOMPDF_DEFAULT_FONT",
"liberation");) and generated a test-pdf with this php-script:

require_once("dompdf_config.inc.php");
$html = "ŠŘšžě";
//$html = mb_convert_encoding($inhalt, "iso-8859-2", "utf8");
$inhalt = utf8_decode($html);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("pdf_file.pdf");

When I am using mb_convert.... the result is "©Ø¹¾ì" and
when I am using utf8_decode the result is "?????"

That's .... really .... strange o_O

BrianS

unread,
Mar 24, 2010, 1:46:04 PM3/24/10
to dompdf
On Mar 24, 9:09 am, Shamharoth <shamhar...@googlemail.com> wrote:
> now I tried to use a font from fontspace (http://www.fontspace.com/red-
> hat-inc/liberation-sans) which normally supports symbols like 'č'.
> I checked it online (it's possible to try the font by typing words in
> one of the textboxes) and I tried it with the gnome font viewer.
> Everytime it's possible to display the letters.

I haven't tried with any of the fonts you specified. I am, however,
able to use Verdana from my own system and the characters display
correctly.

> So i converted local with the load_font.php - script (with no
> failures).
> (./php ./load_font.php liberation /..../LiberationSans-
> Regular.ttf /..../LiberationSans-Bold.ttf /..../Desktop/LiberationSans-
> Italic.ttf /...../LiberationSans-BoldItalic.ttf)
>
> Then I changed the defaultfont (define("DOMPDF_DEFAULT_FONT",
> "liberation");) and  generated a test-pdf with this php-script:
>
> require_once("dompdf_config.inc.php");
> $html = "ŠŘšžě";
> //$html = mb_convert_encoding($inhalt, "iso-8859-2", "utf8");
> $inhalt = utf8_decode($html);
> $dompdf = new DOMPDF();
> $dompdf->load_html($html);
> $dompdf->render();
> $dompdf->stream("pdf_file.pdf");
>
> When I am using mb_convert.... the result is "©Ø¹¾ì" and
> when I am using utf8_decode the result is "?????"

One of the problems here is that you are not supplying a full HTML
document. It may be that even when using mb_convert_encoding() PHP is
reporting the character set of the string incorrectly to DOMPDF.
Create a full document including a meta tag. I've tried this on my
system and it appears to work correctly. Try something like:

require_once("dompdf_config.inc.php");
$html = '<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;charset=ISO-8859-2" />
</head>
<body><p>ŠŘšžě</p></body>
</html>';


$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("pdf_file.pdf");

I would definitely not use utf8_decode. That will, essentially, take
any characters that fall outside the ISO-8859-1 character set and
convert them to "?" ... as you have seen.

Lastly, which version of DOMPDF are you using? Do you have
DOMPDF_UNICODE_ENABLED set to true?

Shamharoth

unread,
Mar 25, 2010, 3:56:16 AM3/25/10
to dompdf
thx for your answer I will try your code.

I am using linux to work so I don't really know is there a verdana-
font preinstalled? so when I try to locate it ("locate verdana") the
program finds only my downloaded font.

to your question: Yes I set the DOMPDF_UNICODE_ENABLED to true and I
tried it with dompdf 0.5.x and the 0.6 beta.
At the moment I am installing the beta a second time (so when there
was a problem with my first installation maybe it solve the problem by
reinstalling).

Shamharoth

unread,
Mar 25, 2010, 4:15:29 AM3/25/10
to dompdf
Now I tried your code. At first when I edit DOMPDF_DEFAULT_FONT the
font of the PDF doesn't change and when I explizit say that the body-
tag has the font liberation (it's the font which normally can ŠŘšžě)
the output changes to:
"? ?˜???žÄ›"
(So there is ž! its 5% of the target ;) )
the entry of my font in the font_family_cache -file:
'liberation' =>
array (
'normal' => '/.../lib/fonts/LiberationSans-Regular',
'bold' => '/.../lib/fonts/LiberationSans-Bold',
'italic' => '/.../lib/fonts/LiberationSans-Italic',
'bold_italic' => '/.../lib/fonts/LiberationSans-BoldItalic',
),

so I don't think that there is the problem.

Shamharoth

unread,
Mar 25, 2010, 5:07:43 AM3/25/10
to dompdf
Now i installed a other ISO-8859-2 - font (a Times - Font) and the
problem still exists. Now when I generate a pdf with the second half
von the ISO table (the -2 spacific chars) the file has a lot of '?'
again ....
Now I added the mp_convert ... command again and thats the result:

html-code:
Ą˘Ł¤ĽŚ§¨ŠŞŤŹŽŻ°ą˛ł´ľśˇ<br>
¸šşťź˝žżŔÁÂĂÄĹĆÇČÉĘËĚÍ<br>
ÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâă<br>
äĺćçčéęëěíîďđňóôőö÷řůú<br>
űüýţ˙<br>

pdf-code:
???¤??§¨Š???Ž?°???´???
¸š????ž??ÁÂ?Ä??Ç?É?Ë?Í
Î????ÓÔ?Ö×??Ú?ÜÝ?ß?áâ?
ä??ç?é?ë?íî???óô?ö÷??ú
?üý??

So it would be the best way to use UTF-8, because the next weeks I
have to add the russian font, too.
What can I do to use all the ISO-8859-2 - chars?

BrianS

unread,
Mar 25, 2010, 7:46:08 AM3/25/10
to dompdf
On Mar 25, 4:15 am, Shamharoth <shamhar...@googlemail.com> wrote:
> Now I tried your code. At first when I edit DOMPDF_DEFAULT_FONT the
> font of the PDF doesn't change and when I explizit say that the body-
> tag has the font liberation (it's the font which normally can ŠŘšžě)
> the output changes to:
> "? ?˜???žÄ›"
> (So there is ž! its 5% of the target ;) )
> the entry of my font in the font_family_cache -file:
> 'liberation' =>
>   array (
>     'normal' => '/.../lib/fonts/LiberationSans-Regular',
>     'bold' => '/.../lib/fonts/LiberationSans-Bold',
>     'italic' => '/.../lib/fonts/LiberationSans-Italic',
>     'bold_italic' => '/.../lib/fonts/LiberationSans-BoldItalic',
>   ),
>
> so I don't think that there is the problem.

This path doesn't look to be quite right (e.g. it looks like it's
pointing to the system root then /lib/fonts). Your font and the *.afm/
*.ufm files should all go in your dompdf installation folder dompdf/
lib/fonts. You can then make the array entry look like this:

'liberation' =>
array (
'normal' => DOMPDF_FONT_DIR . 'LiberationSans-Regular',
'bold' => DOMPDF_FONT_DIR . ' LiberationSans-Bold',
'italic' => DOMPDF_FONT_DIR . ' LiberationSans-Italic',
'bold_italic' => DOMPDF_FONT_DIR . ' LiberationSans-BoldItalic'
)

Shamharoth

unread,
Mar 25, 2010, 11:51:58 AM3/25/10
to dompdf
thanks for all your answers! :)

this is strange, because I didn't changed the path by myself.
So I changed all entries to ...=>DOMPDF_FONT_DIR . '... but it's stil
not right.

There is a very strange thing to:
when I edit the defaut-font for example to courier and don't set a css-
style for
the body-tag, the font doesn't change to courier in the PDF.

And so on I think there domPDF doesn't use every entry of the
font_family_cache - file.
I copied 8 fonts (czech courier - reg, bold, italic and bolditalic
(.afm and .pfa)) into the /lib/fonts folder
and added this the font_family_cache:

'newcourier' =>
array (
'normal' => DOMPDF_FONT_DIR . 'Cour',
'bold' => DOMPDF_FONT_DIR . 'Courb',
'italic' => DOMPDF_FONT_DIR . 'Couri',
'bold_italic' => DOMPDF_FONT_DIR . 'Courbd',
),

But when I try to use the font for the body-tag (<style>body{....) the
pdf file has the
standardfont. Same font like I would delet the style-tag. ....

Some of the defines of my dompdf_config.inc.php:
...
define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/',
realpath(dirname(__FILE__))));
...
define("DOMPDF_FONT_DIR", DOMPDF_DIR . "/lib/fonts/");
...
define("DOMPDF_FONT_CACHE", DOMPDF_FONT_DIR);
...
define("DOMPDF_UNICODE_ENABLED", true);
...
define("DOMPDF_DEFAULT_PAPER_SIZE", "a4");
...
define("DOMPDF_DEFAULT_FONT", "courier");

BrianS

unread,
Mar 25, 2010, 2:51:59 PM3/25/10
to dompdf
On Mar 25, 11:51 am, Shamharoth <shamhar...@googlemail.com> wrote:
> thanks for all your answers! :)
>
> this is strange, because I didn't changed the path by myself.
> So I changed all entries to ...=>DOMPDF_FONT_DIR . '... but it's stil
> not right.

When you use the load_font.php script it updates your file with an
absolute path. I haven't seen it have any path problems when using the
script, but it's a possibility. If you didn't use the script then I'm
not sure why the entries were changes.

> There is a very strange thing to:
> when I edit the defaut-font for example to courier and don't set a css-
> style for
> the body-tag, the font doesn't change to courier in the PDF.
>
> And so on I think there domPDF doesn't use every entry of the
> font_family_cache - file.
> I copied 8 fonts (czech courier - reg, bold, italic and bolditalic
> (.afm and .pfa)) into the /lib/fonts folder
> and added this the font_family_cache:
>
>  'newcourier' =>
>   array (
>     'normal' => DOMPDF_FONT_DIR . 'Cour',
>     'bold' => DOMPDF_FONT_DIR . 'Courb',
>     'italic' => DOMPDF_FONT_DIR . 'Couri',
>     'bold_italic' => DOMPDF_FONT_DIR . 'Courbd',
>   ),
>
> But when I try to use the font for the body-tag (<style>body{....) the
> pdf file has the
> standardfont. Same font like I would delet the style-tag. ....

That is odd. I would expect that if you had no styles defined or font
tags that DOMPDF would use your default font. Can you post a sample
document?

> Some of the defines of my dompdf_config.inc.php:
> ...
> define("DOMPDF_DIR", str_replace(DIRECTORY_SEPARATOR, '/',
> realpath(dirname(__FILE__))));
> ...
> define("DOMPDF_FONT_DIR", DOMPDF_DIR . "/lib/fonts/");
> ...
> define("DOMPDF_FONT_CACHE", DOMPDF_FONT_DIR);
> ...
> define("DOMPDF_UNICODE_ENABLED", true);
> ...
> define("DOMPDF_DEFAULT_PAPER_SIZE", "a4");
> ...
> define("DOMPDF_DEFAULT_FONT", "courier");

These all look fine to me.

Shamharoth

unread,
Mar 26, 2010, 3:55:56 AM3/26/10
to dompdf
ok i used the load_font.php script to add a font.

Here the actual example:


require_once("dompdf_config.inc.php");
$html = '<html>
<head>
<meta http-equiv="Content-Type" content="text/
html;charset=ISO-8859-2" />

<style>
body{
font-family: newcourier;
}
</style>
</head>
<body>
<p>


Ą˘Ł¤ĽŚ§¨ŠŞŤŹŽŻ°ą˛ł´ľśˇ<br>
¸šşťź˝žżŔÁÂĂÄĹĆÇČÉĘËĚÍ<br>
ÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâă<br>
äĺćçčéęëěíîďđňóôőö÷řůú<br>
űüýţ˙<br>

The quick brown fox jumps over the lazy dog</p></body>
</html>';
$html = mb_convert_encoding($html, "iso-8859-2", "utf8");


$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("pdf_file.pdf");

But when I delete the <style> tag out of the example, the script will
not use the courier - font.

Message has been deleted

BrianS

unread,
Mar 26, 2010, 1:58:52 PM3/26/10
to dompdf
The following line is unnecessary. DOMPDF will handle the conversion
to UTF-8 internally:

$html = mb_convert_encoding($html, "iso-8859-2", "utf8");

Otherwise your script looks ok. Do you receive any error messages from
PHP, either when attempting to render your PDF or when you use the
load_font.php script?

Shamharoth

unread,
Mar 29, 2010, 3:13:35 AM3/29/10
to dompdf
There were only problems mith the magic_quotes function. Then I got a
warning that i should not use this function.
There is no warning or error while generating an afm-font. There are
only the messages that it copies the ttf-fonts into the font folder
and genartes the afm font.

Shamharoth

unread,
Apr 1, 2010, 2:48:45 AM4/1/10
to dompdf
Hi,

is there no solution for problem?

plz help

BrianS

unread,
Apr 13, 2010, 9:48:29 PM4/13/10
to dompdf

Have you had any more luck getting things to work?

Pavel Tyl

unread,
Apr 14, 2010, 10:28:33 AM4/14/10
to dompdf
I have absolutely the same problem as Shamharoth:
I have last version of DOMPDF 0-6-0_beta1, trying to get to work czech
fonts (áéěíóúůýžščřďťň), but without success. And also font family is
not correct even if I am using define("DOMPDF_DEFAULT_FONT", "arial");
I will always get some Serif :(
Any idea?

BrianS

unread,
Apr 16, 2010, 12:09:17 AM4/16/10
to dompdf
On Apr 14, 10:28 am, Pavel Tyl <pavel....@gmail.com> wrote:
> I have absolutely the same problem as Shamharoth:
> I have last version of DOMPDF 0-6-0_beta1, trying to get to work czech
> fonts (áéěíóúůýžščřďťň), but without success. And also font family is
> not correct even if I am using define("DOMPDF_DEFAULT_FONT", "arial");
> I will always get some Serif :(
> Any idea?

DOMPDF uses Windows ANSI encoding with the core fonts. Most of the
characters you specified aren't supported in this character set. You
would need to load your own font and enable Unicode. We hope to have
Unicode support enabled in the core fonts for the final release of
0.6.0.

Also, you would be better off using something like "sans-serif" for
your default font. Unless you have loaded arial it isn't available in
the default install of DOMPDF.


>
> On Apr 14, 3:48 am, BrianS <eclecticg...@gmail.com> wrote:
>
>
>
> > On Apr 1, 2:48 am, Shamharoth <shamhar...@googlemail.com> wrote:
>
> > > Hi,
>
> > > is there no solution for problem?
>
> > > plz help
>
> > Have you had any more luck getting things to work?

Pavel Tyl

unread,
Apr 17, 2010, 3:18:18 AM4/17/10
to dom...@googlegroups.com
So I tried to add two own fonts (DejaVu Serif and Sans by using
ttf2ufm). I dont know, where is the error, but I have:
* in my lib/fonts dir these files (I dont know if some extension is
missing (*.pfa...)?):
djvsan.afm djvser.afm
djvsan.ctg.z djvser.ctg.z
djvsan.php djvser.php
djvsan.t1a djvser.t1a
djvsan.ttf djvser.ttf
djvsan.ufm djvser.ufm
djvsan.z djvser.z
* unicode enabled
if (!defined("DOMPDF_UNICODE_ENABLED")) {
define("DOMPDF_UNICODE_ENABLED", true);
}
* default font
if (!defined("DOMPDF_DEFAULT_FONT")) {
define("DOMPDF_DEFAULT_FONT", "djvsan");
//define("DOMPDF_DEFAULT_FONT", "serif"); // orig.
}

Result is very strange (whole page full of letters, php arrays...), but
I can see the following:
TPhpErrorException Object ( [_errorCode:private] => [Notice] Undefined
index: djvsan (@line 176 in file
/home1/starttech/dompdf_0-6-0_beta1/include/font_metrics.cls.php).
[message:protected] => [Notice] Undefined index: djvsan (@line 176 in
file /home1/starttech/dompdf_0-6-0_beta1/include/font_metrics.cls.php).
. .. . . . .. . . . . .. . . .. .and so
on................................................................................

Now I think my problem is loading font correctly... I have read
http://www.digitaljunkies.ca/dompdf/install.php but with no success. I
dont know, if I have to use load_font.php and how? :-(
Regards
Pavel Tyl




BrianS napsal(a):

Pavel Tyl

unread,
Apr 17, 2010, 12:37:29 PM4/17/10
to dom...@googlegroups.com
So, I made djvsan fonts (normal, b, i, bi) using your web generation
tool, I suppose that it is the same like using load_font.php. I copied
all font files to my lib/fonts, set djvsan as default font and unicode
enabled in dompdf_config.inc.php.
catch(Exception $e) {
print_r($e);
}
produces following :(

TPhpErrorException Object ( [_errorCode:private] => [Notice] Undefined
index: (@line 2885 in file
/home1/starttech/dompdf_0-6-0_beta1/lib/class.pdf.php).
[message:protected] => [Notice] Undefined index: (@line 2885 in file
/home1/starttech/dompdf_0-6-0_beta1/lib/class.pdf.php). [string:private]
=> [code:protected] => 0 [file:protected] =>
/home1/starttech/prado-3.1.2.r2448/framework/PradoBase.php
[line:protected] => 131 [trace:private] => Array ( [0] => Array ( [file]
=> /home1/starttech/dompdf_0-6-0_beta1/lib/class.pdf.php [line] => 2885
[function] => phpErrorHandler [class] => PradoBase [type] => :: [args]
=> Array ( [0] => 8 [1] => Undefined index: [2] =>
/home1/starttech/dompdf_0-6-0_beta1/lib/class.pdf.php [3] => 2885 [4] =>
Array ( [size] => 12 ) ) ) [1] => Array ( [file] =>
/home1/starttech/dompdf_0-6-0_beta1/include/cpdf_adapter.cls.php [line]
=> 759 [function] => getFontHeight [class] => Cpdf [type] => -> [args]
=> Array ( [0] => 12 ) ) [2] => Array ( [file] =>
/home1/starttech/dompdf_0-6-0_beta1/include/font_metrics.cls.php [line]
=> 135 [function] => get_font_height [class] => CPDF_Adapter [type] =>
-> [args] => Array ( [0] =>
/home1/starttech/dompdf_0-6-0_beta1/lib/fonts/Times-Roman [1] => 12 ) )
[3] => Array ( [file] =>
/home1/starttech/dompdf_0-6-0_beta1/include/text_frame_reflower.cls.php
[line] => 185 [function] => get_font_height [class] => Font_Metrics
[type] => :: [args] => Array ( [0] =>
/home1/starttech/dompdf_0-6-0_beta1/lib/fonts/Times-Roman [1] => 12 ) )
[4] => Array ( [file] =>
/home1/starttech/dompdf_0-6-0_beta1/include/text_frame_reflower.cls.php
[line] => 332 [function] => _layout_line [class] => Text_Frame_Reflower
[type] => -> [args] => Array ( ) ) [5] => Array ( [file] =>
/home1/starttech/dompdf_0-6-0_beta1/include/frame_decorator.cls.php [l
...............................
AND SO ON.......

It shows the line 2885 in class.pdf.php
$h =
$this->fonts[$this->currentFont]['FontBBox'][3]-$this->fonts[$this->currentFont]['FontBBox'][1];

May I have incorrectly generated fonts?
Thank you for your answers, Brian.
Pavel

BrianS napsal(a):

BrianS

unread,
Apr 19, 2010, 4:12:06 PM4/19/10
to dompdf
First, did you rename the dompdf_font_family_cache.sample file to
dompdf_font_family_cache? Or copy the contents to your
dompdf_font_family_cache? Without this file set up correctly, DOMPDF
won't know that your font is installed.

Second, I wouldn't make djvsan your default. If everything is working
correctly this shouldn't be a problem, but it's safer, initially, to
leave something like "sans" as your default and to style your HTML
document to use the new font. That way if DOMPDF has a problem finding
the font it can fall back to something known.
> >> fonts (áéìíóúùý¾¹èøï»ò), but without success. And also font family is

Pavel Tyl

unread,
Apr 19, 2010, 5:20:35 PM4/19/10
to dom...@googlegroups.com
Hi,
my dompdf_font_family_cache file was OK. But there were several other
problems I found:
First of all - Web Generation Tool produced my font djvsan.ufm and
djvsan.afm with size 0 kB. Then I tried to use ttf2ufm that is attached
to dompdf (dompdf_0-6-0_beta1), but it always ends with win error and
program stops working. *.afm and *.ufm has 0 kB.
Btw. when I used fonts from CodilX
(http://dompdf.googlegroups.com/web/dompdf_fonts.zip?hl=en&gda=ZL9MT0IAAACN_9EbLIV3_bhkg1ItOESvqz7zj-RFyvWW8y6Vf1oQJsRIK7q3AYyqF65KDK8fIcFV4u3aa4iAIyYQIqbG9naPgh6o8ccLBvP6Chud5KMzIQ)
result was the best I have ever seen, but for example czech " ť " was
problem, also dash " - " displayed like some arabic character :-(

Therefore I found another (maybe older) version of ttf2ufm:
ttf2ufm.exe -a -O u djvsan.ttf
ttf2ufm.exe -a -O u djvsanb.ttf
ttf2ufm.exe -a -O u djvsani.ttf
ttf2ufm.exe -a -O u djvsanbi.ttf

Then I found makefontuni.php:
php -q makefontuni.php djvsan.ttf djvsan.ufm
php -q makefontuni.php djvsanb.ttf djvsanb.ufm
php -q makefontuni.php djvsani.ttf djvsani.ufm
php -q makefontuni.php djvsanbi.ttf djvsanbi.ufm

Then I copied fonts (*.ttf, *.afm, *.ufm, *.php, ) to lib/fonts
directory and modify dompdf_font_family_cache:
'djvsan' =>
array (
'normal' => DOMPDF_FONT_DIR . 'djvsan',
'bold' => DOMPDF_FONT_DIR . 'djvsanb',
'italic' => DOMPDF_FONT_DIR . 'djvsani',
'bold_italic' => DOMPDF_FONT_DIR . 'djvsanbi',
),

I made a control of settings in dompdf_config.inc.php:
if (!defined("DOMPDF_UNICODE_ENABLED")) {
define("DOMPDF_UNICODE_ENABLED", true);
}
if (!defined("DOMPDF_DEFAULT_FONT")) {
define("DOMPDF_DEFAULT_FONT", "djvsan");
}

And my code at the end:
// try {
$html = '<html>'.
'<head>'.
'</head>'.
'<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />'.
'<body style="font-family: \'djvsan\'">'.
'<h1>žščřďťň - áéíóúůý</h1>'.
'<p>žščřďťň - áéíóúůý / ŽŠČŘĎŤŇ - ÁÉÍÓÚŮÝ</p>'.
'</body>'.
'</html>';
$dompdf= new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream(str_replace('akce.','',$this->Page->PagePath) .
'Aktualni' . ".pdf", array("Attachment" => 1));
// }
// catch(Exception $e) {
// print_r($e);
// }

VICTORY! :-D
It works fine now.
Only one question I have - how to change font-family for dofferent
paragraphs?
<p style="font-family: \'djvser\'"><!--djvser = DejaVu Serif--></p>
produces some error...

Thank you Brian for your answers. Maybe you could add some comments.
Pavel Tyl

BrianS napsal(a):

BrianS

unread,
Apr 19, 2010, 11:56:54 PM4/19/10
to dompdf
Wow ... that was quite the effort to get this working. I'm glad it
worked out in the end.

Just a few comments:
-The web tool is still in an early development stage. the problems you
saw with the font from CodiIX are a result of some bugs we still need
to work out.

-The ttf2ufm program included with DOMPDF currently does not work
under Windows (as you have seen). I'm not sure when we'll be able to
address the issue.

-I tried Deja Vu Sans and ran into the same problem. I'll have to look
into the problem further.

-Your HTML looks ok. What errors do you see? Try it without the quotes
around djvser and see what happens.


On Apr 19, 5:20 pm, Pavel Tyl <pavel....@gmail.com> wrote:
> Hi,
> my dompdf_font_family_cache file was OK. But there were several other
> problems I found:
> First of all - Web Generation Tool produced my font djvsan.ufm and
> djvsan.afm with size 0 kB. Then I tried to use ttf2ufm that is attached
> to dompdf (dompdf_0-6-0_beta1), but it always ends with win error and
> program stops working. *.afm and *.ufm has 0 kB.
> Btw. when I used fonts from CodilX
> (http://dompdf.googlegroups.com/web/dompdf_fonts.zip?hl=en&gda=ZL9MT0I...)
> >> $this->fonts[$this->currentFont]['FontBBox'][3]-$this->fonts[$this->current Font]['FontBBox'][1];

Pavel Tyl

unread,
Apr 20, 2010, 4:14:31 AM4/20/10
to dom...@googlegroups.com
I see no errors with my HTML and you are right, quotes are needless with
one-word font name.
But with this code (removed style attribute from body tag):
// try {
$html = '<html>'.
'<head>'.
'</head>'.
'<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />'.
'<body>'.
'<h1>žščřďťň - áéíóúůý</h1>'.
'<p>žščřďťň - áéíóúůý / ŽŠČŘĎŤŇ - ÁÉÍÓÚŮÝ</p>'.
'</body>'.
'</html>';
$dompdf= new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream(str_replace('akce.','',$this->Page->PagePath) .
'Aktualni' . ".pdf", array("Attachment" => 1));
// }
// catch(Exception $e) {
// print_r($e);
// }

I got this error:
[Notice] Undefined index: (@line 2885 in file
/home1/starttech/dompdf_0-6-0_beta1/lib/class.pdf.php).

It is this line (seems like I have no default font even if I set it up
in dompdf_config.inc.php):
$h =
$this->fonts[$this->currentFont]['FontBBox'][3]-$this->fonts[$this->currentFont]['FontBBox'][1];

So I am able to set up the font only at the beggining of html in body
tag. No later change (ie. in p tag) takes effect.
Any idea?

BrianS napsal(a):

Pavel Tyl

unread,
Apr 20, 2010, 5:35:45 AM4/20/10
to dom...@googlegroups.com
So, now I see that font change in p tag is OK, my fault. But I dont know
how to use default font without using style tag.
Pavel Tyl

BrianS napsal(a):

BrianS

unread,
Apr 23, 2010, 8:36:33 PM4/23/10
to dompdf
Is this with your default font still set to djvsan? If so, do the
errors go away when you use just sans?

xarp

unread,
May 9, 2010, 7:07:25 AM5/9/10
to dompdf
Hi Pavel,

congrats to your victory! ;o) Btw do you think you could upload the
successfully generated "Czech" fonts, so it would save time to others?
You can just include all the fonts you have generated, I guess you
were doing some basic ones too, like Arial, Helvetica, Times..

Thanks!

xarp


On Apr 19, 11:20 pm, Pavel Tyl <pavel....@gmail.com> wrote:
> Hi,
> my dompdf_font_family_cache file was OK. But there were several other
> problems I found:
> First of all - Web Generation Tool produced my font djvsan.ufm and
> djvsan.afm with size 0 kB. Then I tried to use ttf2ufm that is attached
> to dompdf (dompdf_0-6-0_beta1), but it always ends with win error and
> program stops working. *.afm and *.ufm has 0 kB.
> Btw. when I usedfontsfrom CodilX
> (http://dompdf.googlegroups.com/web/dompdf_fonts.zip?hl=en&gda=ZL9MT0I...)
> result was the best I have ever seen, but for exampleczech" ť " was
> problem, also dash " - " displayed like some arabic character :-(
>
> Therefore I found another (maybe older) version of ttf2ufm:
> ttf2ufm.exe -a -O u djvsan.ttf
> ttf2ufm.exe -a -O u djvsanb.ttf
> ttf2ufm.exe -a -O u djvsani.ttf
> ttf2ufm.exe -a -O u djvsanbi.ttf
>
> Then I found makefontuni.php:
> php -q makefontuni.php djvsan.ttf djvsan.ufm
> php -q makefontuni.php djvsanb.ttf djvsanb.ufm
> php -q makefontuni.php djvsani.ttf djvsani.ufm
> php -q makefontuni.php djvsanbi.ttf djvsanbi.ufm
>
> Then I copiedfonts(*.ttf, *.afm, *.ufm, *.php, ) to lib/fonts
> >> So, I made djvsanfonts(normal, b, i, bi) using your web generation
> >>>>fonts(áéìíóúùý¾¹èøï»ò), but without success. And also font family is
> >>>> not correct even if I am using define("DOMPDF_DEFAULT_FONT", "arial");
> >>>> I will always get some Serif :(
> >>>> Any idea?
>
> >>> DOMPDF uses Windows ANSI encoding with the corefonts. Most of the
> >>> characters you specified aren't supported in this character set. You
> >>> would need to load your own font and enable Unicode. We hope to have
> >>> Unicode support enabled in the corefontsfor the final release of

Pavel Tyl

unread,
May 12, 2010, 2:24:34 PM5/12/10
to dom...@googlegroups.com
Hello,
as I wrote to Brian, my fonts dir contain currently only czech UTF
DejaVu fonts. I've already uploaded them:
http://groups.google.com/group/dompdf/web/DejaVu-Czech-UTF8.zip
I hope, it will help somebody. Maybe I will need some other fonts and
then I prepare them. But I think I will certainly make no non-free fonts
as Arial etc.
Pavel

xarp napsal(a):

Pavel Tyl

unread,
May 12, 2010, 2:06:52 PM5/12/10
to dom...@googlegroups.com
Hello,
I did not make further experiments with fonts, because I have not enough
time for my project with DOMPDF included. I hope I will continue soon.
But there is no other font than DejaVu in my font dir now and I am
satisfied :)
Pavel

BrianS napsal(a):
Reply all
Reply to author
Forward
0 new messages