Search code examples
phppdftcpdfwkhtmltopdf

PHP : Create PDF from html with 400-500 pages


I converted html to PDF file which contains 400-500 pages using wkhtmltopdf. But getting undesirable spaces after each 4 rows in table. How to overcome this issue ? HTML is looks fine but PDF has spaces.

I use following things to create PDF.

  1. PHP => exec('/usr/bin/wkhtmltopdf temp.html temp.pdf 2>&1', $output);
  2. Style in HTML :

@media all { table { empty-cells: hide !important;} tr { page-break:avoid; page-break-inside: avoid; empty-cells:hide; margin:0px; padding:0px;} .pgBrk { page-break-after: always !important; page-break-inside:avoid !important;} tr.json-array-table { page-break-inside: avoid !important;}

Please suggest.


Solution

  • I have done this using TCPDF library. wkhtmltopdf is fast execution but less customization. TCPDF supports customization and a lot of key features when you work with the creation of PDF files. We can checkout BEST library in php here .