public function output($file = null) { ob_clean(); $this->pdf = new PDFDocument($this->orientation, $this->paper); $this->pdfPreCustomize(); $this->pdf->showPageNumbers = $this->showPageNumbers; $this->pdf->showFooter = $this->showFooter; foreach ($this->contents as $key => $content) { if ($content == null) { continue; } if (is_string($content)) { switch ($content) { case "NEW_PAGE": $this->pdf->AddPage(); break; case "RESET_PAGE_NUMBERS": $this->pdf->resetPageNumbers(); break; } continue; } switch ($content->getType()) { case "text": if (isset($content->style["color"])) { $this->pdf->SetTextColor($content->style["color"][0], $content->style["color"][1], $content->style["color"][2]); } else { $this->pdf->SetTextColor(0, 0, 0); } $this->pdf->SetFont($content->style["font"], ($content->style["bold"] ? "B" : "") . ($content->style["underline"] ? "U" : "") . ($content->style["italics"] ? "I" : ""), $content->style["size"]); if (isset($content->style["top_margin"])) { $this->pdf->Ln($content->style["top_margin"]); } if ($content->style["flow"]) { $this->pdf->WriteHTML($content->style['line_height'] == '' ? $content->style["size"] * 0.353 + 1 : $content->style['line_height'], $content->getText()); $this->pdf->Ln(); } else { $this->pdf->SetFillColor(180, 200, 180); $this->pdf->Cell(0, isset($content->style["height"]) ? $content->style["height"] : $content->style["size"] * 0.353 + 1, $content->getText(), 0, 0, $content->style["align"], $content->style["fill"]); $this->pdf->Ln(); } if (isset($content->style["bottom_margin"])) { $this->pdf->Ln($content->style["bottom_margin"]); } break; case "attributes": $this->pdf->attributeBox($content->data, $content->style); break; case "table": if ($content->style["totalsBox"] == true) { $this->pdf->totalsBox($content->getData(), $content->data_params); } else { if ($content->style["autoTotalsBox"]) { $this->pdf->table($content->getHeaders(), $content->getData(), $content->style, $content->data_params); $totals = $content->getTotals(); $totals[0] = "Totals"; $this->pdf->totalsBox($totals, $content->data_params); } else { $this->pdf->table($content->getHeaders(), $content->getData(), $content->style, $content->data_params); $this->contents[$key] = $content; } } break; case "image": $this->pdf->image($content->image, null, null, $content->width, $content->height); break; case "logo": $this->pdf->image($content->image, null, null, 8, 8); //print $this->pdf->getY(); $this->pdf->sety($this->pdf->getY() - 8); $this->pdf->SetFont("Times", "B", "18"); $this->pdf->cell(9); $this->pdf->cell(0, 8, $content->title); $this->pdf->SetFont("Arial", null, 7); //print $this->pdf->getY(); //$this->pdf->sety(10); foreach ($content->address as $address) { $this->pdf->setx(($this->pdf->GetStringWidth($address) + 10) * -1); $this->pdf->cell(0, 3, $address); $this->pdf->Ln(); } $this->pdf->Ln(5); } } $this->pdfPostCustomize(); if ($file == null) { $this->pdf->Output(); die; } else { $this->pdf->Output($file); } }
/** * Object constructor. * Constructor signatures: * * 1. Load PDF page from a parsed PDF file. * Object factory is created by PDF parser. * --------------------------------------------------------- * new Zend_PDF_Page(\Zend\PDF\InternalType\DictionaryObject $pageDict, * \Zend\PDF\InternalType\ObjectFactory\ObjectFactoryInterface $factory); * --------------------------------------------------------- * * 2. Clone PDF page. * New page is created in the same context as source page. Object factory is shared. * Thus it will be attached to the document, but need to be placed into Zend_PDF::$pages array * to be included into output. * --------------------------------------------------------- * new Zend_PDF_Page(Zend_PDF_Page $page); * --------------------------------------------------------- * * 3. Create new page with a specified pagesize. * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_PDF_Page(string $pagesize, \Zend\PDF\ObjectFactory\ObjectFactoryInterface $factory = null); * --------------------------------------------------------- * * 4. Create new page with a specified pagesize (in default user space units). * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_PDF_Page(numeric $width, numeric $height, * \Zend\PDF\ObjectFactory\ObjectFactotyInterface $factory = null); * --------------------------------------------------------- * * * @param mixed $param1 * @param mixed $param2 * @param mixed $param3 * @throws \Zend\PDF\Exception */ public function __construct($param1, $param2 = null, $param3 = null) { if ($param1 instanceof InternalType\IndirectObjectReference && $param1->getType() == InternalType\AbstractTypeObject::TYPE_DICTIONARY && $param2 instanceof ObjectFactory\ObjectFactoryInterface && $param3 === null) { $this->_pageDictionary = $param1; $this->_objFactory = $param2; $this->_attached = true; $this->_safeGS = false; return; } else { if ($param1 instanceof Page && $param2 === null && $param3 === null) { // Clone existing page. // Let already existing content and resources to be shared between pages // We don't give existing content modification functionality, so we don't need "deep copy" $this->_objFactory = $param1->_objFactory; $this->_attached =& $param1->_attached; $this->_safeGS = false; $this->_pageDictionary = $this->_objFactory->newObject(new InternalType\DictionaryObject()); foreach ($param1->_pageDictionary->getKeys() as $key) { if ($key == 'Contents') { // Clone Contents property $this->_pageDictionary->Contents = new InternalType\ArrayObject(); if ($param1->_pageDictionary->Contents->getType() != InternalType\AbstractTypeObject::TYPE_ARRAY) { // Prepare array of content streams and add existing stream $this->_pageDictionary->Contents->items[] = $param1->_pageDictionary->Contents; } else { // Clone array of the content streams foreach ($param1->_pageDictionary->Contents->items as $srcContentStream) { $this->_pageDictionary->Contents->items[] = $srcContentStream; } } } else { $this->_pageDictionary->{$key} = $param1->_pageDictionary->{$key}; } } return; } else { if (is_string($param1) && ($param2 === null || $param2 instanceof ObjectFactory\ObjectFactoryInterface) && $param3 === null) { if ($param2 !== null) { $this->_objFactory = $param2; } else { $this->_objFactory = ObjectFactory\ObjectFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; /** New page created. That's users App responsibility to track GS changes */ switch (strtolower($param1)) { case 'a4': $param1 = self::SIZE_A4; break; case 'a4-landscape': $param1 = self::SIZE_A4_LANDSCAPE; break; case 'letter': $param1 = self::SIZE_LETTER; break; case 'letter-landscape': $param1 = self::SIZE_LETTER_LANDSCAPE; break; default: // should be in "x:y" or "x:y:" form } $pageDim = explode(':', $param1); if (count($pageDim) == 2 || count($pageDim) == 3) { $pageWidth = $pageDim[0]; $pageHeight = $pageDim[1]; } else { /** * @todo support of user defined pagesize notations, like: * "210x297mm", "595x842", "8.5x11in", "612x792" */ throw new Exception('Wrong pagesize notation.'); } /** * @todo support of pagesize recalculation to "default user space units" */ } else { if (is_numeric($param1) && is_numeric($param2) && ($param3 === null || $param3 instanceof ObjectFactory\ObjectFactoryInterface)) { if ($param3 !== null) { $this->_objFactory = $param3; } else { $this->_objFactory = ObjectFactory\ObjectFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; /** New page created. That's users App responsibility to track GS changes */ $pageWidth = $param1; $pageHeight = $param2; } else { throw new Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.'); } } } } $this->_pageDictionary = $this->_objFactory->newObject(new InternalType\DictionaryObject()); $this->_pageDictionary->Type = new InternalType\NameObject('Page'); $this->_pageDictionary->LastModified = new InternalType\StringObject(PDFDocument::pdfDate()); $this->_pageDictionary->Resources = new InternalType\DictionaryObject(); $this->_pageDictionary->MediaBox = new InternalType\ArrayObject(); $this->_pageDictionary->MediaBox->items[] = new InternalType\NumericObject(0); $this->_pageDictionary->MediaBox->items[] = new InternalType\NumericObject(0); $this->_pageDictionary->MediaBox->items[] = new InternalType\NumericObject($pageWidth); $this->_pageDictionary->MediaBox->items[] = new InternalType\NumericObject($pageHeight); $this->_pageDictionary->Contents = new InternalType\ArrayObject(); }