How to remove blank page in mpdf

I am converting an html file to PDF using mPdf , but the returned PDF file contains blank pages. I want to delete these blank pages.

+6
source share
3 answers

Had the same problem and realized that my CSS forced these page breaks. Make sure you don't have this in your CSS:

 page-break-after: always; 
+2
source

This can be for many reasons:

1) Make sure that the elements do not have unnecessary margins and gaskets

2) Correctly set the page properties (special fields):

 $page_orientation = 0; $page_size = 'Letter'; $page_margins = array('LEFT(int)','RIGHT(int)','UP(int)','BOTTOM(int)'); $pdf_output = 'I'; $css_files = array( 'path/file.css', 'path/file_2.css', ); $orientationPage = array('','-L'); /* ===== [ MPDF ] =====*/ $mpdf=new mPDF('utf-8', $page_size.$orientationPage[$page_orientation],'','',$page_margins[0],$page_margins[1],$page_margins[2],$page_margins[3]); // Loading CSS for($i = 0; $i < count($css_files); $i++){ $stylesheet = file_get_contents('../../'.$css_files[$i]); $mpdf->WriteHTML($stylesheet,1); // 1 para indicar que es CSS } // Set header & Footer (This are variables with html code) $mpdf->SetHTMLHeader($header); $mpdf->SetHTMLFooter($footer); $mpdf->SetDisplayMode('fullpage'); $mpdf->SetTitle($title); $mpdf->WriteHTML($html); // <-- insert HTML // Create PDF $mpdf->Output($titulo.'.pdf',$pdf_output); 

3) Make sure you don't have any unnecessary "page breaks" in HTML

 <pagebreak type="NEXT-ODD" resetpagenum="1" pagenumstyle="i" suppress="off" /> 

I hope this can help you!

0
source

I had the same problem and fixed it by removing the AddPage property from my code

I changed the following code

  // Code with bug $mpdf = new mPDF('utf-8', array(380,500)); $mpdf->WriteHTML($htmlContent); $mpdf->AddPage('P'); // It will add extra page - I that i removed this line $mpdf->Output(); 

In that

  // code after resolving the bug $mpdf = new mPDF('utf-8', array(380,500)); $mpdf->WriteHTML($htmlContent); $mpdf->Output(); 
0
source

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


All Articles