0

Im trying to generate a PDF with wkhtmltopdf with PHP:

<?php
if(isset($_POST['submit']))
{
    require_once("../include/WkHtmlToPdf.php");

?>
<div id="layout">
<div id="top">
    <img src="images/logo.png">
    <br/><br/><br/>
    Net at Once <br/>
    Box 177 <br/>
    351 04 Växjö
</div>
<div id="addresspos">
<?= $_POST['firstname'] ?> <?= $_POST['lastname'] ?><br/>
<?= $_POST['address'] ?><br/>
<?= $_POST['zip'] ?> <?= $_POST['city'] ?>
</div>
<div id="middle">
<p><?= $_POST['textcontent'] ?>
</div>
<div id="bottomcontent">
<div class="addressinfo">Net at Once Sweden AB</div> 
<div class="addressinfo">Adress<br/>Box 177<br/>351 04 Växjö</div> 
<div class="addressinfo">Telefon<br/>0771-40 44 00</div> 
<div class="addressinfo">Fax<br/>0470-137 77</div> 
<div class="addressinfo">E-post/Hemsida<br/>support@netatonce.se<br/>www.netatonce.se</div>
<div class="addressinfo">Org.nr<br/>556506-3491<br/>Godkänd för f-skatt</div> 
</div>
</div>

<?php
$pdf = new WkHtmlToPdf;
$pdf->addPage('/var/www/kadm/www/ebrevcreate.php');
$pdf->addToc();
$pdf->saveAs('/var/www/kadm/www/test.pdf');
$pdf->send();
echo "<pre>";
var_dump($pdf);
echo "</pre>";
}
?>

When I run the script, I get this error message:

"Could not run command '/usr/bin/wkhtmltopdf' '/var/www/kadm/www/ebrevcreate.php' 'toc' /tmp/tmp_WkHtmlToPdf_yrCVEE:
wkhtmltopdf: cannot connect to X server 

Anyone who can help me?

user500468
  • 1,183
  • 6
  • 21
  • 36

2 Answers2

0

I believe you have a problem with the WKHTMLTOPDF installation. Please take a look at these: wkhtmltopdf: cannot connect to X server

wicked_pdf does not run on Ubuntu server : wkhtmltopdf: cannot connect to X server

Community
  • 1
  • 1
Tuomo B
  • 127
  • 2
  • 7
0

You absolutely don't have any problem !

You need to use the xvfb command before ! If you launch the command from a server, there is no X server, you need to add the

xvfb-run 

command before "wkhtmltopdf" for create a virtual framebuffer, just add xvfb-run before your command.

At the end you will get something like this:

xvfb-run wkhtmltopdf http://yourlink.com

I think that you will need to edit some lines in your WkHtmlToPdf.php file for add the xvfb command.

Superdrac
  • 1,208
  • 17
  • 29