WebFaction
Community site: login faq

Continuing from this thread: http://forum.webfaction.com/viewtopic.php?pid=19127

Hi Aaronh,

thanks for your answer, I followed your instructions and got a bit further, it seems that the paths are working all right, temporary HTML files are generated in the server, but the PDF are not created (not stored in the server or opened in the browser), I get his error when I run the script:

Fatal error: Uncaught exception 'Exception' with message 'WKPDF shell error, return code 2.' in /home/fariazz/webapps/pruebas/pruebapdf.php:207 Stack trace: #0 /home/fariazz/webapps/pruebas/pruebapdf.php(273): WKPDF->render() #1 {main} thrown in /home/fariazz/webapps/pruebas/pruebapdf.php on line 207

asked 20 Oct '10, 07:00

fxsymfony
26111
accept rate: 100%

I've looked through your code and it seems that this line:

272 $pdf->render();

is the line causing the problem. I've looked through the example on the Google code page and I don't see where $pdf->render(); is called.

(21 Oct '10, 23:49) klynton

Ok problem solved. Once having wkhtmltopdf working on the command line just use this library instead of the other php script:

http://github.com/knplabs/snappy

permanent link

answered 25 Oct '10, 20:26

fxsymfony
26111
accept rate: 100%

The original script contains this:

$GLOBALS['WKPDF_BASE_PATH']=str_replace(str_replace('\\','/',getcwd().'/'),'',dirname(str_replace('\\','/',__FILE__))).'/';

In other words, it's setting WKPDF_BASE_PATH to the parent directory of the script itself.

Later in the code, the render() function defines $web like this:

$web=$GLOBALS['WKPDF_BASE_SITE'].$GLOBALS['WKPDF_BASE_PATH'].'tmp/'.basename($this->tmp);

So, it's building a URL out of WKPDF_BASE_SITE and WKPDF_BASE_PATH.

If you followed the advice in the forum, then your code contains something like this:

$GLOBALS['WKPDF_BASE_PATH']='/home/username/bin/';
$GLOBALS['WKPDF_BASE_SITE']='http://yourdomain.com/';

That means that $web will evaluate to something like http://yourdomain.com//home/username/bin/tmp/something. I don't really know anything about wkhtmltopdf or how the script uses that URL, but that definitely looks wrong to me.

I think you should try the following:

  1. Define $GLOBALS['WKPDF_BASE_PATH'] as shown in the original code.
  2. Create a tmp directory: mkdir /home/fariazz/webapps/pruebas/tmp
  3. Create a symlink to your wkhtmltopdf executable in your app directory: ln -s ~/bin/wkhtmltopdf /home/fariazz/webapps/pruebas/

I think that if you do that, all of the action will happen inside of your web app directory, which (as far as I can tell) is what the script expects.

permanent link

answered 21 Oct '10, 11:52

seanf
12.2k41936
accept rate: 37%

edited 21 Oct '10, 12:42

Hi Seanf,

Thanks for your answer. I started with the original script and followed the steps:

1-used the original $GLOBALS['WKPDF_BASE_PATH']
2-used my domain in $GLOBALS['WKPDF_BASE_SITE']
3-created the tmp dir
4-created the symlink to the executable

Then I added the following after the class definition:

$pdf=new WKPDF(); $pdf->set_html('http://www.google.com'); $pdf->render(); (after the render method one needs to call the output method, but the error occurs when calling the render method)

I get the same error as before:

Fatal error: Uncaught exception 'Exception' with message 'WKPDF shell error, return code 2.' in /home/fariazz/webapps/pruebas/pruebapdf.php:207 Stack trace: #0 /home/fariazz/webapps/pruebas/pruebapdf.php(272): WKPDF->render() #1 {main} thrown in /home/fariazz/webapps/pruebas/pruebapdf.php on line 207

The script works just fine from the command line.

(21 Oct '10, 22:48) fxsymfony
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×9
×3

question asked: 20 Oct '10, 07:00

question was seen: 23,601 times

last updated: 25 Oct '10, 20:26

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM