{"id":1548,"date":"2022-08-30T15:17:27","date_gmt":"2022-08-30T15:17:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/how-do-i-get-wkhtmltopdf-to-execute-via-php-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:27","modified_gmt":"2022-08-30T15:17:27","slug":"how-do-i-get-wkhtmltopdf-to-execute-via-php-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-do-i-get-wkhtmltopdf-to-execute-via-php-collection-of-common-programming-errors\/","title":{"rendered":"How do I get WKHTMLTOPDF to execute via PHP?-Collection of common programming errors"},"content":{"rendered":"<p>Ok, this has been asked to some degree before but there are no solutions or accepted answers and I&#8217;d like to try and be more comprehensive in my question so:<\/p>\n<p>I&#8217;m trying to WKHTMLTOPDF up and running via PHP on a shared server (in this case it&#8217;s MediaTemple (gs)). According to the host there is no reason this won&#8217;t work and in fact it is working via SSH. So&#8230;<\/p>\n<p>I&#8217;ve tried a variety of things, the most basic does nothing, just silently fails:<\/p>\n<pre><code>exec(\"\/path\/to\/binary\/wkhtmltopdf http:\/\/www.google.com pdf1.pdf\");\n<\/code><\/pre>\n<p><sup>&#8211; <em>Source: Question on Stack Overflow<\/em><\/sup><\/p>\n<p>The full PHP bindings along with the following give me errors, which despite my best Googling I can&#8217;t figure out:<\/p>\n<p>Call:<\/p>\n<pre><code>$html = file_get_contents(\"http:\/\/www.google.com\");\n$pdf = new WKPDF();\n$pdf-&gt;set_html($html);\n$pdf-&gt;render();\n$pdf-&gt;output(WKPDF::$PDF_EMBEDDED,'sample.pdf');\n<\/code><\/pre>\n<p><sup>&#8211; <em>Source: WKHTMLTOPDF on Google Code<\/em><\/sup><\/p>\n<p>Error:<\/p>\n<pre><code>Fatal error: Uncaught exception 'Exception' with message 'WKPDF didn't return\nany data. <\/code><\/pre>\n<pre><code>Loading pages (1\/6) [&gt; ] 0% [======&gt; ] 10% terminate called\nafter throwing an instance of 'std::bad_alloc' what(): std::bad_alloc <\/code><\/pre>\n<pre>'\nin \/path\/to\/wkhtmltopdf.php:206 Stack trace: #0 \/path\/to\/index.php(8):\nWKPDF-&gt;render() #1 {main} thrown in \/path\/to\/wkhtmltopdf.php on line 206\n<\/pre>\n<p><code>And once I got this (below is an extract as I can't reproduce it now):<\/code><\/p>\n<pre><code><code>Qt Concurrent has caught an exception thrown from a worker thread. This is not\nsupported, exceptions thrown in worker threads must be caught before\ncontrol returns to Qt Concurrent.\n<\/code><\/code><\/pre>\n<p>I&#8217;ve also tried a few other options but with the same results; no PDF. So what do I do now, how do I figure out what&#8217;s wrong? My PHP level is on the basic side but I&#8217;ll do my best. Many thanks in advance.<\/p>\n<ol>\n<li>\n<p>You can also try my project here. It provides a clean OO interface to the command line utility:<\/p>\n<p>http:\/\/mikehaertl.github.io\/phpwkhtmltopdf\/<\/p>\n<p>Usage is very simple:<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 05:08:43. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Ok, this has been asked to some degree before but there are no solutions or accepted answers and I&#8217;d like to try and be more comprehensive in my question so: I&#8217;m trying to WKHTMLTOPDF up and running via PHP on a shared server (in this case it&#8217;s MediaTemple (gs)). According to the host there is [&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-1548","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1548","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=1548"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1548\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}