To PDF or not to PDF
#1
Posted 11 February 2010 - 05:47 PM
It was a required from my current client, I think it breaks down to they want to generate filled in forms based on the data in the database and print them. Which can be done with XHTML.
I guess my question is.. what does generating a PDF for a standard form give you over just generating XHTML?
#2
Posted 12 February 2010 - 02:29 AM
I imagine your client wanted to generate forms that had "lines" instead of "text-boxes". He may have made the conclusion from that that pdf files were needed. Or maybe he wanted the ability to email them, or use some other sort of pdf features.
#3
Posted 13 February 2010 - 11:48 PM
http://code.google.com/p/wkhtmltopdf/
It basically is the same as having a webkit browser doing 'print to pdf'.
Bas
#4
Posted 15 February 2010 - 03:14 PM
#5
Posted 16 February 2010 - 04:36 AM
DarkNSF, on 11 February 2010 - 05:47 PM, said:
First, have you tried Quick PDF Library? I use it since late '90 with Delphi (then known as Isedquickpdf), now with C# (and I know it works with PHP, but haven't tried yet). Good product, covers probably all the features of the current pdf standard.
My answer to your question: check the functions eg. the a/m library covers - above some level of complexity it's hard to implement all them in XHTML. At least I don't have time for it.
#6
Posted 25 February 2010 - 08:32 PM
DarkNSF, on 11 February 2010 - 05:47 PM, said:
One major benefit (depending on your target/client) is the fact that when you print a PDF, you do not get the (usually unwanted) 'header and footer' appended by your browser by default.
By this I mean for example, the URL printed at the top of the document.
You can't expect your users to mess about (or even know about) changing print settings.
#7
Posted 25 August 2010 - 06:39 PM
http://code.google.com/p/dompdf/
#8
Posted 26 August 2010 - 01:48 AM
DarkNSF, on 25 August 2010 - 06:39 PM, said:
http://code.google.com/p/dompdf/
I used this one a long time ago almost 2 years I think... it worked pretty good but some of the html/css i needed to hack a little to get it displayed properly.
As to your question..
"I guess my question is.. what does generating a PDF for a standard form give you over just generating XHTML?"
Only benefit is that you can download the pdf

#9
Posted 01 September 2010 - 04:48 AM
DarkNSF, on 25 August 2010 - 06:39 PM, said:
http://code.google.com/p/dompdf/
Could you please post sample code of dompdf usage inside Yii?
I've tried code from http://groups.google...bb20c85878d89c1 but it's not very clean with spl_autoload_* stuff and works for me only with version 0.6.0 beta 1 which has some problems rendering my html markup into pdf.
#10
Posted 03 September 2010 - 05:42 PM
Zifius, on 01 September 2010 - 04:48 AM, said:
I've tried code from http://groups.google...bb20c85878d89c1 but it's not very clean with spl_autoload_* stuff and works for me only with version 0.6.0 beta 1 which has some problems rendering my html markup into pdf.
Sure, this is what I use:
<?php Yii::import('application.extensions.pdf.dompdf.*'); require_once(dirname(__FILE__).'/dompdf/dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase','autoload')); spl_autoload_register(array('YiiBase','autoload')); class Pdf { private $_dompdf; private $_html; /** * Init */ public function __construct() { $this->_dompdf = new DOMPDF(); $this->_dompdf->base_path = Yii::app()->request->baseUrl; } /** * set paper size * * @param string $size * @param string $orientation */ public function setSize($size, $orientation='portrait') { $this->_dompdf->set_paper($size, $orientation); } public function renderPartial($view, $params) { $html = Yii::app()->controller->renderPartial($view, $params, true, true); $this->_html .= $html; } public function stream($name) { $this->_dompdf->load_html($this->_html); $this->_dompdf->render(); $this->_dompdf->stream($name); } }
#11
Posted 04 September 2010 - 02:54 AM
For now I went with tcpdf and extension for it (had to finish project quickly) but I will try dompdf too.
Sadly there is no cleaner way of using it. Maybe new version will change something in this regard.
#12
Posted 25 November 2010 - 09:03 AM
DarkNSF, on 25 August 2010 - 06:39 PM, said:
http://code.google.com/p/dompdf/
Hi as a newbie in Yii. How did you set up the dompdf files through your yii setup. Is that the whole downloaded dompdf folder inside extensions and then a dompdf subfolder in controllers ?
Regards,
xavier
#14
Posted 25 November 2010 - 10:07 AM
DarkNSF, on 03 September 2010 - 05:42 PM, said:
<?php Yii::import('application.extensions.pdf.dompdf.*'); require_once(dirname(__FILE__).'/dompdf/dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase','autoload')); spl_autoload_register(array('YiiBase','autoload')); class Pdf { private $_dompdf; private $_html; /** * Init */ public function __construct() { $this->_dompdf = new DOMPDF(); $this->_dompdf->base_path = Yii::app()->request->baseUrl; } /** * set paper size * * @param string $size * @param string $orientation */ public function setSize($size, $orientation='portrait') { $this->_dompdf->set_paper($size, $orientation); } public function renderPartial($view, $params) { $html = Yii::app()->controller->renderPartial($view, $params, true, true); $this->_html .= $html; } public function stream($name) { $this->_dompdf->load_html($this->_html); $this->_dompdf->render(); $this->_dompdf->stream($name); } }
How do you cope with images ?
#15
Posted 27 January 2011 - 03:08 AM
DarkNSF, on 03 September 2010 - 05:42 PM, said:
<?php Yii::import('application.extensions.pdf.dompdf.*'); require_once(dirname(__FILE__).'/dompdf/dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase','autoload')); spl_autoload_register(array('YiiBase','autoload')); class Pdf { private $_dompdf; private $_html; /** * Init */ public function __construct() { $this->_dompdf = new DOMPDF(); $this->_dompdf->base_path = Yii::app()->request->baseUrl; } /** * set paper size * * @param string $size * @param string $orientation */ public function setSize($size, $orientation='portrait') { $this->_dompdf->set_paper($size, $orientation); } public function renderPartial($view, $params) { $html = Yii::app()->controller->renderPartial($view, $params, true, true); $this->_html .= $html; } public function stream($name) { $this->_dompdf->load_html($this->_html); $this->_dompdf->render(); $this->_dompdf->stream($name); } }
I can't get Yii to cope with loading DomPdf. I created sample controller action as follows:
public function actionIndexTest() { Yii::import('application.extensions.pdf.dompdf.*'); require_once('dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase', 'autoload')); spl_autoload_register(array('YiiBase', 'autoload')); $dompdf = new DOMPDF(); }
and I get:
YiiBase::include(DOMPDF.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory
How to fix that ? I've tried many include combinations and all of them yield the same include error message.
dompdf_config.inc.php has not been edited.
#16
Posted 27 January 2011 - 04:27 AM
proto, on 27 January 2011 - 03:08 AM, said:
public function actionIndexTest() { Yii::import('application.extensions.pdf.dompdf.*'); require_once('dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase', 'autoload')); spl_autoload_register(array('YiiBase', 'autoload')); $dompdf = new DOMPDF(); }
and I get:
YiiBase::include(DOMPDF.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory
How to fix that ? I've tried many include combinations and all of them yield the same include error message.
dompdf_config.inc.php has not been edited.
I got it. I found suitable spl load and unload:
public function actionIndexTest() { Yii::import('application.extensions.pdf.dompdf.*'); require_once('dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase', 'autoload')); spl_autoload_register('DOMPDF_autoload'); $dompdf = new DOMPDF(); }
#17
Posted 19 March 2011 - 06:15 PM
DarkNSF, on 11 February 2010 - 05:47 PM, said:
A bit off-topic or forked question. If you prefer XHTML, how do you force browser to print-out what you just generated? Or maybe you leave clicking on "Print" to the user? I heard that there were a bunch of JS code for forcing printing out of a webpage, without user interaction, but there were not cross-browsers compatibility.
BTW: Any idea for what reason you get -3? For asking a really good question? Hm... seems we have more and more strange people in this forum.
#18
Posted 22 March 2011 - 01:01 PM
Strict Standards: require_once() [function.require-once]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set()function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/dompdf_config.inc.php on line 208
Warning: require_once(/home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/include/coutputprocessor.cls.php) [function.require-once]: failed to open stream: No such file or directory in /home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/dompdf_config.inc.php on line 208
Strict Standards: require_once() [function.require-once]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/dompdf_config.inc.php on line 208
Fatal error: require_once() [function.require]: Failed opening required '/home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/include/coutputprocessor.cls.php' (include_path='.:/home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf:/home/farberam/public_html/BuilderApp/public_html/protected/extensions:/home/farberam/public_html/BuilderApp/public_html/protected/helpers:/home/farberam/public_html/BuilderApp/public_html/protected/components:/home/farberam/public_html/BuilderApp/public_html/protected/models:/usr/lib/php:/usr/local/lib/php') in /home/farberam/public_html/BuilderApp/public_html/protected/extensions/pdf/dompdf/dompdf_config.inc.php on line 208
I'm using DarkNSF's example with only a couple of minor changes...
<?php Yii::import('ext.pdf.dompdf.*'); require_once('dompdf_config.inc.php'); spl_autoload_unregister(array('YiiBase','autoload')); spl_autoload_register('DOMPDF_autoload'); class Pdf { private $_dompdf; private $_html; /** * Init */ public function __construct() { $this->_dompdf = new dompdf(); $this->_dompdf->base_path = Yii::app()->request->baseUrl; } /** * set paper size * * @param string $size * @param string $orientation */ public function setSize($size, $orientation='portrait') { $this->_dompdf->set_paper($size, $orientation); } public function renderPartial($view, $params) { $html = Yii::app()->controller->renderPartial($view, $params, true, true); $this->_html .= $html; } public function stream($name) { $this->_dompdf->load_html($this->_html); $this->_dompdf->render(); $this->_dompdf->stream($name); } }
and I call it from the following action in my controller...
public function actionPDF2($invID) { $inventory = $this->loadModel($invID); $fileName = $inventory->communityPlan->community->name.'-Lot#'.$inventory->lotNumber; $params = array('data'=>$inventory) $pdf = new Pdf(); $pdf->renderPartial('pdfview', $params); $pdf->stream($fileName); }
Here is the function that contains line 208 that the errors are referring to...
function DOMPDF_autoload($class) { $filename = mb_strtolower($class) . ".cls.php"; require_once(DOMPDF_INC_DIR . "/$filename"); }
Anyone have any ideas of what I'm doing wrong?
Thanks in advance!
#19
Posted 01 June 2012 - 03:19 PM
When Yiiframework will have a widget to generate the pdf anyway

this topics started in 2010, now the framework changed a lot.
and the way to create components too.
PHP with Yii devel.
#20
Posted 01 June 2012 - 03:33 PM
