how TCPDF prevent the extra blank page

扶醉桌前 提交于 2019-11-28 01:34:54

I had the same Problem: I fixed it with:

class TCPDFextended extends \TCPDF {

    public function Output($name = 'doc.pdf', $dest = 'I')
    {
        $this->tcpdflink = false;
        return parent::Output($name, $dest);
    }

}

My answer is similar to @kanti. I think we can set the default to false even before the Output generation.

Background. The extra page we see is basically

"If true print TCPDF meta link".

so by default the TCPDF::$tcpdflink = true , is set true. All we need is

 class My_PDF extends TCPDF {
     public function changeTheDefault($tcpdflink) {
            $this->tcpdflink = $tcpdflink;
          }
}

call your public function later when you need it. ...

$get_pdf = new My_PDF (your_parameters);
$get_pdf->changeTheDefault(false); # changes the default to false

Good Luck.

You should check your $html variable.

1) If it could contains any <html />, <head />, <title />, <body /> tag then please remove them and just take html contents after and before <body />.

2) You should avoid any css, js link file within $html content.

3) Finally you should use $html=utf8_encode($html); just before $this->writeHTML($html, true, false, true, false, '');.

4) You may need to adjust your MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT and MARGIN_BOTTOM to solve such problems. Please check $this->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); and $this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);.

Hopefully it can solve your problem.

Usman Saeed

Try this deletePage function

$lastPage = $this->getPage();
$this->deletePage($lastPage);

Instead Delete use deletePage

Check also the height of your enclosing div. It should not be 100%. Try to remove any height property from the CSS style of the enclosing div ( I mean the div which encloses all the content).

The problem is the 4th parameter (unicode = true) in your create_pdf.php file. This parameter is passed into tcpdf.php on line 1838

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'ISO-8859-1', false);

change it to false.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!