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: -----

#21 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 01 June 2012 - 04:22 PM

Well mPDF proved reliable to me. There's an extension for it (can be used for HTML2PDF as well)
0

#22 User is offline   Tsunami 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 16-February 12

Posted 16 August 2012 - 09:45 AM

Since this topic is still alive, here's the bare minimum to get DOMPDF working (I use the same technique to temporarily get Smarty working in another project).
I copied the DOMPDF_autoload function and manually registered it as an autoloader. Then I simply include dompdf_config.inc.php and all is well :)

Save the code below as protected/components/DOMPDF.php and Yii will autoload it when you call new DOMPDF().

// DOMPDF_autoload
Yii::registerAutoloader(function($class) {
  $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";
  
  if ( is_file($filename) )
    require_once($filename);
});


require Yii::getPathOfAlias('application.vendors.dompdf') . '/dompdf_config.inc.php';

Of course a wrapper class for rendering the HTML (as DarkNSF posted) is nice too, so you could add that to the bottom of this code.
0

#23 User is offline   Paul_Kish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 25-October 12
  • Location:Nairobi,Kenya

Posted 08 February 2013 - 02:03 AM

I ended up implementing this as Tsunami had mentioned above

<?php

// DOMPDF_autoload
Yii::registerAutoloader(function($class) {
  $filename = DOMPDF_INC_DIR . "/" . mb_strtolower($class) . ".cls.php";
  
  if ( is_file($filename) )
    require_once($filename);
});

require Yii::getPathOfAlias('ext.dompdf').DIRECTORY_SEPARATOR.'dompdf_config.inc.php';

class Pdf
{
  private $_dompdf;
  
  private $_html;
  
  public $output;
  
  /**
   * 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, false);
    $this->_html .= $html;
  }
  
  public function stream($name)
  {
    $this->_dompdf->load_html($this->_html);
    $this->_dompdf->render();
    $this->_dompdf->stream($name);
  }
  //Returning pdf output as a stream, e,g when using you want to send pdf as attachment in emails
  public function output()
  {
    $this->_dompdf->load_html($this->_html);
    $this->_dompdf->render();
    $this->output = $this->_dompdf->output();
    return $this->output;
  }
}

"Live without Regret"- Fire Fist Ace
@Paul_Kish
0

#24 User is offline   airmaxs19841 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-April 13

Posted 06 May 2013 - 07:49 AM

Oh my goodness! an amazing article dude. Thank you However My business is experiencing issue with ur rss. Don’t know why Struggling to subscribe to it. Is there anyone having identical rss problem? Anyone who knows kindly respond. Thnkx
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