Drugi parametr w funkcji load_html w oryginalnej wersji nie był w ogóle używany.
Podmień sobie ten fragment w pliku include/dompdf.cls.php
function load_html($str, $encoding = FALSE, $auto_detect = TRUE) {
$this->save_locale();
// FIXME: Determine character encoding, switch to UTF8, update meta tag. Need better http/file stream encoding detection, currently relies on text or meta tag.
mb_detect_order('auto');
if ($encoding === FALSE && $auto_detect === TRUE) {
$_encoding = strtoupper(mb_detect_encoding
($str)); } else if ($encoding !== FALSE) {
}
'@<meta\s+http-equiv="Content-Type"\s+content="(?:[\w/\+]+)(?:;\s*?charset=([^\s"]+))?@i',
'@<meta\s+content="(?:[\w/\+]+)(?:;\s*?charset=([^\s"]+))"?\s+http-equiv="Content-Type"@i',
'@<meta [^>]*charset\s*=\s*["\']?\s*([^"\' ]+)@i',
);
foreach($metatags as $metatag) {
}
if (isset($matches[1
])) { } else {
$_encoding = 'UTF-8';
}
} else {
if (isset($matches[1
])) { } else {
$_encoding = 'auto';
}
}
if (isset($matches[1
])) { $str = preg_replace('/charset=([^\s"]+)/i', 'charset=UTF-8', $str); } else {
$str = str_replace('<head>', '<head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">', $str); }
}
if ($_encoding !== 'UTF-8') {
if ($_encoding == 'WINDOWS-1250') {
$str = iconv('UTF-8', $_encoding, $str);
$str = strtr($str, $this->_PL_WIN_SPECIFIC
, $this->_PL_ISO_SPECIFIC
); } else {
$str = mb_convert_encoding($str, 'UTF-8', $_encoding);
}
}
// remove BOM mark from UTF-8, it's treated as document text by DOMDocument
// FIXME: roll this into the encoding detection using UTF-8/16/32 BOM (http://us2.php.net/manual/en/function.mb-detect-encoding.php#91051)?
if (substr($str, 0
, 3
) == chr
(0xEF
).chr
(0xBB
).chr
(0xBF
)) { }
// Parse embedded php, first-pass
if ( DOMPDF_ENABLE_PHP ) {
}
// if the document contains non utf-8 with a utf-8 meta tag chars and was
// detected as utf-8 by mbstring, problems could happen.
if ( $_encoding !== 'UTF-8' ) {
$re = '/<meta ([^>]*)((?:charset=[^"\' ]+)([^>]*)|(?:charset=["\'][^"\' ]+["\']))([^>]*)>/i';
}
Na początku dodaj do klasy
private $_PL_WIN_SPECIFIC = "\xa5\x8c\x8f";
private $_PL_ISO_SPECIFIC = "\xa1\xa6\xac";
Wywołujesz to:
load_html($zmienna_z_tekstem, 'windows-1250');
$auto_detect jest dla moich potrzeb, więc możesz to zignorować.
Z htmla, który wrzucasz do funkcji najlepiej wywal "charset="
Całość ma być w UTF-8.
Być może będziesz musiał też podmienić class.pdf.php na ten, o którym tutaj mowa:
http://bukox.pl/php/dompdf-i-polskie-znakie/U mnie działa to i na Unixowych systemach i pod Windowsem.
Jeżeli chcesz używać skryptów PHP wewnętrznie i generować z nich polskie znaki, to musisz jeszcze zamienić w pliku include/php_evaluator.cls.php
z
eval(utf8_decode
($code));
na