DomPDF with unicode support

5,761 views
Skip to first unread message

T R Modi

unread,
May 20, 2011, 7:12:55 AM5/20/11
to dompdf
Hello sir,
Dompdf Unicode (UTF-8) test example is not working properly with the
Chinese or Arabic font.

I want to display Chinese and english char in the pdf.
Could you please provide me some sample for the generating the pdf
with Chinese.

Thanks you.

BrianS

unread,
May 26, 2011, 2:48:59 PM5/26/11
to dom...@googlegroups.com
Please take a look at the just-posted guide to enabling Unicode support in DOMPDF and see if that helps.

T R Modi

unread,
May 27, 2011, 6:28:08 AM5/27/11
to dompdf
Thanks for your answer.

I achieved this using droidsansfallback font.

the web based font tool http://eclecticgeek.com/dompdf/load_font.php
is not working with large size of unicode font.
I tried with CyberCJK, Cyberbase or cyberbit font, but it is unable
to generate these fonts.

I have a another questions as well.
The unicode support pdf word-wrap is not working properly,

Could you please pass me the created font files for above fonts and if
the word-wrap issue issue is solved it will be really great-full.

Thanks.

On May 26, 11:48 pm, BrianS <eclecticg...@gmail.com> wrote:
> Please take a look at the just-posted guide to enabling Unicode support in
> DOMPDF <http://code.google.com/p/dompdf/wiki/CPDFUnicode> and see if that
> helps.

BrianS

unread,
May 27, 2011, 2:09:39 PM5/27/11
to dom...@googlegroups.com
I had to update some of the server settings for the web-based font prep tool. Can you try again, using the PHP-based font parser?

T R Modi

unread,
May 30, 2011, 4:20:54 AM5/30/11
to dompdf
Thanks a lot,
Now I am able to generate the above fonts but still the arialunicode
font is not generating.

I word-wrap is not working while using unicode font.

My code is as fallow

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Rights Catalog</title>
<style>
body {
padding-top: 7em;
padding-bottom: 3em;
margin: 0;
font-family:'lucida-sans', monospace;
width:100%;
line-height:15px;
}

div.header,
div.footer {
position: fixed;
opacity: 0.9;
border: 0px solid #888;
width: 100%;
overflow:hidden;

}

div.header {
top: 0cm;
}

div.footer {
bottom: 0cm;
border-top-width: 1px;
height: 2em;
}

div.footer table {
width: 100%;
text-align: center;
}

@media print {
div.header,
div.footer {
opacity: 1;
background: #fff;
}
hr {
page-break-after: always;
visibility: hidden;
}
}

@media screen {
div.body {
border-bottom: 1px dotted #888;
}
}
p
{
padding:0px;margin:0px;
}

div,p,td
{
font-size:11px;
}

img{ border:0px;}
#wrap{width:100%;}
#top{ width:100%;margin:0px auto;}
#bookstudio{ width:136px;float:left;}
.top_content_wrap{ width:100%; float:left; }
.top_content_center{
background:#ecf6f9;;
width:100%;
color:#000000;;
text-align:left; font-weight:normal;
border:1px solid #bebebe; ;
padding:2px;
}
.top_content_center h1{
font-family:'lucida-sans', monospace;
font-weight:bold;
font-size:12px;
color:#ba7b00;;
padding-bottom:10px;
}
.main_content_wrap{
width:100%;
float:left;
font-family:'lucida-sans', monospace;
background:#ecf6f9;;
color:#000000;;
text-align:left;
font-weight:normal;
border-right:1px solid #bebebe; ;
border-bottom:1px solid #bebebe; ;
border-top:0px;
border-left:0px;
}

.main_content_wrap h1{
font-family:'lucida-sans', monospace;
font-weight:bold;
font-size:13px;
color:#ba7b00;;
padding:0px;
margin:2px;
}
.b1_image{padding:3px;}
.b2_image{padding:3px;}
</style>
</head>
<body>
<div id="wrap">
<div class="top_content_center" style="font-
family:cyberbit"><h1>test</h1>
<p style="font-family:cyberbit">testtesttesttest</p>
</div>
<br clear="all">
<br>
<div class="main_content_wrap">
<table border="0" width="100%" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td width="33%" style="border-left:1px solid #bebebe; ;
border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/4327394173.01.SCTHUMBZZZ_.jpg"
width="110"></div>
</td>
<td
valign="top">

<h1>เดินสู่อิสรภาพ</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>Pramuan Pengchan<br>
<strong>Book Category:</strong> RELIGION &gt; General, SELF-
HELP &gt; General, TRAVEL &gt; Gen<br>

<strong>ISBN:</strong>9789744098436<br>
<strong>Publication
Year:</strong>

2007 <br>

<strong>Number of Pages:</strong>300 +<br>
<strong>All Print
Rights Available EXCEPT:</strong> Thailand
China
Taiwan<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
National Best Book Award in Non-Fiction 2008
JUDPRAKAI Award 2008, Distinguished Documentary Award.
The Fourth “Seven Book Awards”, Best Book
Awar... </p>
</td>
</tr>
</tbody></table>
</td>
<td width="33%" style="border-left:1px solid #bebebe; ;
border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/4327394173.01.SCTHUMBZZZ_.jpg"
width="110"></div>
</td>
<td
valign="top">

<h1>レストラン・お店で使う 英中韓3か国語きほん接客フレーズ</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>니시가게히로고 (西蔭浩子)<br>
<strong>Book Category:</strong> FOREIGN LANGUAGE STUDY &gt;
General, LANGUAGE ARTS &amp; DISCIPLINES &gt; Linguistics &gt;
Gen<br>

<strong>ISBN:</strong>9784327394172<br>
<strong>Publication
Year:</strong>

2010 <br>

<strong>Number of Pages:</strong>200 - 300<br>
<strong>All Print
Rights Available EXCEPT:</strong> Japan
Taiwan
China<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
シンプルフレーズで、おもてなしの心を届ける

お店やデパート、レストラン、駅、銀行、案内所などで使える...
</p>
</td>
</tr>
</tbody></table>
</td>
<td width="33%" style="border-left:1px solid #bebebe; ;
border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/402330395X.01.SCTHUMBZZZ_.jpg"
width="110"></div>
</td>
<td
valign="top">

<h1>もうひとつの国へ</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>森山 大道<br>
<strong>Book Category:</strong> ART &gt; General, DESIGN
&gt; General, PHOTOGRAPHY &gt; Gen<br>

<strong>ISBN:</strong>9784023303959<br>
<strong>Publication
Year:</strong>

2008 <br>

<strong>Number of Pages:</strong>300 +<br>
<strong>All Print
Rights Available EXCEPT:</strong> Japan
Taiwan
China<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
日本攝影三大巨擘森山大道最新親筆著作
收錄近年來多幅未發表的攝影作品,以及經典散文

「對我而言,所謂藝... </p>
</td>
</tr>
</tbody></table>
</td>
</tr><tr> <td width="33%" style="border-left:1px solid
#bebebe; ; border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/4391622580.01.SCTHUMBZZZ_.jpg"
width="110"></div>
</td>
<td
valign="top">

<h1>はじめてのミシンソ-イング ― LESSON OF SEWING</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>主婦と生活社 <br>
<strong>Book Category:</strong> REFERENCE &gt; Gen<br>

<strong>ISBN:</strong>9784391622584<br>
<strong>Publication
Year:</strong>

2006 <br>

<strong>Number of Pages:</strong>0 - 100<br>
<strong>All Print
Rights Available EXCEPT:</strong> Japan
Taiwan<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
縫紉機就是「sewing machine=縫紉的機器」,雖然簡單地被稱作是縫紉機,但依用途又分成幾種類別。在此就縫紉
機... </p>
</td>
</tr>
</tbody></table>
</td>
<td width="33%" style="border-left:1px solid #bebebe; ;
border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/483992998X.01.SCTHUMBZZZ_.jpg"
width="110"></div>
</td>
<td
valign="top">

<h1>かわいい手製本―童話をテーマに自分らしく作る本とかたち</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>水野 真帆<br>
<strong>Book Category:</strong> ART &gt; General, CRAFTS
&amp; HOBBIES &gt; General, DESIGN &gt; Gen<br>

<strong>ISBN:</strong>9784839929985<br>
<strong>Publication
Year:</strong>

2009 <br>

<strong>Number of Pages:</strong>0 - 100<br>
<strong>All Print
Rights Available EXCEPT:</strong> Japan
Taiwan<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
手工書的準備

1關於手工書的步驟和構造

以下,將先說明本書中有關手工書的作法。
此外,還要請你先了解書... </p>
</td>
</tr>
</tbody></table>
</td>
<td width="33%" style="border-left:1px solid #bebebe; ;
border-top:1px solid #bebebe; ;" valign="top">
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tbody><tr>
<td align="left" valign="top"
style="width:115px;">
<div class="b1_image"><img
src="http://images.amazon.com/images/P/
4327394181.01.SCTHUMBZZZ_.jpg"width="110"></div>
</td>
<td
valign="top">

<h1>ホテル・旅館で使う  英中韓3か国語きほん接客フレーズ</h1>

<p style="font-family:cyberbit">
<strong>Author:</
strong>니시가게히로고 (西蔭浩子)<br>
<strong>Book Category:</strong> FOREIGN LANGUAGE STUDY &gt;
General, LANGUAGE ARTS &amp; DISCIPLINES &gt; Linguistics &gt;
Gen<br>

<strong>ISBN:</strong>9784327394189<br>
<strong>Publication
Year:</strong>

2010 <br>

<strong>Number of Pages:</strong>100 - 200<br>
<strong>All Print
Rights Available EXCEPT:</strong> Japan
Taiwan
China<br>
</p>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<p style="font-
family:cyberbit">
シンプルフレーズで、おもてなしの心を届ける

ホテルや旅館、スキー場、ゴルフ場、温泉施設、案内所などで...
</p>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</div>

</div>

<script type="text/php">
if ( isset($pdf) ) {

$font = Font_Metrics::get_font("helvetica");;
$size = 6;
$color = array(0,0,0);
$text_height = Font_Metrics::get_font_height($font, $size);

$foot = $pdf->open_object();

$w = $pdf->get_width();
$h = $pdf->get_height();

// Draw a line along the bottom
$y = $h - 2 * $text_height - 24;
$pdf->line(16, $y, $w - 16, $y, $color, 1);

$y += $text_height;

$text = "Powered By: www.PubMatch.com";
$pdf->page_text(16, $y, $text, $font, $size, $color);

$pdf->close_object();

$text = "Page {PAGE_NUM} of {PAGE_COUNT}";

// Center the text
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size,
$color);


}
</script>

</body></html>

I need all text should be wrapped in the TD tag.

Could you please provide me a solution or patch for this.

Thanks once again.

BrianS

unread,
May 30, 2011, 10:47:13 PM5/30/11
to dom...@googlegroups.com
First, always better to post your HTML as an attachment or link to external document. Otherwise the code may get mangled.

When you say arialunicode is not generating, do you mean using the web-based font prep tool? If so I'll take a look. It could be that that font is just too large for my system to handle (my server is on a shared host so resources are limited, but I can test it out locally without such limits).

Does the document render acceptably other than the word wrap problem?
Message has been deleted

Trilokchand Modi

unread,
May 31, 2011, 3:31:46 AM5/31/11
to dom...@googlegroups.com, eclect...@gmail.com
Please find the attched html and image for the word wrap issue.

Html document rendered properly other than the word wrap problem.

Please help me out to solve this issue.
--

Thanks & Kind Regards,
Trilokchand Modi

testwrap.html
word-wrap issue.PNG

T R Modi

unread,
May 31, 2011, 3:39:48 AM5/31/11
to dompdf
Thanks for your answer.

I posted html and a screen-shot of pdf for your reference.

The third td is not coming in the pdf because of the wrapping issue.
if I use normal font with english language it works fine, but with
unicode font wordwrap is not working.

arialunicode font is not generating using web-based font tool may be
its beacuse of limitation of the server.

Thanks once again.

T R Modi

unread,
Jun 2, 2011, 8:27:16 AM6/2/11
to dompdf
Hello Brian,

http://code.google.com/p/dompdf/source/detail?r=391

CSS word-wrap is working in latest trunk(
http://www.eclecticgeek.com/dompdf/nightly.php?format=zip).

But it throwing an error while the pdf is large.

can you please provide me the list of the files need to be change for
support css word-wrap.
if I updated these two files then it through and error

Fatal error: Call to undefined method
Block_Frame_Decorator::get_current_line_box() in
text_frame_reflower.cls.php on line 79

Please suggest me

Thanks

BrianS

unread,
Jun 2, 2011, 10:38:43 AM6/2/11
to dom...@googlegroups.com
There have already been a number of changes since the last beta. It's best if you can use the nightly release. If not then you might have to wait until the next release. However, the modifications made to support the word wrap styling were fairly minor and could maybe be easily back-ported if necessary.

BrianS

unread,
Jun 7, 2011, 2:13:22 PM6/7/11
to dom...@googlegroups.com, eclect...@gmail.com
I've taken a closer look at your document and I'm not sure what the optimal solution is. The testwrap.html document is slightly different from your example, so I can't say for certain, but the overall problem appears to be the fact that DOMPDF doesn't know where to break the text.

Additionally, because your text is in tables it gives DOMPDF a bit of a hard time since a table cell will expand to contain the widest content.

You might be able to solve the problem by modifying the characters DOMPDF looks for when determining line breaks or by using an inline element (e.g. <wbr>) where a line could be split.
Reply all
Reply to author
Forward
0 new messages