If in your documents you use the so called extended ASCII characters, those with a code >= 128 and try to make a PDF print using DOMPDF, and you like to have your document justified, you are in trouble. There seems to be a problem right now with this combination. At least when you want to stick with the open source PDF rendering engine, R&OS CPDF.
The problem is that non only you cannot produce a decent justification, but your text can easly span beyond the border of the paper. This is also true for table cells, where text can flow over the next cell.
This seems to derive from an incorrect mapping between the extended characters and the numbering used by the AFM file. The problem is described in the R&OS CPDF FAQ along with a possible workaround.
Following the workaround proposed in the FAQ, I have tried to make it work under DOMPDF. The workaround says to add a second argument to the selectFont() method that specifies the correct mapping. A grep shows that there are 4 occurrences of this call, in the following files: cpdf_adapter.cls.php and page_cache.cls.php. I therefore proceeded to make the following change, from
$this->_pdf->selectFont($font);
to
$this->_pdf->selectFont($font,
array('encoding'=>'WinAnsiEncoding',
'differences'=>self::$diff));
Once I have written down the mapping, it worked well in the test that I have done. So what is the mapping? Here it is:
static $diff = array (
130 => 'quotesinglbase',
131 => 'florin',
132 => 'quotedblright',
133 => 'ellipsis',
134 => 'dagger',
135 => 'daggerdbl',
136 => 'circumflex',
137 => 'perthousand',
// 138 => '{Underscore}',
139 => 'guilsinglleft',
140 => 'OE',
145 => 'quoteleft',
146 => 'quoteright',
147 => 'quotedblleft',
148 => 'quotedblright',
149 => 'bullet',
150 => 'endash',
151 => 'emdash',
152 => 'tilde',
153 => 'trademark',
// 154 => '{Underscore}',
155 => 'guilsinglright',
156 => 'oe',
159 => 'Ydieresis',
// 160 => '{Nonbreaking space}',
161 => 'exclamdown',
162 => 'cent',
163 => 'sterling',
164 => 'currency',
165 => 'yen',
166 => 'brokenbar',
167 => 'section',
168 => 'dieresis',
169 => 'copyright',
170 => 'ordfeminine',
171 => 'guillemotleft',
172 => 'logicalnot',
// 173 => '{Soft hyphen}',
174 => 'registered',
175 => 'macron',
176 => 'degree',
177 => 'plusminus',
178 => 'twosuperior',
179 => 'threesuperior',
180 => 'acute',
181 => 'mu',
182 => 'paragraph',
183 => 'periodcentered',
184 => 'cedilla',
185 => 'onesuperior',
186 => 'ordmasculine',
187 => 'guillemotright',
188 => 'onequarter',
189 => 'onehalf',
190 => 'threequarters',
191 => 'questiondown',
192 => 'Agrave',
193 => 'Aacute',
194 => 'Acircumflex',
195 => 'Atilde',
196 => 'Adieresis',
197 => 'Aring',
198 => 'AE',
199 => 'Ccedilla',
200 => 'Egrave',
201 => 'Eacute',
202 => 'Ecircumflex',
203 => 'Edieresis',
204 => 'Igrave',
205 => 'Iacute',
206 => 'Icircumflex',
207 => 'Idieresis',
208 => 'Eth',
209 => 'Ntilde',
210 => 'Ograve',
211 => 'Oacute',
212 => 'Ocircumflex',
213 => 'Otilde',
214 => 'Odieresis',
215 => 'multiply',
216 => 'Oslash',
217 => 'Ugrave',
218 => 'Uacute',
219 => 'Ucircumflex',
220 => 'Udieresis',
221 => 'Yacute',
222 => 'Thorn',
223 => 'germandbls',
224 => 'agrave',
225 => 'aacute',
226 => 'acircumflex',
227 => 'atilde',
228 => 'adieresis',
229 => 'aring',
230 => 'ae',
231 => 'ccedilla',
232 => 'egrave',
233 => 'eacute',
234 => 'ecircumflex',
235 => 'edieresis',
236 => 'igrave',
237 => 'iacute',
238 => 'icircumflex',
239 => 'idieresis',
240 => 'eth',
241 => 'ntilde',
242 => 'ograve',
243 => 'oacute',
244 => 'ocircumflex',
245 => 'otilde',
246 => 'odieresis',
247 => 'divide',
248 => 'oslash',
249 => 'ugrave',
250 => 'uacute',
251 => 'ucircumflex',
252 => 'udieresis',
253 => 'yacute',
254 => 'thorn',
255 => 'ydieresis'
);

Very good.
I’m using this help in 0.5.3 (in Brazil) and it’s works.
Thanks
Hello!
I’ve been reading your post “Printing with DOMPDF” and I found it very usefull.
Otherwise, the part wich really interests me in is this one (DOMPDF + justification + extended ASCII chars), but I can’t manage it to work.
What I do is:
Open cpdf_adapter.cls.php, replace
$this->_pdf->selectFont($font);
with
$this->_pdf->selectFont($font,
array(’encoding’=>’WinAnsiEncoding’,
‘differences’=>self::$diff));
and add your $diff array at the begining of the same document.
Then I try to do the same in page_cache.cls.php, but I can’t find the line $this->_pdf->selectFont($font);.
What am I missing?
Please please please, help me! Your help will be trully apreciated!
Thanks in advance!
hello,
on which version did you do that?
I tried with v0.5.2, the latest release, and it does not work.
any idea?
Best regards
@rod
Version 0.5.1 (http://dompdf.googlecode.com/files/dompdf-0.5.1.zip)
I haven’t tried it yet, but there is an upcoming new version, which is still in alpha, that might solve this problem. Look at http://code.google.com/p/dompdf/downloads/list
Cheers
I tried with v0.6.0 alpha 2 and it’s working very good!
Luca, the alpha don’t resolve this!