{"id":1545,"date":"2022-08-30T15:17:25","date_gmt":"2022-08-30T15:17:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/how-to-convert-html-css-to-pdf-in-php-on-linux-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:25","modified_gmt":"2022-08-30T15:17:25","slug":"how-to-convert-html-css-to-pdf-in-php-on-linux-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-convert-html-css-to-pdf-in-php-on-linux-collection-of-common-programming-errors\/","title":{"rendered":"How to Convert HTML\/CSS to PDF in PHP on Linux-Collection of common programming errors"},"content":{"rendered":"<p>I have been trying to convert an html page to PDF with out any luck, I have tried to use wkhtmltopdf (http:\/\/code.google.com\/p\/wkhtmltopdf\/) and the PHP class provided by the same developers (http:\/\/code.google.com\/p\/wkhtmltopdf\/wiki\/IntegrationWithPhp) although the following command executed correctly in terminal:<\/p>\n<pre><code>wkhtmltopdf http:\/www.googl.com test.pdf\n<\/code><\/pre>\n<p>I was unable to execute the command in PHP because of the following error: cannot connect to X server.<\/p>\n<p>Can any one provide me with a step-by-step tutorial in order to be able to convert html\/css to PDF file, whether using wkhtmltopdf or any other decent solution.<\/p>\n<p>Thanks in advance<\/p>\n<p>here is the class that i have used http:\/\/code.google.com\/p\/wkhtmltopdf\/wiki\/IntegrationWithPhp<\/p>\n<p>and below is my code<\/p>\n<pre><code>$html = file_get_contents(\"test.html\");\n\n$pdf = new WKPDF();\n\n$pdf-&gt;set_html($html);\n\n$pdf-&gt;render();\n\n$pdf-&gt;output(WKPDF::$PDF_EMBEDDED,'sample.pdf');\n<\/code><\/pre>\n<p>Below is the error:<\/p>\n<pre><code>Fatal error: Uncaught exception 'Exception' with message 'WKPDF didn't return any data.\n\/usr\/bin\/wkhtmltopdf: \/opt\/lampp\/lib\/libxml2.so.2: no version information available\n(required by \/usr\/lib\/libgstreamer-0.10.so.0) No protocol specified wkhtmltopdf: cannot\nconnect to X server :0 <\/code><\/pre>\n<p><code>' in \/var\/www\/c4\/components\/com_wkhtmltopdf \/wkhtmltopdf.class.php:211 Stack trace: #0 \/var\/www\/c4\/components\/com_wkhtmltopdf \/wkhtmltopdf.php(68): WKPDF-&gt;render() #1 \/var\/www\/c4\/components\/com_wkhtmltopdf \/wkhtmltopdf.php(50): html2pdf() #2 \/var\/www\/c4\/index2.php(114): require_once('\/var\/ww...') #3 {main} thrown in \/var\/www\/c4\/components\/com_wkhtmltopdf\/wkhtmltopdf.class.php on line 211<\/code><\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-27 05:08:28. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have been trying to convert an html page to PDF with out any luck, I have tried to use wkhtmltopdf (http:\/\/code.google.com\/p\/wkhtmltopdf\/) and the PHP class provided by the same developers (http:\/\/code.google.com\/p\/wkhtmltopdf\/wiki\/IntegrationWithPhp) although the following command executed correctly in terminal: wkhtmltopdf http:\/www.googl.com test.pdf I was unable to execute the command in PHP because of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1545","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1545"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1545\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}