Reputation: 347
So i am having difficulties trying to generate pdf from URL using mpdf code :
<form action="generate.php" method="POST">
url: <input type="text" name="url"><br>
<input type="submit">
</form>
generate.php:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$url = test_input($_POST["url"]);
$pdf=file_get_contents($url);
include('mpdf60/mpdf.php');
$mpdf=new mPDF();
$mpdf->debug = true;
$mpdf->WriteHTML($pdf);
$mpdf->Output();
exit;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
Returns no errors , just blank pdf page .
Upvotes: 2
Views: 4631
Reputation: 428
I got same problem with mPDF 5.6. When I used xdebug I found these 2 lines:
$str = @preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
$str = @preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
As you can see there is "@" char that blocking errors output. So if you have php >=7.0 you will never get error about "e" modifier that was deprecated. So all your HTML will be NULL after these lines.
I updated this function:
// mpdf/includes/functions.php
if (!function_exists('strcode2utf')) {
function strcode2utf($str,$lo=true)
{
//converts all the &#nnn; and &#xhhh; in a string to Unicode
if ($lo) { $lo = 1; } else { $lo = 0; }
// Deprecated modifier "E" in preg_replace
//$str = @preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str); // blocked errors output!! wtf?
//$str = @preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
$str = preg_replace_callback('/\&\#([0-9]+)\;/m',
function($num) use ($lo) {
return code2utf($num, $lo);
}, $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m',
function($num) use ($lo) {
return codeHex2utf($num, $lo);
}, $str);
return $str;
}
}
Upvotes: 4
Reputation: 372
Yo haven't specified much about the url input that is being given.I hope the url is pointing to the same server.Else mpdf will show error
There is nothing wrong with your code.Please check for any file permission issue.
Upvotes: 0