首页 文章

mpdf生成空白页面

提问于
浏览
1

所以我在尝试使用mpdf代码从URL生成pdf时遇到困难:

<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;
 }
 ?>

返回没有错误,只是空白的pdf页面 .

2 回答

  • 3

    哟没有详细说明正在给出的url输入 . 我希望url指向同一个server.Else mpdf会显示错误

    您的代码没有任何问题 . 请检查是否存在任何文件权限问题 .

  • 0

    我对mPDF 5.6有同样的问题 . 当我使用xdebug时,我找到了这两行:

    $str = @preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
    $str = @preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
    

    正如您所看到的那样,“@”char阻止错误输出 . 因此,如果你有php> = 7.0,你永远不会得到关于弃用的“e”修饰符的错误 . 因此,在这些行之后,所有HTML都将为NULL .

    我更新了这个功能:

    // 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;
        }
    }
    

相关问题