orientation = $orientation; $this->showHeader = false; $this->showFooter = false; // does show effect in standalone adobe application viewer only $this->SetDisplayMode('fullpage'); // no effect so far $this->setViewerPreferences(array('FitWindow' => true)); // page size in mm $this->pageSize = visformsTCPDF_STATIC::getPageSizeFromFormat($format); $this->pageSize[0] = (int) $this->pageSize[0] * 25.4 / 72; $this->pageSize[1] = (int) $this->pageSize[1] * 25.4 / 72 ; // page number placeholders need this to work as expected $this->setHeaderTemplateAutoreset(true); } // getter and setter public function setHeaderTemplate($hdrTemplate) { $this->headerTemplate = $hdrTemplate; } public function setShowHeader($show) { $this->showHeader = $show; } public function setFooterTemplate($ftrTemplate) { $this->footerTemplate = $ftrTemplate; } public function setShowFooter($show) { $this->showFooter = $show; } public function setBackgroundImage($backgroundImage) { // todo: check final image path like '/' or 'something/somewhat/' $this->backgroundImage = $backgroundImage; } public function setShowBackgroundImage($show) { $this->showBackgroundImage = $show; } // overwrites public function Header() { if($this->showBackgroundImage && !empty($this->backgroundImage)) { $this->insertBackgroundImage(); } if( !$this->showHeader) { return; } $cw = $this->w - $this->original_lMargin - $this->original_rMargin; $text = $this->processPageNumberText_byAliasReplacement($this->headerTemplate); $this->writeHTMLCell($cw, 0, $this->x, $this->y, $text, 0, 1, 0, true, '', true); } public function Header_UsingTemplate() { if($this->showBackgroundImage && !empty($this->backgroundImage)) { $this->insertBackgroundImage(); } if( !$this->showHeader) { return; } if ($this->header_xobjid === false) { // start a new XObject Template $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin); $headerfont = $this->getHeaderFont(); $this->y = $this->header_margin; if ($this->rtl) { $this->x = $this->w - $this->original_rMargin; } else { $this->x = $this->original_lMargin; } $cw = $this->w - $this->original_lMargin - $this->original_rMargin; $text = $this->processPageNumberText_byAliasReplacement($this->headerTemplate); $this->writeHTMLCell($cw, 0, $this->x, $this->y, $text, 0, 1, 0, true, '', true); $this->endTemplate(); } // print header template $x = 0; $dx = 0; if (!$this->header_xobj_autoreset AND $this->booklet AND (($this->page % 2) == 0)) { // adjust margins for booklet mode $dx = ($this->original_lMargin - $this->original_rMargin); } if ($this->rtl) { $x = $this->w + $dx; } else { $x = 0 + $dx; } $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false); if ($this->header_xobj_autoreset) { // reset header xobject template at each page $this->header_xobjid = false; } } public function Footer() { if( !$this->showFooter) { return; } $cw = $this->w - $this->original_lMargin - $this->original_rMargin; $text = $this->processPageNumberText_byAliasReplacement($this->footerTemplate); $this->writeHTMLCell($cw, 0, $this->x, $this->y, $text, 0, 1, 0, true, '', true); } // internal overwrites protected function openHTMLTagHandler($dom, $key, $cell) { $tag = $dom[$key]; if('img' == $tag['value']) { $file = $tag['attribute']['src']; $file = $this->stripOffImageSourceBase64Identifier($file); $dom[$key]['attribute']['src'] = $file; } return parent::openHTMLTagHandler($dom, $key, $cell); } public function Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array()) { $file = $this->maintainFilePath($file); return parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage, $alt, $altimgs); } public function ImageEps($file, $x='', $y='', $w=0, $h=0, $link='', $useBoundingBox=true, $align='', $palign='', $border=0, $fitonpage=false, $fixoutvals=false) { $file = $this->maintainFilePath($file); return parent::ImageEps($file, $x, $y, $w, $h, $link, $useBoundingBox, $align, $palign, $border, $fitonpage, $fixoutvals); } public function ImageSVG($file, $x='', $y='', $w=0, $h=0, $link='', $align='', $palign='', $border=0, $fitonpage=false) { $file = $this->maintainFilePath($file); return parent::ImageSVG($file, $x, $y, $w, $h, $link, $align, $palign, $border, $fitonpage); } // implementation private function maintainFilePath($file) { $outFile = preg_replace('\'' . JUri::base() . '\'', '', $file); if (!@file_exists($outFile)) { $outFile = JPATH_ROOT . '/' . $file; } if (!@file_exists($outFile)) { $outFile = JPATH_ROOT. '/images/' . $file; } if (!@file_exists($outFile)) { // tcpdf uses proprietary 'escape' character @ to identify binary images $outFile = $this->stripOffImageSourceBase64Identifier($file); } return $outFile; } private function stripOffImageSourceBase64Identifier($url) { return preg_replace('#^data:image/[a-z^;]+;base64,#i', '@', $url);; } private function processPageNumberText_byAliasReplacement($text) { $text = str_replace('[POP]', $this->getAliasNumPage().' / '.$this->getAliasNbPages(), $text); $text = str_replace('[NPS]', $this->getAliasNbPages(), $text); $text = str_replace('[PNR]', $this->getAliasNumPage(), $text); return $text; } private function processPageNumberText_byNumber($text) { $text = str_replace('[POP]', $this->PageNo().' / '.$this->getNumPages(), $text); $text = str_replace('[NPS]', $this->getNumPages(), $text); $text = str_replace('[PNR]', $this->PageNo(), $text); return $text; } private function insertBackgroundImage() { // get the current page break margin $bMargin = $this->getBreakMargin(); // get current auto-page-break mode $auto_page_break = $this->AutoPageBreak; // disable auto-page-break $this->SetAutoPageBreak(false, 0); // set background image: set size according to page format (A1, 2, 3...) and orientation if('P' == $this->orientation) { $this->Image($this->backgroundImage, 0, 0, $this->pageSize[0], $this->pageSize[1], '', '', '', false, 300, '', false, false, 0); } else { $this->Image($this->backgroundImage, 0, 0, $this->pageSize[1], $this->pageSize[0], '', '', '', false, 300, '', false, false, 0); } // keep the comment: example line was: // $this->Image($this->backgroundImage, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0); // restore auto-page-break status $this->SetAutoPageBreak($auto_page_break, $bMargin); // set the starting point for the page content $this->setPageMark(); } }