@Kristalin As I had problems with swedish characters åäö
I solved it with utf8_decode() have you tried that?
$pagetitle = utf8_decode($goGet['pagetitle']);
As for security I changed getValue to $modx->getDocumentObject()
and some more tricks:
Replace images with (image)
and whats inside of <!--NOPDF--> ... <!--NOPDF--> with (video) in my case
My snippet inside MODx:
<?php
if(isset($_GET['makepdf'])) {
$makepdf = $modx->documentObject['id'];
require_once($modx->config['base_path'] .'myfolder/html2pdf/html2fpdf.php');
require_once($modx->config['base_path'] .'myfolder/html2pdf/sanitize.php');
$goGet = $modx->getDocumentObject('id',$makepdf);
$pagetitle = utf8_decode($goGet['pagetitle']);
$introtext = utf8_decode($goGet['introtext']);
$content = utf8_decode($goGet['content']);
$content2 = preg_replace("/<img[^>]+\>/i", "(image)", $content);
$content3 = preg_replace('#<!--NOPDF-->[^>]*>.*?<!--NOPDF-->#si', '(video)', $content2);
$pdf=new HTML2FPDF();
$pdf->AddPage();
$strContent = '
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>'.$pagetitle.' | My Site Name</title>
</head>
<body>
<strong>'.$pagetitle.' | My Site Name | '.$introtext.'</strong><br /><br />
'.$content3.'
</body>
</html>
';
$pdf_title = sanitize_paranoid_string($pagetitle) . '.pdf';
$pdf->WriteHTML($strContent);
$pdf->Output($pdf_title);
//echo "PDF file is generated successfully!";
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.$pagetitle.'.pdf"');
readfile($pdf_title);
unlink($pdf_title);
}
else {
return;
}
?>
after $strContent = it should be a: ’
I can’t see it there?¿