Note that there are some explanatory texts on larger screens.

plurals
  1. POwkhtmltopdf does not create PDF of website
    primarykey
    data
    text
    <p>I have found a tutorial on the internet about how to create a Wkhtmltopdf form where you can input your website URL and it will automatic create a PDF.</p> <p>First I had to download the exec file wkhtmltopdf-amd64 at: <a href="http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2" rel="nofollow">http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2</a></p> <p>There are two codes:</p> <p>The form (pasted in the index.php):</p> <pre><code>&lt;form action="http://localhost:8888/dev.crm/wkhtmltopdf.php" method="POST"&gt;Website:&amp;nbsp; &lt;input name="url" size="30" type="text" value="http://www.examplewebsite.com" /&gt; &lt;input type="submit" value="transform into a pdf" /&gt; &lt;/form&gt; </code></pre> <p>The wkhtmltopdf.php file (pasted in the wkhtmltopdf.php):</p> <pre><code>&lt;?php /****************************  BEGIN CONFIG ****************************/ // path to the program wkhtmltopdf $conf['wkhtmltopdf'] = "http://www.mydomain.com/var/wkhtmltopdf-amd64"; // arguments for the programma wkhtmltopdf // for example: --margin-top 50 --margin-bottom 30 // look: http://code.google.com/p/wkhtmltopdf/w/list $conf['wkhtmltopdf_arg'] = ""; /****************************  END CONFIG ****************************/ // reads url $pattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&amp;@#\/%?=~_|!:,.;]*[-a-z0-9+&amp;@#\/%=~_|]/i"; if (!preg_match($pattern, $_REQUEST['url'])) { die("no valid URL"); } // temporary file $output = "http://www.mydomain.com/dev.crm/tmp/output.pdf"; // gets the html of the document $html = file_get_contents($_REQUEST['url']); // gets the title of document preg_match("/\&lt;title\&gt;(.+)\&lt;\/title\&gt;/is", $html, $matches); // looks if there is a title if (empty($matches[1])) { $matches[1] = "output.pdf"; } // create pdf from html system($conf['wkhtmltopdf'] . " " . $conf['wkhtmltopdf_arg'] . " " . $_REQUEST['url'] . " " . $output); // output pdf to the browser header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"" . $matches[1] . ".pdf\""); readfile($output); // remove pdf unlink($output); exit(0); ?&gt; </code></pre> <p>The form works perfect and also calls the wkhtmltopdf.php, but somehow my server does not use the wkhtmltopdf-amd64. When I press the transform into a PDF button, I see that my webpage is loading, but it tries to open a PDF file, but I immidiadly get an error: 'the file '....pdf' cannot be openend, because it is empty. It saves the PDF, but the PDF size is 0 bytes. </p> <p>Anyone has any idea how I can fix this issue? I think he does not use the wkhtmltopdf-amd64 file on my webserver.</p> <p>//update</p> <p>I saw that in the form I pasted localhost url. I changed that + line: </p> <p>output ="/tmp/output.pdf"; now I got an error in a new page: Warning: system() has been disabled for security reasons in /home/.../domains/.../public_html/.../wkhtmltopdf.php on line 40</p> <p>Warning: Cannot modify header information - headers already sent by (output started at /home/.../domains/.../public_html/.../wkhtmltopdf.php:40) in /home/.../domains/.../public_html/.../wkhtmltopdf.php on line 43</p> <p>Warning: Cannot modify header information - headers already sent by (output started at /home/.../domains/.../public_html/.../wkhtmltopdf.php:40) in /home/.../domains/.../public_html/.../wkhtmltopdf.php on line 44</p> <p>Warning: readfile(/tmp/output.pdf) [function.readfile]: failed to open stream: No such file or directory in /home/.../domains/.../public_html/stage/wkhtmltopdf.php on line 45 </p> <p>(the ... are my domains.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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