Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting HTML to PDF (not PDF to HTML) using PHP
    primarykey
    data
    text
    <p>I am a PHP developer and in one of my projects, I need to convert some HTML documents (about 30 to 50 pages) into PDF documents.</p> <p>My search has turned up the following possible solutions. Among them are some PHP libraries and some command line applications. Each has its own advantages and disadvantages.</p> <p><strong>PHP libraries:</strong></p> <ol> <li>fpdf (need more effort to convert)</li> <li>tcpdf (need more effort to convert) </li> <li>html2fpdf <a href="http://html2fpdf.sourceforge.net" rel="noreferrer">http://html2fpdf.sourceforge.net</a></li> <li>html2pdf <a href="http://html2pdf.fr/" rel="noreferrer">http://html2pdf.fr/</a></li> <li>dompdf <a href="http://code.google.com/p/dompdf/" rel="noreferrer">http://code.google.com/p/dompdf/</a> (compared to other, works well)</li> </ol> <p>For each library, I have problems like:</p> <ol> <li>Takes a long time (more than five minutes to convert 30 HTML pages)</li> <li><p>Requires too many resources (memory and time) </p> <p>(I set the following parameters in php.ini:</p> <p><code>max_execution_time = 600</code><br> <code>memory_limit = 250M</code></p> <p>but things still don't work.)</p></li> <li><p>Needs HTML pages to be well-formatted (e.g. no missing close tags)</p></li> </ol> <p><em>All of these work when I try to convert simple HTML docs (five or fewer pages with little CSS)</em></p> <p><strong>Command line applications</strong></p> <p>All command line apps work perfectly and very quickly compared to the above libraries, but only when I run them directly on console. When I try to use them in PHP with <code>exec()</code> or <code>system()</code>, they give me errors.</p> <p>The following are the command line applications and their errors when I run them in PHP:</p> <ol> <li><p>html2pdf (<a href="http://www.tufat.com/s_html2ps_html2pdf.htm" rel="noreferrer">http://www.tufat.com/s_html2ps_html2pdf.htm</a>)</p> <blockquote> <p>html2pdf:11380): Gtk-WARNING **: cannot open display: :0.0<br> No protocol specified</p> </blockquote></li> <li><p>wkhtmltopdf</p> <blockquote> <p>Loading page: 10%<br> Loading page: 33%<br> Loading page: 100%<br> Waiting for redirect<br> Outputting pages<br> QPainter::begin(): Returned false<br> QPainter::begin(): Returned false<br> QPainter::save: Painter not active<br> QPainter::scale: Painter not active<br> QPainter::setRenderHint: Painter must be active to set rendering hints<br> QPainter::setBrush: Painter not active<br> QPainter::pen: Painter not active<br> QPainter::setPen: Painter not active</p> </blockquote></li> <li><p>htmltopdf (<a href="http://www.ultrashareware.com/html-to-pdf.htm" rel="noreferrer">http://www.ultrashareware.com/html-to-pdf.htm</a>)</p></li> </ol> <p>So now I am looking for help. Can anyone answer:</p> <p><strong>Which PHP library would work well in my case?</strong> </p> <p><strong>Why do these errors occur in command line applications?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload