mpdf:如何生成包含大页面的mpdf的pdf文件

时间:2018-03-13 11:23:49

标签: php browser fpdf mpdf

我试图使用mpdf生成pdf文件。它包含超过50000页。问题是浏览器可以处理并显示pdf文件,当它有2000页时但是当我试图生成更多时,浏览器没有响应,最后,它显示max_execution_time虽然我将max_execution_time 30增加到300表单php.ini文件,但所有错误。

这是我的mpdf代码......

<?php
// header('Content-type: application/force-download');
// header("Content-type:application/pdf");
ini_set("memory_limit","128M");
ob_start();


include("fpdf/mpdf/mpdf.php");
// $mpdf=new mPDF('mm','array(140,215)',14,'nikosh'); 
$mpdf = new mPDF('0',array(280,216),12,'nikosh',3,3,'L'); 
$mpdf->SetTopMargin(0);
$mpdf->SetRightMargin(0);
$mpdf->useSubstitutions = false;
$mpdf->simpleTables = true;
$stylesheet = file_get_contents('style.css');

$html='
<div style="display:inline-table">
<div style="float:right;width:48.5%;">
<p style="margin-left:55mm;margin-bottom:0mm;padding-bottom:0mm;font-size:8mm;float:left;"> যশোর  <span class="hide">পৌরসভা </span>   </p>
<div style="margin-left:48mm;margin-top:0mm;padding-top :0mm;"><span style="width:20mm;">পৌরকরের বিল</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin-left:50mm;margin-bottom:-10mm;font-size:4mm"> অর্থ বছরঃ   </span></div> 
<div style="margin-left:48mm;margin-top:0mm;padding-top :0mm;"><span style="width:20mm;color:red;">পৌরসভার কপি </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin-left:50mm;margin-bottom:-10mm;font-size:4mm"> কিস্তিঃ   </span></div> 

<div class="all_o_i">
        <p  class="o_in">হোল্ডিং নং &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;: ৩৮৯৪-৩৪৩ </p>
        <p  class="o_in">কর দাতার আই ডি &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
        <p  class="o_in">করদাতার নাম &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
        <p  class="o_in">রাস্তা/মৌজা/এলাকা/মহল্লা &nbsp;: </p>
        <p  class="o_in">বিলের ঠিকানা &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </p>
        <p  class="o_in">বিল ইস্যুর তারিখ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </p>
        <p class="o_in" style="color:red">জমাদানের শেষ তারিখ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
    </div>
</div>
<div style="float:left;width:48.5%;">
<p style="margin-left:55mm;margin-bottom:0mm;padding-bottom:0mm;font-size:8mm;float:left;"> পৌরসভা   </p>
<div style="margin-left:48mm;margin-top:0mm;padding-top :0mm;"><span style="width:20mm;">পৌরকরের বিল</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin-left:50mm;margin-bottom:-10mm;font-size:4mm"> অর্থ বছরঃ   </span></div> 
<div style="margin-left:48mm;margin-top:0mm;padding-top :0mm;"><span style="width:20mm;color:red;">পৌরসভার কপি </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="margin-left:50mm;margin-bottom:-10mm;font-size:4mm"> কিস্তিঃ   </span></div> 
    <div class="all_o_i" style="">
    <p  class="o_in">হোল্ডিং নং &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;: </p>
        <p  class="o_in">কর দাতার আই ডি &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
        <p  class="o_in">করদাতার নাম &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
        <p  class="o_in">রাস্তা/মৌজা/এলাকা/মহল্লা &nbsp;: </p>
        <p  class="o_in">বিলের ঠিকানা &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </p>
        <p  class="o_in">বিল ইস্যুর তারিখ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </p>
        <p class="o_in" style="color:red">জমাদানের শেষ তারিখ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: </p>
    </div>
</div>
</div>

<div class="tax_secion1"> 
    <table class="tax_table"> 
        <tr>
            <td rowspan="2">করের বিবরন</td>
            <td colspan="1">বকেয়া </td>
            <td colspan="5">চলতি</td>
        </tr>

        <tr>
            <td style="line-height: 85%;"> &nbsp;  &nbsp;  &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <span style="float:right">অর্থ </span><br />বছরে   &nbsp;  &nbsp;কিস্তি থেকে </td>
            <td>১ম কিস্তি </td>
            <td>২য় কিস্তি </td>
            <td>৩য় কিস্তি </td>
            <td>৪র্থ কিস্তি </td>
            <td>মোট </td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>- </td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

    </table>
</div>

<div class="tax_secion2"> 
    <table class="tax_table"> 
        <tr>
            <td rowspan="2">করের বিবরন</td>
            <td colspan="1">বকেয়া </td>
            <td colspan="5">চলতি</td>
        </tr>

        <tr>
            <td style="line-height: 85%;"> &nbsp;  &nbsp;  &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <span style="float:right">অর্থ </span><br />বছরে   &nbsp;  &nbsp;কিস্তি থেকে </td>
            <td>১ম কিস্তি </td>
            <td>২য় কিস্তি </td>
            <td>৩য় কিস্তি </td>
            <td>৪র্থ কিস্তি </td>
            <td>মোট </td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>- </td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
    </table>
</div>

<div class="tax_secion1"> 
    <table class="tax_table"> 
        <tr>
            <td>করের বিবরন <br /> করের বিবরন  <br /> </td>
            <td>কেবল বকেয়া </td>
            <td>বকেয়া ও ১ম কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-২য়)কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-৩য়) কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-৪র্থ) কিস্তি একত্রে </td>
        </tr>



        <tr>
            <td>-</td>
            <td>-</td>
            <td>- </td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
    </table>
</div>

<div class="tax_secion2"> 
    <table class="tax_table"> 
        <tr>
            <td>করের বিবরন <br /> করের বিবরন  <br /> </td>
            <td>কেবল বকেয়া </td>
            <td>বকেয়া ও ১ম কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-২য়)কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-৩য়) কিস্তি একত্রে </td>
            <td>বকেয়া ও (১ম-৪র্থ) কিস্তি একত্রে </td>
        </tr>



        <tr>
            <td>-</td>
            <td>-</td>
            <td>- </td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>

        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
        <tr>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
        </tr>
    </table>
</div>
';
// $html = '<h1>This is test papers</h1>';

$x = 1; 
while($x <= 1000) {
    $mpdf->AddPage();
    $mpdf->WriteHTML($stylesheet,1);
    $mpdf->WriteHTML($html,2);

    $x++;
}
ob_end_clean();
$mpdf->Output('test.pdf',I);

exit;

&GT;

1 个答案:

答案 0 :(得分:0)

您有两种选择:

在没有max_execution_time

的情况下在后台生成PDF

在处理这种规模的事情时,无论如何都应该这样做。使用cli脚本生成PDF,cli php.ini通常没有设置max_execution_time。将您的PDF保存在磁盘上进一步利用(发送,共享,链接下载)。

浏览器并不意味着显示如此大量的数据,使用适当的桌面PDF查看器可以获得更好的性能。

生成此大小的PDF时,您很可能遇到内存限制问题,为此,还有第二个选项:

以较小的块在后台生成PDF文件,并将它们与外部程序连接

将HTML拆分为最多100页的块,使用cli生成单独的文档(每个文档都运行一个新的干净脚本),并将生成的PDF文档与外部程序连接起来,例如。 GhostScript的:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf

或pdftk:

pdftk in1.pdf in2.pdf cat output out.pdf