SetTitle($meta['title']);
if (isset($meta['subject'])) $pdf->SetSubject($meta['subject']);
if (isset($meta['keywords'])) $pdf->SetKeywords($meta['keywords']);
// Make the formatter available, just in case some specialized view wants/needs it
$view->pdf_formatter = $pdf;
ob_start();
$view->display();
$html = ob_get_contents();
ob_end_clean();
$pdf->AddPage();
$pdf->PrintContents($html);
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output($path, $dest);
return $path;
}
}
if(!file_exists(JPATH_VM_LIBRARIES.DS.'tcpdf'.DS.'tcpdf.php')){
vmError('VmPDF helper: For the PDF invoice and other PDF business letters, you must install the tcpdf library at '.JPATH_VM_LIBRARIES.DS.'tcpdf');
} else {
if(!class_exists('TCPDF'))require(JPATH_VM_LIBRARIES.DS.'tcpdf'.DS.'tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer as configured in the Backend
class VmVendorPDF extends TCPDF {
var $vendor = 0;
var $vendorImage = '';
var $vendorAddress = '';
var $css = '';
var $virtuemart_vendor_id = 1;
var $tcpdf6 = false;
public function __construct() {
// Load the vendor, so we have the data for the header/footer...
// The images are NOT loaded by default, so do it manually, just in case
$vendorModel = VmModel::getModel('vendor');
$this->vendor = $vendorModel->getVendor($this->virtuemart_vendor_id);
$vendorModel->addImages($this->vendor,1);
$this->vendor->vendorFields = $vendorModel->getVendorAddressFields();
parent::__construct($this->vendor->vendor_letter_orientation, 'mm', $this->vendor->vendor_letter_format);
$this->css = $this->vendor->vendor_letter_css;
// set document information
$this->SetCreator(JText::_('COM_VIRTUEMART_PDF_CREATOR'));
if(empty($this->vendor->images[0])){
vmError('Vendor image given path empty ');
} else if(empty($this->vendor->images[0]->file_url_folder) or empty($this->vendor->images[0]->file_name) or empty($this->vendor->images[0]->file_extension) ){
vmError('Vendor image given image is not complete '.$this->vendor->images[0]->file_url_folder.$this->vendor->images[0]->file_name.'.'.$this->vendor->images[0]->file_extension);
vmdebug('Vendor image given image is not complete, the given media',$this->vendor->images[0]);
} else if(!empty($this->vendor->images[0]->file_extension) and strtolower($this->vendor->images[0]->file_extension)=='png'){
vmError('Warning extension of the image is a png, tpcdf has problems with that in the header, choose a jpg or gif');
} else {
$imagePath = str_replace('/',DS, $this->vendor->images[0]->file_url_folder.$this->vendor->images[0]->file_name.'.'.$this->vendor->images[0]->file_extension);
if(!file_exists(JPATH_ROOT . DS . $imagePath)){
vmError('Vendor image missing '.$imagePath);
} else {
$this->vendorImage=$imagePath;
}
}
// Generate PDF header
if (!class_exists ('JFile')) {
require(JPATH_VM_LIBRARIES . DS . 'joomla' . DS . 'filesystem' . DS . 'file.php');
}
$this->tcpdf6 = JFile::exists(JPATH_VM_LIBRARIES.DS.'tcpdf'.DS.'include'.DS.'tcpdf_colors.php');
if($this->tcpdf6){
$this->tcpdf6 = method_exists('TCPDF','getAllSpotColors');
}
if($this->tcpdf6){
$getAllSpotColors = TCPDF::getAllSpotColors();
$vlfooterlcolor = TCPDF_COLORS::convertHTMLColorToDec($this->vendor->vendor_letter_footer_line_color,$getAllSpotColors);
} else {
$vlfooterlcolor = $this->convertHTMLColorToDec($this->vendor->vendor_letter_footer_line_color);
}
$this->setHeaderData(($this->vendor->vendor_letter_header_image?$this->vendorImage:''),
($this->vendor->vendor_letter_header_image?$this->vendor->vendor_letter_header_imagesize:0),
'', $this->vendor->vendor_letter_header_html,
array(0,0,0),$vlfooterlcolor );
$this->vendorAddress = shopFunctions::renderVendorAddress($this->vendor->virtuemart_vendor_id, "
");
// Trim the final
from the address, which is inserted by renderVendorAddress automatically!
if (substr($this->vendorAddress, -5, 5) == '
') {
$this->vendorAddress = substr($this->vendorAddress, 0, -5);
}
$vmFont=$this->vendor->vendor_letter_font;
$this->SetFont($vmFont, '', $this->vendor->vendor_letter_font_size, '', 'false');
$this->setHeaderFont(Array($vmFont, '', $this->vendor->vendor_letter_header_font_size ));
$this->setFooterFont(Array($vmFont, '', $this->vendor->vendor_letter_footer_font_size ));
// Remove all vertical margins and padding from the HTML cells (default is excessive padding):
$this->SetCellPadding(0);
$tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
'div' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
'h1' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
'h2' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
'h3' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
'table' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)),
);
$this->setHtmlVSpace($tagvs);
// set default font subsetting mode
$this->setFontSubsetting(true);
// set default monospaced font
// $this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$this->SetMargins($this->vendor->vendor_letter_margin_left, $this->vendor->vendor_letter_margin_top, $this->vendor->vendor_letter_margin_right);
$this->SetHeaderMargin($this->vendor->vendor_letter_margin_header);
$this->SetFooterMargin($this->vendor->vendor_letter_margin_footer);
$this->SetAutoPageBreak(TRUE, $this->vendor->vendor_letter_margin_bottom);
//set image scale factor
$this->setImageScale(PDF_IMAGE_SCALE_RATIO);
//TODO include the right file (in libraries/tcpdf/config/lang set some language-dependent strings
$l='';
$this->setLanguageArray($l);
}
/** Replace variables like {vm:page}, {vm:pagecount} etc. in the given string
*/
function replace_variables($txt) {
// TODO: Implement more Placeholders (ordernr, invoicenr, etc.)
// Use PageNo rather than getAliasNumPage, since the alias will be misaligned (spaced like the {:npn:} text rather than the final number)
$txt = str_replace('{vm:pagenum}', $this->/*getAliasNumPage*/PageNo(), $txt);
// Can't use getNumPages, because when this is evaluated, we don't know the final number of pages (getNumPages is always equal to the current page numbe)
$txt = str_replace('{vm:pagecount}', $this->getAliasNbPages/*getNumPages*/(), $txt);
$txt = str_replace('{vm:vendorname}', $this->vendor->vendor_store_name, $txt);
$imgrepl='';
if (!empty($this->vendor->images)) {
$img = $this->vendor->images[0];
$imgrepl = "