Page break in Html2Pdf

I am creating a dynamic pdf file containing data from about 10,000 users, in general, the application is developed using MySQL and PHP. The dynamic content is so heavy that it's hard for me to handle the fpdf() class. So I converted my output PHP page as an HTML file using ob_get_clean() . Now the html file has been generated successfully, as well as the pdf file. But I want to leave a page break after each user data, that is, all user data should start on a new page. I could not use HTML tags because in the dynamically generated HTML file all of the <html> and </html> tags. Please help me to some of them, as I do a page break in a PDF file after each user data ... Thanks in advance :)

+4
source share
4 answers

I just figured it out due to the same problem. the parser they use supports the page break tag, but html2pdf does not work.

I think I'm working by making the following changes to html2pdf.class:

around line 4174, the first thing inside:

 protected function _tag_close_P($param){ 

it 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'){ 

it should be:

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

Based on the work of macdabby (which does not work). But thanks to him, the idea is correct.

Html2Pdf v4.03

For example, we want to parse a DIV tag:

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 adds a new handler to the switch enclosure:

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

And then for it to work, your html content must contain a break element

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

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

+10
source

html2pdf supports page tag:

 protected function _tag_open_PAGE($param) {} 

on line 2229. You can see which attributes are supported. For example, the following creates one page in landscape orientation and one in portrait mode:

 <page orientation="l"> ... some content ... </page> <page orientation="p"> ... some content ... </page> 
+9
source

You might want to use some css, for example:

 h1 {page-break-before:always} 
+1
source

Source: https://habr.com/ru/post/1299110/


All Articles