View source
<?php
$default = variable_get('webform2pdf_default', '');
include_once $default['pdf_lib'] . '/tcpdf.php';
class W2PDF extends TCPDF {
protected $header_logo = array();
protected $header_logo_size = array();
protected $header_string_align = array();
protected $footer_logo = array();
protected $footer_logo_size = array();
protected $footer_string_align = array();
public function setHeaderData($ln = array(), $ls = array(), $hs = '', $hsa = '') {
$this->header_logo = $ln;
$this->header_logo_size = $ls;
$this->header_string = $hs;
$this->header_string_align = $hsa;
}
public function getHeaderData() {
$ret = array();
$ret['logo'] = $this->header_logo;
$ret['logo_size'] = $this->header_logo_size;
$ret['string'] = $this->header_string;
$ret['align'] = $this->header_string_align;
return $ret;
}
public function setFooterData($ln = array(), $ls = array(), $hs = '', $hsa = '') {
$this->footer_logo = $ln;
$this->footer_logo_size = $ls;
$this->footer_string = $hs;
$this->footer_string_align = $hsa;
}
public function getFooterData() {
$ret = array();
$ret['logo'] = $this->footer_logo;
$ret['logo_size'] = $this->footer_logo_size;
$ret['string'] = $this->footer_string;
$ret['align'] = $this->footer_string_align;
return $ret;
}
public function Header() {
$ormargins = $this
->getOriginalMargins();
$headerfont = $this
->getHeaderFont();
$headerdata = $this
->getHeaderData();
$imgy['left'] = $imgy['right'] = $this
->GetY();
$header_w = 0;
$empty_header = 1;
if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
if ($headerdata['logo']['left'] and $headerdata['logo']['left'] != K_BLANK_IMAGE) {
$this
->Image(K_PATH_IMAGES . $headerdata['logo']['left'], $this
->GetX(), $this
->getHeaderMargin(), $headerdata['logo_size']['left']['w']);
$imgy['left'] = $this
->getImageRBY();
$empty_header = 0;
}
}
if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
if ($headerdata['logo']['right'] and $headerdata['logo']['right'] != K_BLANK_IMAGE) {
$this
->Image(K_PATH_IMAGES . $headerdata['logo']['right'], $this
->getPageWidth() - $ormargins['right'] - $headerdata['logo_size']['right']['w'], $this
->getHeaderMargin(), $headerdata['logo_size']['right']['w']);
$header_w = $this
->getPageWidth() - $ormargins['left'] - $ormargins['right'] - $headerdata['logo_size']['left']['w'] * 1.1 - $headerdata['logo_size']['right']['w'] * 1.1;
$imgy['right'] = $this
->getImageRBY();
$empty_header = 0;
}
}
$cell_height = round($this
->getCellHeightRatio() * $headerfont[2] / $this
->getScaleFactor(), 2);
if ($this
->getRTL()) {
$header_x = $ormargins['right'] + $headerdata['logo_size']['right']['w'] * 1.1;
}
else {
$header_x = $ormargins['left'] + $headerdata['logo_size']['left']['w'] * 1.1;
}
$this
->SetTextColor(0, 0, 0);
$this
->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
$this
->SetX($header_x);
if (!empty($headerdata['string'])) {
$empty_header = 0;
}
$this
->writeHTMLCell($header_w, $cell_height, '', '', $headerdata['string'], 0, 1, 0, TRUE, $headerdata['align']);
$this
->SetLineStyle(array(
'width' => 0.85 / $this
->getScaleFactor(),
'cap' => 'butt',
'join' => 'miter',
'dash' => 0,
'color' => array(
0,
0,
0,
),
));
$this
->SetY(1 + max($imgy['left'], $this
->GetY()));
$this
->SetY(1 + max($imgy['right'], $this
->GetY()));
if ($this
->getRTL()) {
$this
->SetX($ormargins['right']);
}
else {
$this
->SetX($ormargins['left']);
}
if (!$empty_header) {
$this
->Cell(0, 0, '', 'T', 0, 'C');
}
$this
->SetTopMargin($this
->GetY() + 1);
}
public function Footer() {
$ormargins = $this
->getOriginalMargins();
$footerfont = $this
->getFooterFont();
$footerdata = $this
->getFooterData();
$imgy['left'] = $imgy['right'] = $this
->GetY();
$footer_w = 0;
$empty_footer = 1;
$cell_height = 18;
if (!empty($footerdata['logo_size']['left']['h']) || !empty($footerdata['logo_size']['right']['h'])) {
$this
->SetY($this
->GetY() - $cell_height);
}
else {
$this
->SetY($this
->GetY() - $cell_height);
}
if (!empty($footerdata['logo']['left']) && !empty($footerdata['logo_size']['left']['w'])) {
if ($footerdata['logo']['left'] and $footerdata['logo']['left'] != K_BLANK_IMAGE) {
$this
->Image(K_PATH_IMAGES . $footerdata['logo']['left'], $this
->GetX(), $this
->GetY(), $footerdata['logo_size']['left']['w']);
$imgy['left'] = $this
->getImageRBY();
$empty_footer = 0;
}
}
if (!empty($footerdata['logo']['left']) && !empty($footerdata['logo_size']['left']['w'])) {
if ($footerdata['logo']['right'] and $footerdata['logo']['right'] != K_BLANK_IMAGE) {
$this
->Image(K_PATH_IMAGES . $footerdata['logo']['right'], $this
->getPageWidth() - $ormargins['right'] - $footerdata['logo_size']['right']['w'], $this
->GetY(), $footerdata['logo_size']['right']['w']);
$footer_w = $this
->getPageWidth() - $ormargins['left'] - $ormargins['right'] - $footerdata['logo_size']['left']['w'] * 1.1 - $footerdata['logo_size']['right']['w'] * 1.1;
$imgy['right'] = $this
->getImageRBY();
$empty_footer = 0;
}
}
$this
->SetTextColor(0, 0, 0);
$this
->SetY($this
->GetY() - 1);
if ($this
->getRTL()) {
$footer_x = $ormargins['right'] + $footerdata['logo_size']['right']['w'] * 1.1;
}
else {
$footer_x = $ormargins['left'] + $footerdata['logo_size']['left']['w'] * 1.1;
}
$this
->SetX($footer_x);
$line_width = 0.85 / $this
->getScaleFactor();
$this
->SetLineStyle(array(
'width' => $line_width,
'cap' => 'butt',
'join' => 'miter',
'dash' => 0,
'color' => array(
0,
0,
0,
),
));
$page_var = array(
"%pagenumber" => $this
->PageNoFormatted(),
"%totalpage" => $this
->getAliasNbPages(),
);
$footerdata['string'] = strtr($footerdata['string'], $page_var);
$this
->SetFont($footerfont[0], $footerfont[1], $footerfont[2]);
if (!empty($footerdata['string'])) {
$empty_footer = 0;
}
$this
->writeHTMLCell($footer_w, $cell_height, '', '', $footerdata['string'], 0, 0, 0, TRUE, $footerdata['align']);
if ($this
->getRTL()) {
$this
->SetX($ormargins['right']);
}
else {
$this
->SetX($ormargins['left']);
}
if (!$empty_footer) {
$this
->Cell(0, 0, '', 'T', 0, 'C');
}
}
}