0, 'right' => 0, 'top' => 0, 'bottom' => 0);
protected $_outputWidth = 1274;
protected $_outputLandscape = false;
protected $_sourceType = 'url';
protected $_source = null;
protected $_options = null;
public function __construct($options = null, $source = null, $output = null)
{
if (!is_null($options)) {
$this->_options = $options;
}
if (!is_null($source)) {
if (!$this->setSource($source)) {
return false;
}
}
if (!is_null($output)) {
if (!$this->setOutput($output)) {
return false;
}
}
}
public function setSource($source)
{
if (isset($source['type']) && !is_null($source['type'])) {
if (!in_array($source['type'], $this->_allowedSourceTypes)) {
$this->errors[] = "Source type '{$source['type']}' is disallowed";
return false;
}
$this->_sourceType = $source['type'];
}
if ($source['type'] == 'url') {
if (isset($source['name']) && !is_null($source['name'])) {
$this->_source = $source['name'];
} else {
$this->errors[] = "Source name should not be blank";
return false;
}
} elseif ($source['type'] == 'memory') {
$this->_source = str_replace('userfiles/images', 'userfiles/files', $source['content']);
}
return true;
}
public function setOutput($output)
{
if (isset($output['type']) && !is_null($output['type'])) {
if (!in_array($output['type'], $this->_allowedOutputTypes)) {
$this->errors[] = "Output type '{$output['type']}' is disallowed";
return false;
}
$this->_outputType = $output['type'];
}
if (isset($output['name']) && !is_null($output['name'])) {
$this->_output = $output['name'];
} elseif($this->_outputType == 'file') {
$this->errors[] = "Output file name should not be empty";
return false;
}
foreach ($output as $variable => $value) {
if (!in_array($variable, array('name', 'type'))) {
$propertyName = '_output' . ucfirst($variable);
if (property_exists($this, $propertyName)) {
$this->$propertyName = $value;
}
}
}
return true;
}
public function render()
{
parse_config_file(BASE_PATH . '/lib/html2pdf/html2ps.config');
global $g_config, $g_px_scale, $g_pt_scale;
$g_config = array(
'cssmedia' => isset($this->_options['cssmedia'])?$this->_options['cssmedia']:'screen',
'renderimages' => isset($this->_options['renderimages'])?$this->_options['renderimages']:true,
'renderforms' => isset($this->_options['renderforms'])?$this->_options['renderforms']:false,
'renderlinks' => isset($this->_options['renderlinks'])?$this->_options['renderlinks']:true,
'renderfields' => isset($this->_options['renderfields'])?$this->_options['renderfields']:true,
'mode' => isset($this->_options['mode'])?$this->_options['mode']:'html',
'debugbox' => isset($this->_options['debugbox'])?$this->_options['debugbox']:false,
'draw_page_border' => isset($this->_options['draw_page_border'])?$this->_options['draw_page_border']:false,
'scalepoints' => '1',
'encoding' => '',
'pdfversion' => '1.4',
);
$media = &Media::predefined($this->_outputSize);
$media->set_landscape($this->_outputLandscape);
$media->set_margins($this->_outputMargins);
$media->set_pixels($this->_outputWidth);
$g_px_scale = mm2pt($media->width() - $media->margins['left'] - $media->margins['right'])/$media->pixels;
$g_pt_scale = $g_px_scale * 1.43;
$pipeline = PipelineFactory::create_default_pipeline("", "");
foreach ($this->_options['features'] as $feature => $featureOptions){
$pipeline->add_feature($feature, $featureOptions);
}
if (isset($this->_options['headerhtml']) || isset($this->_options['footerhtml'])) {
$filter = new PreTreeFilterHeaderFooter($this->_options['headerhtml'], $this->_options['footerhtml']);
$pipeline->pre_tree_filters[] = $filter;
}
if ($this->_outputType == 'file') {
$pipeline->destination = new Qs_Html2Pdf_Destination_File($this->_output);
}
if ($this->_sourceType == 'url') {
$pipeline->process($this->_source, $media);
} elseif ($this->_sourceType == 'memory') {
$pipeline->fetchers = array(new Qs_Html2Pdf_Source_Memory($this->_source, WWW_PATH));
$pipeline->process_batch(array(''), $media);
} elseif ($this->_sourceType == 'memory') {
$pipeline->fetchers = array(new Qs_Html2Pdf_Source_Memory(@file_get_contents($this->_source), WWW_PATH));
$pipeline->process_batch(array(''), $media);
}
return true;
}
}