mpdf生成空白页面

时间:2016-01-20 17:28:29

标签: php mpdf

所以我很难尝试使用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 个答案:

答案 0 :(得分:3)

我遇到了与mPDF 5.6相同的问题。当我使用xdebug时,我找到了这两行:

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

正如你所看到的,&#34; @&#34;阻止错误输出的char。因此,如果你有php&gt; = 7.0,你将永远不会得到关于&#34; e&#34;已弃用的修饰符。因此,在这些行之后,所有HTML都将为NULL。

我更新了这个功能:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_margin="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <SeekBar
        android:id="@+id/seekBar"
        android:max="100"
        android:progress="50"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

答案 1 :(得分:0)

哟没有详细说明正在给出的url输入。我希望url指向同一个服务器.Ell这个mpdf会显示错误

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

相关问题