Yii Framework Forum: To PDF or not to PDF - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

To PDF or not to PDF Rate Topic: -----

#1 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 11 February 2010 - 05:47 PM

I've looked in to a few interfaces to PDF generation. None of them seem as great as I was hoping for. So after doing all of this research, I am starting to think that there is little to no benefit of a PDF file.

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?
0

#2 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 12 February 2010 - 02:29 AM

I just did a lot of work with pdf generation and I haven't found anything good that's free.. I'm using TCPDF but it kinda sucks. I also considered generating Excel files and converting them to PDFs with PHPExcel but not much formatting converts.

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.
http://php-thoughts.cubedwater.com - my bloggings about Yii
1

#3 User is offline   basva 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 19-August 09

Posted 13 February 2010 - 11:48 PM

I am using wkhtmltopdf at the moment. Needs X and uses some resources, but PDF creation couldn't be simpler and the result is very beautiful.

http://code.google.com/p/wkhtmltopdf/

It basically is the same as having a webkit browser doing 'print to pdf'.

Bas
0

#4 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 15 February 2010 - 03:14 PM

wkhtmltopdf looks really good but I'm not really sure how I can get it running through php on both my local windows server and my shared linux server
http://php-thoughts.cubedwater.com - my bloggings about Yii
0

#5 User is offline   e_t_k 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 09-January 09
  • Location:Poland

Posted 16 February 2010 - 04:36 AM

View PostDarkNSF, on 11 February 2010 - 05:47 PM, said:

[...]None of them seem as great as I was hoping for. [...]what does generating a PDF for a standard form give you over just generating XHTML?

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.
0

#6 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 313
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 25 February 2010 - 08:32 PM

View PostDarkNSF, on 11 February 2010 - 05:47 PM, said:

I guess my question is.. what does generating a PDF for a standard form give you over just generating XHTML?


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.
0

#7 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 25 August 2010 - 06:39 PM

I ended up using DOMPDF, seems to be the best of the best. Has high activity, so I have hope for it.


http://code.google.com/p/dompdf/
0

#8 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 26 August 2010 - 01:48 AM

View PostDarkNSF, on 25 August 2010 - 06:39 PM, said:

I ended up using DOMPDF, seems to be the best of the best. Has high activity, so I have hope for it.


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 ;)
0

#9 User is offline   Zifius 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 30-April 10

Posted 01 September 2010 - 04:48 AM

View PostDarkNSF, on 25 August 2010 - 06:39 PM, said:

I ended up using DOMPDF, seems to be the best of the best. Has high activity, so I have hope for it.


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.
0

#10 User is offline   DarkNSF 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 287
  • Joined: 12-November 08
  • Location:Palm Bay, Florida

Posted 03 September 2010 - 05:42 PM

View PostZifius, on 01 September 2010 - 04:48 AM, said:

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.




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);
  }
}

0

#11 User is offline   Zifius 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 30-April 10

Posted 04 September 2010 - 02:54 AM

Thanks for reply!
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.
0

#12 User is offline   xav 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 09-August 10

Posted 25 November 2010 - 09:03 AM

View PostDarkNSF, on 25 August 2010 - 06:39 PM, said:

I ended up using DOMPDF, seems to be the best of the best. Has high activity, so I have hope for it.


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
0

#13 User is offline   xav 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 09-August 10

Posted 25 November 2010 - 09:52 AM

View Postxav, on 25 November 2010 - 09:03 AM, said:

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



okay, i think I've found the way.
0

#14 User is offline   xav 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 09-August 10

Posted 25 November 2010 - 10:07 AM

View PostDarkNSF, on 03 September 2010 - 05:42 PM, said:

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);
  }
}



How do you cope with images ?
0

#15 User is offline   proto 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 02-November 10
  • Location:Switzerland

Posted 27 January 2011 - 03:08 AM

View PostDarkNSF, on 03 September 2010 - 05:42 PM, said:

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);
  }
}




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.
0

#16 User is offline   proto 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 02-November 10
  • Location:Switzerland

Posted 27 January 2011 - 04:27 AM

View Postproto, on 27 January 2011 - 03:08 AM, said:

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.


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();
}

0

#17 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 19 March 2011 - 06:15 PM

View PostDarkNSF, on 11 February 2010 - 05:47 PM, said:

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.


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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
1

#18 User is offline   Farberama 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 17-November 10

Posted 22 March 2011 - 01:01 PM

I'm trying to use dompdf but I keep getting the following errors...

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!
0

#19 User is offline   radames_ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 06-October 11
  • Location:São Paulo - Brazil

Posted 01 June 2012 - 03:19 PM

So,

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.
Radamés Galvao
PHP with Yii devel.
0

#20 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,219
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 01 June 2012 - 03:33 PM

I'd guess most people still use tcpdf. Sadly, it's still the most matured PHP lib for PDF generation <_<
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users