Pdfable (Wkhtmltopdf) Create PDFs with wkhtmltopdf
#1
Posted 25 April 2012 - 05:50 AM
http://mikehaertl.gi...phpwkhtmltopdf/
It provides a nice OO interface to the command line utility.
UPDATE (2012-11-16):
This is also available as Yii extension now: http://www.yiiframew...ension/pdfable/
#2
Posted 25 April 2012 - 10:56 PM
#3
Posted 26 April 2012 - 01:41 AM
Or let me ask the other way round: What should a wrapper class add what the original class doesn't already provide?
#4
Posted 26 April 2012 - 08:26 AM
Good point on the library stuff. A counter point though is that people who don't know that much about PDF creation from HTML may look through the extension section and never end up using your gem, because they don't find it. Wouldn't it help raise the visibility of your library (and thus help people more often) to make it an extension?
#5
Posted 26 April 2012 - 11:23 AM
<?php
$options=array(
'footer-html'=>'footer.html',
'header-html'=>'header.html',
));
// Then either set it for every page:
$pdf->setPageOptions($options);
// Or only for a specific page:
$pdf->addPage('page.html', $options);
See wkhtmltopdf -H for more options.
I agree that an extension might help to increase popularity. I'm just not sure if this really makes sense: This class is not related to Yii at all. It's rather a standalone class which you can easily integrate into Yii. And for now the home is the github page. I don't want to maintain two downloads for this class. But let me think about it, maybe i change my mind ...
What a wrapper class could do: Add getter/setter support through CComponent and wrap up errors in exceptions. Let's see.
#6
Posted 14 May 2012 - 10:51 AM
Mike, on 26 April 2012 - 11:23 AM, said:
I agree that an extension might help to increase popularity. I'm just not sure if this really makes sense: This class is not related to Yii at all. It's rather a standalone class which you can easily integrate into Yii. And for now the home is the github page. I don't want to maintain two downloads for this class. But let me think about it, maybe i change my mind ...
What a wrapper class could do: Add getter/setter support through CComponent and wrap up errors in exceptions. Let's see.
Thanks for the class. WkHtmltoPdf seems to be a nice,quick pdf solution.
It would be nicer if there is a wiki and/or extension of it.
I try to use it, but because of safe mode restrictions I couldnt find a way of using it so far.
Edit: Ok I did it.
I made safe_mode_exec_dir =/tmp/wkm/
and put binary there. Modified class accordingly. It works now except css formatting.
I search for howto include a css file.
#7
Posted 15 May 2012 - 01:22 AM
wyginwys, on 14 May 2012 - 10:51 AM, said:
If you add a page from URL you don't have to include a CSS file - wkhtmltopdf will fetch the HTML and whatever CSS file is defined inside the page. But you can also set a static CSS file like this:
<?php
$pdf->setPageOptions(array(
'user-style-sheet' => '/path/to/your/own/pdf.css',
));
#8
Posted 15 May 2012 - 05:48 AM
Mike, on 15 May 2012 - 01:22 AM, said:
<?php
$pdf->setPageOptions(array(
'user-style-sheet' => '/path/to/your/own/pdf.css',
));I tried both.
I am using your class seeding it with $html by $pdf->addPage($page); where $page is a local html file.
A css link inside html file like this <head><link rel=\"stylesheet\" href=\"css/detailview.css\" type=\"text/css\"/> dont work.
Maybe because wkhtmltopdf dont understand where css/detailview.css file is.
For the second I have used
$pdf->setPageOptions(array(
'disable-smart-shrinking',
'user-style-sheet' => 'detailview.css', ('css/detailview.css' neither works)
));
that didnt work neither. Maybe because I didnt use absolute paths. I will try the absolute paths.
Your class and wkhtmltopdf deserves an extension and a wiki.
#10
Posted 18 October 2012 - 08:55 AM
BTW i'm preparing a Yii extension now, which should make it very easy to render PDFs from one/several Yii pages.
#13
Posted 30 November 2012 - 03:23 AM
but I have a question about TOC,
how to use it? because I get an error when I try to use it..thanks..
#15
Posted 02 December 2012 - 10:44 PM
Mike, on 01 December 2012 - 04:24 AM, said:
I use it like this source and I put it in my function:
$this->renderPdf('printRkakl',
array('model'=>$this->loadModel($id)),
array('toc-header-text' => 'test',),
'program_'.$id.'.pdf');
and I get a blank page..
thanks
#16
Posted 03 December 2012 - 03:06 AM
#17
Posted 04 December 2012 - 04:15 AM
when I use header option or page option,its all work, but when I try to use TOC option it didn't work (blank page)...
thanks..
#18
Posted 05 December 2012 - 03:46 AM
Personally i've never used a TOC, so it's very well possible that there's still a bug here.
#19
Posted 18 December 2012 - 04:14 AM
'/usr/local/bin/wkhtmltopdf' --outline --encoding 'UTF-8' --margin-top '65' --margin-right '10' --margin-bottom '20' --margin-left '10' --title 'RKAKL' --page-size 'A4' --dpi '600' /home/Documents/work/protected/runtime/tmp_WkHtmlToPdf_1mbnkb.html --user-style-sheet '/var/www/work/css/main.css' --header-html '/var/www/work/header.html' --header-spacing '1' --toc-header-text 'test' /home/Documents/work/protected/runtime/tmp_WkHtmlToPdf_Y7JFBp
sorry mike I'm late for reply..hehe
#20
Posted 18 December 2012 - 04:41 AM
Can you try to use addToc($tocOptions) instead? You need to create the PDF a little different in this case. See the multi page example.

Help













