Page break in Html2Pdf

久未见 提交于 2019-11-27 23:19:44

i just figured this out after having the same problem. the parser that they use DOES support the page-break-after tag, but the html2pdf does not work.

i think i have it working by doing the following modifications to html2pdf.class:

around line 4174, the first thing inside:

protected function _tag_close_P($param){

should be:

   if($this->parsingCss->value['page-break-after'] == "always")
        $this->_setNewPage();

around line 2961, the first thing inside:

protected function _tag_close_DIV($param, $other='div'){

should be:

 if($this->parsingCss->value['page-break-after'] == "always")
        $this->_setNewPage();

html2pdf supports page tag:

protected function _tag_open_PAGE($param) {} 

at line 2229. You can see there what attributes are supported. For example following creates one page in landscape and one in portrait mode:

<page orientation="l">
... some content ...
</page>
<page orientation="p">
... some content ...
</page>
Thanh Trung

Basing on macdabby's work (which doesn't work). But thanks to him, the idea is correct.

Html2Pdf v4.03

For example we want to parse a tag DIV:

html2pdf.class.php line 2948:

protected function _tag_close_DIV($param, $other='div')
{
    if ($this->parsingCss->value['page-break-after'] == "always")
      $this->_setNewPage(null, '', null, $this->_defaultTop);
      $this->parsingCss->setPosition();
    ...
}

parsingCss.class.php Line 114:

//add a new style declaration
public function initStyle()
{
    ...
    $this->value['page-break-after'] = null;
}

Line 1024 add a new handler to the switch case:

case 'page-break-after':
    $this->value[$nom] = $val;
    break;

And then for it to work, your html content should contain the break element

 <div style="page-break-after:always; clear:both"></div>

Watch out for case sensitive style, not sure if the plugin handle it

You possibly want to use some css, eg:

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