PDFable
PDFable is a Yii extension to create PDFs from web
pages with PHPWkHtmlToPdf.
For the documentation please have a look at the project page on github.
PHPWkHtmlToPdf depends on wkhtmltopdf. So make sure, you have a wkhtmltopdf binary installed on your system.
This extension was developed on Yii 1.1.x. But it should work on other versions, too.
Here's just a quick example:
class DemoController extends Controller { public function behaviors() { return array( 'pdfable'=>array( 'class' => 'ext.pdfable.Pdfable', ), ); } public function actionPdfDemo() { // Render this view as PDF and display inline in the browser: $this->renderPdf('pdfDemo'); } }
composer.json
Total 20 comments
It's a wkhtmltopdf problem if you want to run it with x11. As a workaround you have to run it with xvfb-run or do this: https://code.google.com/p/wkhtmltopdf/wiki/compilation
This rather looks like a problem with
wkhtmltopdf. Does it run on the command line? If not and you still think, the problem is caused by the behavior please open a new issue on the github page."wkhtmltopdf: cannot connect to X server" on ubuntu 12.04.2
Fix: apt-get install xvfb
Other attempt:
... but error: Could not execute xvfb-run /usr/bin/wkhtmltopdf
@jhonka I think it's easier to discuss if you open an issue over at github. Please also include the full command call to
wkhtmltopdf. Thehttp://in front of the file paths seem very odd to me.I have installed the extension and am running into problems with the demo. I seem to be having similar problems to what report fleuryc ran into. When I try to export the PDF from the demo site, I get a blank page.
I tried installing the stand alone wkhtmltopdf v. 10.0 rc2 (there was a bug in v 11 that prevented it from running) but the standalone didn't seem to help. When I run wkhtmltopdf from the command line in RedHat, it works without a problem.
I did as advised to fleuryc and output the command of the multipage pdf and ran that in my RedHat server and got the following error:
Do you guys have any ideas?
Hi!
I just created a issue, becaus I get an error when setting page options :
https://github.com/mikehaertl/pdfable/issues/2
Cheers!
But you already can override options when you render a page. Look at the signatures of
renderPdf()or the advancedrenderPage():You can override also single options there. They will be merged with the options you configured in the behavior.
I also recommend to have a look at the sources to find out about all other possible arguments.
Hey Mike,
Thanks for your comment, Well in my case I have a set of options that I always want to load, and I do it in the behaviors() of the controller when attaching pdfable. But later on, in my controller action, I want to specify additional options depending on the (post) data I am handling.
Can you give an example, where this would be useful? You actually already have many ways to supply options for your PDF, so i can't really think of a situation where it would be neccessary to set some single global options.
Hey Mike,
here is a suggestion to add to the Pdfable behavior, in order to set options after the behavior was attached to the Controller.
What do you think about it ?
Cheers,
Yann
Hello,
Thanks for your work. I am just implenting it right now.
When rendering, I am also experiencing the problem with windows + the user-style-sheet option from wkhtmltopdf mentionned here : http://mikehaertl.github.com/phpwkhtmltopdf/
For now I'll use inline CSS.
Dammit! The 'bin' parameter won't get overridden...
EDIT : OK, gottit : need to be configured in the
behavior()part of the controller. Theconfig.phpbinparameter doesn't seem to be useful, is it?EDIT2 : OK, gottit² : the
config.pgppdfablemodule is just for the demo. To actually be able to use the extension, you must attach the behavior to the controller.Dumb me...
Arrgh!
Allright, thanks for your help!
Forgot to post the link to the download page:
http://code.google.com/p/wkhtmltopdf/wiki/static
Unfortunately, the
wkhtmltopdfversion which is shipped by some distros (i only know about Ubuntu, but it's probably the same for others), does not use the patched version of the Qt library.The solution is, to install the statically linked binary version for
wkhtmltopdf. You can download it for your architecture on it's Google code page. I can not really help you much, how to do it, but this information here should hopefully help you out:http://code.google.com/p/wkhtmltopdf/wiki/static
@Mike:
the command is :
and the result (executed via CLI) :
If I remove the
--no-outlineoption, I get this error:Thaks for your help!
If you try the advanced example, you can fetch the command line sent to
wkthtmltopdfwith$pdf->getCommand(). What happens if you echo this command right beforesendPdf()is called and call that command manually on the command line?Hi!
I can't get it to work. I follow the installation instructions, wkhtmltopdf is correctly installed on my Ubuntu workstation.
On the demo page, when I click the "Download" link, I get a empty blank page (nothing is returned). Same when I use it in one of my actions :
Thanks for your help.
Sorry, you need
wkhtmltopdfinstalled on your system. I've updated the description to make this more clear.When I try out the demo and click on "single page pdf" for example, all I get is a blank screen, not even a border of the pdf. Does that mean I don't have PHPWkHtmlToPdf installed correctly?
Leave a comment
Please login to leave your comment.