Well mPDF proved reliable to me. There’s an extension for it (can be used for HTML2PDF as well)
Well mPDF proved reliable to me. There’s an extension for it (can be used for HTML2PDF as well)
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.
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;
}
}
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