public function getPdf($creditmemos = array())
 {
     $this->_beforeGetPdf();
     $this->_initRenderer('creditmemo');
     $pdf = new Zend_Pdf();
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($creditmemos as $creditmemo) {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $creditmemo->getOrder();
         /* Add image */
         $this->insertLogo($page, $creditmemo->getStore());
         /* Add address */
         $this->insertAddress($page, $creditmemo->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID, $order->getStoreId()));
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page);
         $page->drawText(Mage::helper('sales')->__('Credit Memo # ') . $creditmemo->getIncrementId(), 35, 780, 'UTF-8');
         /* Add table head */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
         $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
         $page->setLineWidth(0.5);
         $page->drawRectangle(25, $this->y, 570, $this->y - 15);
         $this->y -= 10;
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
         $this->_drawHeader($page);
         $this->y -= 15;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($creditmemo->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             $shift = array();
             if ($this->y < 20) {
                 /* Add new table head */
                 $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
                 $pdf->pages[] = $page;
                 $this->y = 800;
                 $this->_setFontRegular($page);
                 $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
                 $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
                 $page->setLineWidth(0.5);
                 $page->drawRectangle(25, $this->y, 570, $this->y - 15);
                 $this->y -= 10;
                 $this->_drawHeader($page);
                 $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                 $this->y -= 20;
             }
             /* Draw item */
             $this->_drawItem($item, $page, $order);
         }
         /* Add totals */
         $this->insertTotals($page, $creditmemo);
     }
     $this->_afterGetPdf();
     return $pdf;
 }
 /**
  * Print label for one specific shipment
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     try {
         $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
         $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
         $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
         $shipment = $this->shipmentLoader->load();
         $labelContent = $shipment->getShippingLabel();
         if ($labelContent) {
             $pdfContent = null;
             if (stripos($labelContent, '%PDF-') !== false) {
                 $pdfContent = $labelContent;
             } else {
                 $pdf = new \Zend_Pdf();
                 $page = $this->labelGenerator->createPdfPageFromImageString($labelContent);
                 if (!$page) {
                     $this->messageManager->addError(__('We don\'t recognize or support the file extension in this shipment: %1.', $shipment->getIncrementId()));
                 }
                 $pdf->pages[] = $page;
                 $pdfContent = $pdf->render();
             }
             return $this->_fileFactory->create('ShippingLabel(' . $shipment->getIncrementId() . ').pdf', $pdfContent, DirectoryList::VAR_DIR, 'application/pdf');
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('An error occurred while creating shipping label.'));
     }
     $this->_redirect('adminhtml/order_shipment/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
 }
Example #3
0
 /**
  * Creates a PDF report from the Minutes model given.
  * Returns the PDF as a string that can either be saved to disk
  * or streamed back to the browser.
  *
  * @param Phprojekt_Model_Interface $minutesModel The minutes model object to create the PDF from.
  *
  * @return string The resulting PDF document.
  */
 public static function getPdf(Phprojekt_Model_Interface $minutesModel)
 {
     $phpr = Phprojekt::getInstance();
     $pdf = new Zend_Pdf();
     $page = new Phprojekt_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
     $pages = array($page);
     $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 12);
     $page->setBorder(2.0 * Phprojekt_Pdf_Page::PT_PER_CM, 2.0 * Phprojekt_Pdf_Page::PT_PER_CM, 2.0 * Phprojekt_Pdf_Page::PT_PER_CM, 3.0 * Phprojekt_Pdf_Page::PT_PER_CM);
     $page->addFreetext(array('lines' => $minutesModel->title, 'fontSize' => 20));
     $page->addFreetext(array('lines' => array_merge(explode("\n\n", $minutesModel->description), array($phpr->translate('Start') . ': ' . $minutesModel->meetingDatetime, $phpr->translate('End') . ': ' . $minutesModel->endTime, $phpr->translate('Place') . ': ' . $minutesModel->place, $phpr->translate('Moderator') . ': ' . $minutesModel->moderator)), 'fontSize' => 12));
     $invited = Minutes_Helpers_Userlist::expandIdList($minutesModel->participantsInvited);
     $attending = Minutes_Helpers_Userlist::expandIdList($minutesModel->participantsAttending);
     $excused = Minutes_Helpers_Userlist::expandIdList($minutesModel->participantsExcused);
     $pages += $page->addTable(array('fontSize' => 12, 'rows' => array(array(array('text' => $phpr->translate('Invited'), 'width' => 4.7 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => array_reduce($invited, array('self', '_concat')), 'width' => 12.0 * Phprojekt_Pdf_Page::PT_PER_CM)), array(array('text' => $phpr->translate('Attending'), 'width' => 4.7 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => array_reduce($attending, array('self', '_concat')), 'width' => 12.0 * Phprojekt_Pdf_Page::PT_PER_CM)), array(array('text' => $phpr->translate('Excused'), 'width' => 4.7 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => array_reduce($excused, array('self', '_concat')), 'width' => 12.0 * Phprojekt_Pdf_Page::PT_PER_CM)))));
     $page = end($pages);
     $itemtable = array();
     $items = $minutesModel->items->fetchAll();
     foreach ($items as $item) {
         $itemtable[] = array(array('text' => $item->topicId, 'width' => 1.3 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => $phpr->translate($item->information->getTopicType($item->topicType)), 'width' => 3.0 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => $item->getDisplay(), 'width' => 12.4 * Phprojekt_Pdf_Page::PT_PER_CM));
     }
     $pages += $page->addTable(array('fontSize' => 12, 'rows' => array_merge(array(array('isHeader' => true, array('text' => $phpr->translate('No.'), 'width' => 1.3 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => $phpr->translate('Type'), 'width' => 3.0 * Phprojekt_Pdf_Page::PT_PER_CM), array('text' => $phpr->translate('Item'), 'width' => 12.4 * Phprojekt_Pdf_Page::PT_PER_CM))), $itemtable)));
     $page = end($pages);
     $pdf->pages = $pages;
     $pdf->properties['Title'] = $minutesModel->title;
     $owner = Minutes_Helpers_Userlist::expandIdList($minutesModel->ownerId);
     $pdf->properties['Author'] = $owner[0]['display'];
     $pdf->properties['Producer'] = 'PHProjekt version ' . Phprojekt::getVersion();
     $pdf->properties['CreationDate'] = 'D:' . gmdate('YmdHis');
     $pdf->properties['Keywords'] = $minutesModel->description;
     return $pdf->render();
 }
Example #4
0
 protected function _buildPDFDocuments(Doc_Book $book)
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../_vendor/zf');
     $pdf = new Zend_Pdf();
     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
     $font = Zend_Pdf_Font::fontWithPath('c:\\windows\\fonts\\simkai.ttf');
     $page->setFont($font, 12);
     $pdf->pages[] = $page;
     $page->drawText('中文测试', 100, 430, 'UTF-8');
     $pdf->save('output.pdf');
 }
Example #5
0
 /**
  *
  * @return Zend_Pdf
  *
  */
 protected function createPdfTemplate()
 {
     if ($this->getDi()->config->get('invoice_custom_template') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template')))) {
         $pdf = Zend_Pdf::load($upload->getFullPath());
         $this->pointer = $this->getPaperHeight() - $this->getDi()->config->get('invoice_skip', 150);
     } else {
         $pdf = new Zend_Pdf();
         $pdf->pages[0] = $pdf->newPage($this->getDi()->config->get('invoice_format', Zend_Pdf_Page::SIZE_LETTER));
         $this->pointer = $this->drawDefaultTemplate($pdf);
     }
     return $pdf;
 }
Example #6
0
 public function getPdf()
 {
     $pdf = new Zend_Pdf();
     $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
     $page->setFont($font, 12);
     $width = $page->getWidth();
     $i = 0;
     $this->insertLogo($page);
     $this->insertAddress($page);
     /*$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
       $page->drawRectangle(25, $this->y + 15, 190, $this->y - 35);
       $page->drawRectangle(190, $this->y + 15, 350, $this->y - 35);
       $page->drawRectangle(350, $this->y + 15, 570, $this->y - 35);*/
     $page->setFont($font, 16);
     $this->y -= 50;
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.5));
     $page->drawRectangle(25, $this->y + 15, 573, $this->y - 57);
     $page->setFillColor(new Zend_Pdf_Color_Html('#ffffff'));
     $headerText = "Report: Net Sales & Tax";
     $page->drawText($headerText, 30, $this->y, 'UTF-8');
     $this->y -= 22;
     $page->drawText("From: " . $this->from, 30, $this->y, 'UTF-8');
     $this->y -= 22;
     $page->drawText("To: " . $this->to, 30, $this->y, 'UTF-8');
     $page->setFont($font, 14);
     $this->y -= 50;
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
     $totalText = Mage::helper('sales')->__('Total Net Sale');
     $page->drawText($totalText, 25, $this->y, 'UTF-8');
     $total = Mage::helper('core')->currency($this->getTotalSale(), true, false);
     $page->drawText($total, 505, $this->y, 'UTF-8');
     $this->y -= 50;
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
     $totalText = Mage::helper('sales')->__('Net Sales Texas Only');
     $page->drawText($totalText, 25, $this->y, 'UTF-8');
     $total = Mage::helper('core')->currency($this->getTotalTexasSale(), true, false);
     $page->drawText($total, 505, $this->y, 'UTF-8');
     $this->y -= 50;
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
     $totalText = Mage::helper('sales')->__('Net Shipping Costs for Texas only');
     $page->drawText($totalText, 25, $this->y, 'UTF-8');
     $total = Mage::helper('core')->currency($this->getTotalTexasShipping(), true, false);
     $page->drawText($total, 505, $this->y, 'UTF-8');
     $this->y -= 50;
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
     $totalText = Mage::helper('sales')->__('Texas Net Sales Tax');
     $page->drawText($totalText, 25, $this->y, 'UTF-8');
     $total = Mage::helper('core')->currency($this->getTotalTexasTax(), true, false);
     $page->drawText($total, 505, $this->y, 'UTF-8');
     $pdf->pages[] = $page;
     return $pdf->render();
 }
 public function generateAction()
 {
     // Create new PDF document.
     $pdf = new Zend_Pdf();
     // 421 x 596 = A5 Landscape in pixels @ 72dpi
     $pdf->pages[] = new Zend_Pdf_Page(596, 421);
     $pdf->pages[] = new Zend_Pdf_Page(596, 421);
     $front = $pdf->pages[0];
     $back = $pdf->pages[1];
     // Create new font
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     // Apply font
     $front->setFont($font, 18);
     // Start at the top
     $y = 590;
     // With a left Margin of 10
     $x = 10;
     $front->drawText($this->recipe->name, $x, $y);
     $y = $y - 30;
     $front->setFont($font, 12);
     $front->drawText('Difficulty: ' . $this->recipe->difficulty, $x, $y);
     $y = $y - 15;
     $front->drawText('Preparation Time: ' . $this->recipe->preparation_time, $x, $y);
     $y = $y - 15;
     $front->drawText('Cooking Time: ' . $this->recipe->preparation_time, $x, $y);
     $y = $y - 15;
     $front->drawText('Serves: ' . $this->recipe->serves, $x, $y);
     $y = $y - 15;
     $front->drawText('Freezable: ' . $this->recipe->freezable, $x, $y);
     $ingredients = $this->recipe->findRecipeIngredient();
     $y = $y - 15;
     foreach ($ingredients as $ingredient) {
         $y = $y - 15;
         $text = '';
         if ($ingredient->quantity > 0) {
             $text .= $ingredient->quantity;
         }
         if ($ingredient->amount > 0) {
             $text .= $ingredient->amount . ' ';
         }
         if (!empty($ingredient->measurement)) {
             $text .= $ingredient->measurement_abbr . ' ';
         }
         $text .= $ingredient->name;
         $front->drawText($text, $x, $y);
     }
     $back->setFont($font, 18);
     $pdf->save('pdf/foo.pdf');
 }
 public function verPdfAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $producto = $this->_producto->getDetalle($this->_getParam('id'));
     //        var_dump($producto);exit;
     $pdf = new Zend_Pdf();
     $pdf1 = Zend_Pdf::load(APPLICATION_PATH . '/../templates/producto.pdf');
     //        $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // 595 x842
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     //        $pdf->pages[] = $page;
     //        $page->setFont($font, 20);$page->drawText('Zend: PDF', 10, 822);
     //        $page->setFont($font, 12);$page->drawText('Comentarios', 10, 802);
     //        $pdfData = $pdf->render();
     $page = $pdf1->pages[0];
     $page->setFont($font, 12);
     $page->drawText($producto['producto'], 116, 639);
     $page->drawText($producto['precio'], 116, 607);
     $page->drawText($producto['categoria'], 116, 575);
     $page->drawText($producto['fabricante'], 116, 543);
     $page->drawText('zEND', 200, 200);
     $pdfData = $pdf1->render();
     header("Content-type: application/x-pdf");
     header("Content-Disposition: inline; filename=result.pdf");
     $this->_response->appendBody($pdfData);
 }
Example #9
0
 /**
  * test to combine Zend_Pdf content with tcpdf pdfs
  *
  * @param $observer
  */
 public function adjustPdf($observer)
 {
     $extractor = new Zend_Pdf_Resource_Extractor();
     $pdf = $observer->getEvent()->getPdf();
     $counter = false;
     foreach ($pdf->pages as $key => &$page) {
         if ($page instanceof Fooman_PdfCustomiser_Model_Abstract) {
             $counter = 1;
             $instance = $page;
             $firstKey = $key;
             unset($pdf->pages[$key]);
         } elseif ($counter == 1) {
             $objectArray = $page;
             $counter++;
             unset($pdf->pages[$key]);
         } elseif ($counter == 2) {
             $orderIds = $page;
             $tcpdf = Zend_Pdf::parse($instance->renderPdf($objectArray, $orderIds, null, true));
             foreach ($tcpdf->pages as $p) {
                 $pdf->pages[$firstKey] = $extractor->clonePage($p);
             }
             $counter = 0;
         }
     }
 }
Example #10
0
 /**
  * Create Label
  *
  * @return string
  * @throws Zend_Pdf_Exception
  * @throws InvalidArgumentException
  */
 public function render()
 {
     $pdf = new Zend_Pdf();
     $pdfBuilder = new Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder();
     $template = new Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     $pdfBuilder->setPage($template)->addProductName((string) $this->_info->ProductShortName)->addProductContentCode((string) $this->_info->ProductContentCode)->addSenderInfo($this->_info->Shipper)->addOriginInfo((string) $this->_info->OriginServiceArea->ServiceAreaCode)->addReceiveInfo($this->_info->Consignee)->addDestinationFacilityCode((string) $this->_info->Consignee->CountryCode, (string) $this->_info->DestinationServiceArea->ServiceAreaCode, (string) $this->_info->DestinationServiceArea->FacilityCode)->addServiceFeaturesCodes()->addDeliveryDateCode()->addShipmentInformation($this->_request->getOrderShipment())->addDateInfo($this->_info->ShipmentDate)->addWeightInfo((string) $this->_info->ChargeableWeight, (string) $this->_info->WeightUnit)->addWaybillBarcode((string) $this->_info->AirwayBillNumber, (string) $this->_info->Barcodes->AWBBarCode)->addRoutingBarcode((string) $this->_info->DHLRoutingCode, (string) $this->_info->DHLRoutingDataId, (string) $this->_info->Barcodes->DHLRoutingBarCode)->addBorder();
     $packages = array_values($this->_request->getPackages());
     $i = 0;
     foreach ($this->_info->Pieces->Piece as $piece) {
         $page = new Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page($template);
         $pdfBuilder->setPage($page)->addPieceNumber((int) $piece->PieceNumber, (int) $this->_info->Piece)->addContentInfo($packages[$i])->addPieceIdBarcode((string) $piece->DataIdentifier, (string) $piece->LicensePlate, (string) $piece->LicensePlateBarCode);
         array_push($pdf->pages, $page);
         $i++;
     }
     return $pdf->render();
 }
Example #11
0
 /**
  * keep compatible with the Zend_Pdf way of doing things
  * collect input for later processing with render()
  *
  * @param array $input    array of items to print
  * @param array $orderIds array of order ids
  *
  * @return Fooman_PdfCustomiser_Model_Abstract | Zend_Pdf
  */
 public function getPdf($input = array(), $orderIds = null)
 {
     if (self::COMPAT_MODE) {
         try {
             $newPdf = new Zend_Pdf();
             $extractor = new Zend_Pdf_Resource_Extractor();
             if (!empty($orderIds)) {
                 $origPdf = $this->renderPdf(null, $orderIds, null, true);
             } else {
                 $origPdf = $this->renderPdf($input, $orderIds, null, true);
             }
             if ($origPdf->getPdfAnyOutput()) {
                 $pdfString = $origPdf->Output('output.pdf', 'S');
                 $tcpdf = Zend_Pdf::parse($pdfString);
                 foreach ($tcpdf->pages as $p) {
                     $newPdf->pages[] = $extractor->clonePage($p);
                 }
             }
             return $newPdf;
         } catch (Exception $e) {
             Mage::logException($e);
         }
     } else {
         $this->pages[] = array('instance' => $this, 'objectArray' => $input, 'orderIds' => $orderIds);
         return $this;
     }
 }
 public function testRender()
 {
     $pdf = \Zend_Pdf::load(__DIR__ . '/MSWord.pdf');
     $expected = \Zend_Pdf::load(__DIR__ . '/MSWordExpected.pdf');
     $gemsPdf = $this->loader->getPdf();
     // Start code to expose protected method
     $addTokenToDocument = function (\Zend_Pdf $pdf, $tokenId, $surveyId) {
         return $this->addTokenToDocument($pdf, $tokenId, $surveyId);
     };
     $testObject = $addTokenToDocument->bindTo($gemsPdf, $gemsPdf);
     // End code to expose protected method
     $testObject($pdf, "abcd-efgh", 1);
     // fix the date to prevent differences
     $pdf->properties['ModDate'] = 'D:' . str_replace(':', "'", date('YmdHisP', 1458048768)) . "'";
     // Uncomment to update the test pdf
     /*
      $stream = fopen(__DIR__ . '/MSWordExpected.pdf', 'w');
      $pdf->render(false, $stream);
      fclose($stream);
     */
     // This will trigger the warning in #812: Warning when printing a survey pdf that was created using Word
     // This warning will cause the test to fail
     $pdf->render();
     $this->assertEquals($expected->getMetadata(), $pdf->getMetadata());
     $this->assertEquals($expected->properties, $pdf->properties);
 }
Example #13
0
 /**
  * Object constructor
  *
  * @param string  $data
  * @param boolean $storeContent
  */
 private function __construct($data, $storeContent)
 {
     try {
         $zendpdf = \Zend_Pdf::parse($data);
         // Store meta data properties
         if (isset($zendpdf->properties['Title'])) {
             $this->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title']));
         }
         if (isset($zendpdf->properties['Author'])) {
             $this->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author']));
         }
         if (isset($zendpdf->properties['Subject'])) {
             $this->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject']));
         }
         if (isset($zendpdf->properties['Keywords'])) {
             $this->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords']));
         }
         //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata()
         //do the content extraction
         $pdfParse = new \App_Search_Helper_PdfParser();
         $body = $pdfParse->pdf2txt($zendpdf->render());
         if ($body != '') {
             // Store contents
             if ($storeContent) {
                 $this->addField(\Zend_Search_Lucene_Field::Text('body', $body, 'UTF-8'));
             } else {
                 $this->addField(\Zend_Search_Lucene_Field::UnStored('body', $body, 'UTF-8'));
             }
         }
     } catch (\Exception $e) {
         Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR);
     }
 }
Example #14
0
 /**
  * Extract data from a PDF document and add this to the Lucene index.
  *
  * @param string $pdfPath                       The path to the PDF document.
  * @param Zend_Search_Lucene_Proxy $luceneIndex The Lucene index object.
  * @return Zend_Search_Lucene_Proxy
  */
 public static function index($pdfPath, $luceneIndex)
 {
     // Load the PDF document.
     $pdf = Zend_Pdf::load($pdfPath);
     $key = md5($pdfPath);
     /**
      * Set up array to contain the document index data.
      * The Filename will be used to retrive the document if it is found in
      * the search resutls.
      * The Key will be used to uniquely identify the document so we can
      * delete it from the search index.
      */
     $indexValues = array('Filename' => $pdfPath, 'Key' => $key, 'Title' => '', 'Author' => '', 'Subject' => '', 'Keywords' => '', 'Creator' => '', 'Producer' => '', 'CreationDate' => '', 'ModDate' => '', 'Contents' => '');
     // Go through each meta data item and add to index array.
     foreach ($pdf->properties as $meta => $metaValue) {
         switch ($meta) {
             case 'Title':
                 $indexValues['Title'] = $pdf->properties['Title'];
                 break;
             case 'Subject':
                 $indexValues['Subject'] = $pdf->properties['Subject'];
                 break;
             case 'Author':
                 $indexValues['Author'] = $pdf->properties['Author'];
                 break;
             case 'Keywords':
                 $indexValues['Keywords'] = $pdf->properties['Keywords'];
                 break;
             case 'CreationDate':
                 $dateCreated = $pdf->properties['CreationDate'];
                 $distance = substr($dateCreated, 16, 2);
                 if (!is_long($distance)) {
                     $distance = null;
                 }
                 // Convert date from the PDF format of D:20090731160351+01'00'
                 $dateCreated = mktime(substr($dateCreated, 10, 2), substr($dateCreated, 12, 2), substr($dateCreated, 14, 2), substr($dateCreated, 6, 2), substr($dateCreated, 8, 2), substr($dateCreated, 2, 4), $distance);
                 //distance
                 $indexValues['CreationDate'] = date('Ymd', $dateCreated);
                 break;
             case 'Date':
                 $indexValues['Date'] = $pdf->properties['Date'];
                 break;
         }
     }
     /**
      * Parse the contents of the PDF document and pass the text to the
      * contents item in the $indexValues array.
      */
     $pdfParse = new App_Search_Helper_PdfParser();
     $indexValues['Contents'] = $pdfParse->pdf2txt($pdf->render());
     // Create the document using the values
     $doc = new App_Search_Lucene_Document($indexValues);
     if ($doc !== false) {
         // If the document creation was sucessful then add it to our index.
         $luceneIndex->addDocument($doc);
     }
     // Return the Lucene index object.
     return $luceneIndex;
 }
 /**
  * Constructor.
  *
  * @param mixed $param1
  * @param mixed $param2
  * @param mixed $param3
  *
  * @throws Zend_Pdf_Exception
  *
  * @return void
  */
 public function __construct($param1, $param2 = NULL, $param3 = NULL)
 {
     parent::__construct($param1, $param2, $param3);
     if ($param1 instanceof FFR_Pdf_PdfGenerator && $param2 === null && $param3 === null) {
         // Clone additional properties
         $this->setBorder($param1->borderTop, $param1->borderRight, $param1->borderBottom, $param1->borderLeft);
     }
 }
Example #16
0
 public function render()
 {
     $page = $this->newPage();
     $this->createHeader($page);
     $this->createContent($page);
     $this->createFooter($page);
     $this->_pdf->pages[] = $page;
     return $this->_pdf->render();
 }
Example #17
0
 /** extract metadata */
 public function extract($revision)
 {
     /** @var ItemRevisionModel $itemRevisionModel */
     $itemRevisionModel = MidasLoader::loadModel('ItemRevision');
     $revision = $itemRevisionModel->load($revision['itemrevision_id']);
     if (!$revision) {
         return;
     }
     $bitstreams = $revision->getBitstreams();
     if (count($bitstreams) != 1) {
         return;
     }
     $bitstream = $bitstreams[0];
     $ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1));
     /** @var MetadataModel $metadataModel */
     $metadataModel = MidasLoader::loadModel('Metadata');
     if ($ext == 'pdf') {
         $pdf = Zend_Pdf::load($bitstream->getFullPath());
         foreach ($pdf->properties as $name => $property) {
             $name = strtolower($name);
             try {
                 $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'misc', $name);
                 if (!$metadataDao) {
                     $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'misc', $name, '');
                 }
                 $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'misc', $name, $property);
             } catch (Zend_Exception $exc) {
                 echo $exc->getMessage();
             }
         }
     } else {
         /** @var SettingModel $settingModel */
         $settingModel = MidasLoader::loadModel('Setting');
         $command = $settingModel->getValueByName(METADATAEXTRACTOR_HACHOIR_METADATA_COMMAND_KEY, $this->moduleName);
         exec(str_replace("'", '"', $command) . ' "' . $bitstream->getFullPath() . '"', $output);
         if (!isset($output[0]) || $output[0] != 'Metadata:') {
             return;
         }
         unset($output[0]);
         foreach ($output as $out) {
             $out = substr($out, 2);
             $pos = strpos($out, ': ');
             $name = strtolower(substr($out, 0, $pos));
             $value = substr($out, $pos + 2);
             try {
                 $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'misc', $name);
                 if (!$metadataDao) {
                     $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'misc', $name, '');
                 }
                 $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'misc', $name, $value);
             } catch (Zend_Exception $exc) {
                 echo $exc->getMessage();
             }
         }
     }
 }
Example #18
0
 function pdfgenerationAction()
 {
     //$fetchMeetings=new Meetingreport_Model_Meetingreport();
     $pdf = new Zend_Pdf();
     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
     // 		 $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     $pdf->pages[] = $page;
     // Image
     $app = $this->view->baseUrl();
     $word = explode('/', $app);
     $projname = '';
     for ($i = 0; $i < count($word); $i++) {
         if ($i > 0 && $i < count($word) - 1) {
             $projname .= '/' . $word[$i];
         }
     }
     $image_name = "/var/www" . $app . "/images/logo.jpg";
     $image = Zend_Pdf_Image::imageWithPath($image_name);
     //$page->drawImage($image, 25, 770, 570, 820);
     $page->drawImage($image, 30, 770, 130, 820);
     $page->setLineWidth(1)->drawLine(25, 25, 570, 25);
     //bottom horizontal
     $page->setLineWidth(1)->drawLine(25, 25, 25, 820);
     //left vertical
     $page->setLineWidth(1)->drawLine(570, 25, 570, 820);
     //right vertical
     $page->setLineWidth(1)->drawLine(570, 820, 25, 820);
     //top horizontal
     $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 8);
     $text = array("Bank", "Branch", "Thumb Impression Declaration", "I hereby declare that Smt/sri ______________________ has given the thumb impression in the presence of me and his mother tongue", " ___________________________", "Date", "Yours sincerely");
     $x0 = 60;
     $x10 = 450;
     $x11 = 285;
     $page->drawText($text[0], $x0, 725);
     $page->drawText($text[1], $x0, 700);
     $page->drawText($text[2], $x0, 675);
     $page->drawText($text[3], $x0, 650);
     $page->drawText($text[4], $x0, 625);
     $page->drawText($text[5], $x0, 575);
     $page->drawText($text[6], $x10, 575);
     $page->setLineWidth(1)->drawLine(50, 750, 550, 750);
     $page->setLineWidth(1)->drawLine(50, 750, 50, 465);
     $page->setLineWidth(1)->drawLine(50, 750, 50, 465);
     $page->setLineWidth(1)->drawLine(50, 465, 550, 465);
     $page->setLineWidth(1)->drawLine(550, 465, 550, 750);
     $page->setLineWidth(1)->drawLine(50, 690, 550, 690);
     $page->setLineWidth(1)->drawLine(50, 670, 550, 670);
     $y1 = 700;
     $totalAmount = "0";
     $totaldebit = "0";
     $pdfData = $pdf->render();
     $pdf->save('/var/www' . $projname . '/reports/thumbdeclaration' . date('Y-m-d') . '.pdf');
     $path = '/var/www' . $projname . '/reports/thumbdeclaration' . date('Y-m-d') . '.pdf';
     chmod($path, 0777);
 }
 public function editmetaAction()
 {
     // Get the form and send to the view.
     $form = new Form_PdfMeta();
     $this->view->form = $form;
     // Get the file and send the location to the view.
     $pdfPath = urldecode($this->_request->getParam('file'));
     $file = substr($pdfPath, strrpos($pdfPath, SLASH) + 1);
     $this->view->file = $file;
     // Define what meta data we are looking at.
     $metaValues = array('Title' => '', 'Author' => '', 'Subject' => '', 'Keywords' => '');
     if ($this->_request->isPost()) {
         // Get the current form values.
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             // Form values are valid.
             // Save the contents of the form to the associated meta data fields in the PDF.
             $pdf = Zend_Pdf::load($pdfPath);
             foreach ($metaValues as $meta => $metaValue) {
                 if (isset($formData[$meta])) {
                     $pdf->properties[$meta] = $formData[$meta];
                 } else {
                     $pdf->properties[$meta] = '';
                 }
             }
             $pdf->save($pdfPath);
             // Add to/update index.
             $config = Zend_Registry::get('config');
             $appLucene = App_Search_Lucene::open($config->luceneIndex);
             $index = App_Search_Lucene_Index_Pdfs::index($pdfPath, $appLucene);
             // Redirect the user to the list action of this controller.
             return $this->_helper->redirector('list', 'pdf', '', array())->setCode(301);
         } else {
             // Form values are not valid send the current values to the form.
             $form->populate($formData);
         }
     } else {
         // Make sure the file exists before we start doing anything with it.
         if (file_exists($pdfPath)) {
             // Extract any current meta data values from the PDF document
             $pdf = Zend_Pdf::load($pdfPath);
             foreach ($metaValues as $meta => $metaValue) {
                 if (isset($pdf->properties[$meta])) {
                     $metaValues[$meta] = $pdf->properties[$meta];
                 } else {
                     $metaValues[$meta] = '';
                 }
             }
             // Populate the form with out metadata values.
             $form->populate($metaValues);
         } else {
             // File doesn't exist.
         }
     }
 }
Example #20
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return boolean
  * @throws \Zend_Valid_Exception If validation of $value is impossible
  */
 public function isValid($value, $context = array())
 {
     // Only fail when file really can't be loaded.
     try {
         \Zend_Pdf::load($value);
         return true;
     } catch (\Zend_Pdf_Exception $e) {
         $this->_error(self::ERROR_INVALID_VERSION, $e->getMessage());
         return false;
     }
 }
 /**
  * Format pdf file
  *
  * @param null $shipment
  * @return Zend_Pdf
  */
 public function getPdf($shipment = null)
 {
     $this->_beforeGetPdf();
     $this->_initRenderer('shipment');
     $pdf = new Zend_Pdf();
     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
     $pdf->pages[] = $page;
     if ($shipment->getStoreId()) {
         Mage::app()->getLocale()->emulate($shipment->getStoreId());
         Mage::app()->setCurrentStore($shipment->getStoreId());
     }
     $this->_setFontRegular($page);
     $this->_drawHeaderBlock($page);
     $this->y = 740;
     $this->_drawPackageBlock($page);
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
     $this->_afterGetPdf();
     if ($shipment->getStoreId()) {
         Mage::app()->getLocale()->revert();
     }
     return $pdf;
 }
 /**
  * Object constructor
  *
  * @param integer $objCount
  */
 public function __construct($objNum, $genNum, $isFree, $dump = null)
 {
     $this->_objNum = $objNum;
     $this->_genNum = $genNum;
     $this->_isFree = $isFree;
     if ($dump !== null) {
         if (strlen($dump) > 1024) {
             $this->_dump = Zend_Pdf::getMemoryManager()->create($dump);
         } else {
             $this->_dump = $dump;
         }
     }
 }
 public function __construct()
 {
     if (Config::$glsbox_label_beginx != '' && (int) Config::$glsbox_label_beginx >= 0) {
         $startpunktX = (int) Config::$glsbox_label_beginx;
     } else {
         $startpunktX = 0;
     }
     if (Config::$glsbox_label_beginy != '' && (int) Config::$glsbox_label_beginy >= 0) {
         $startpunktY = (int) Config::$glsbox_label_beginy;
     } else {
         $startpunktY = 0;
     }
     $startpunkt = array('x' => $startpunktX, 'y' => $startpunktY);
     //Angabe in Milimeter
     $this->_startpunkt = array('x' => $this->mmToPts($startpunkt['x']), 'y' => $this->mmToPts($startpunkt['y']));
     $this->pdf = new Zend_Pdf();
     // Erstelle eine neue Seite mit Hilfe des Zend_Pdf Objekts
     // (die Seite wird an das angegebene Dokument angehängt)
     if (Config::$glsbox_label_papersize != 'A4' && Config::$glsbox_label_papersize != 'A5') {
         $lettersize = Zend_Pdf_Page::SIZE_A4;
     } else {
         if (Config::$glsbox_label_papersize == 'A4') {
             $lettersize = Zend_Pdf_Page::SIZE_A4;
         }
         if (Config::$glsbox_label_papersize == 'A5') {
             $lettersize = '420.94:595.28';
         }
     }
     $this->pdf->pages[] = $this->page = $this->pdf->newPage($lettersize);
     // Erstelle einen neuen Stil
     $this->defaultStyle = new Zend_Pdf_Style();
     $this->defaultStyle->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));
     $this->defaultStyle->setLineColor(new Zend_Pdf_Color_GrayScale(0.2));
     $this->defaultStyle->setLineWidth(2);
     //$fontH = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
     //$this->defaultStyle->setFont($fontH, 32);
     $this->page->setStyle($this->defaultStyle);
     $this->drawGeneralLayout();
 }
Example #24
0
 /**
  * Object constructor
  *
  * @param integer $objCount
  */
 public function __construct($objNum, $genNum, $isFree, $dump = null)
 {
     $this->_objNum = $objNum;
     $this->_genNum = $genNum;
     $this->_isFree = $isFree;
     if ($dump !== null) {
         if (strlen($dump) > 1024) {
             require_once PHP_LIBRARY_PATH . 'Zend/Pdf.php';
             $this->_dump = Zend_Pdf::getMemoryManager()->create($dump);
         } else {
             $this->_dump = $dump;
         }
     }
 }
Example #25
0
    /**
     * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::executeInternal
     */
    public function testExecute()
    {
        $creditmemoId = 2;
        $date = '2015-01-19_13-03-45';
        $fileName = 'creditmemo2015-01-19_13-03-45.pdf';
        $fileContents = 'pdf0123456789';
        $this->prepareTestExecute($creditmemoId);

        $this->objectManagerMock->expects($this->any())
            ->method('create')
            ->willReturnMap(
                [
                    ['Magento\Sales\Model\Order\Creditmemo', [], $this->creditmemoMock],
                    ['Magento\Sales\Model\Order\Pdf\Creditmemo', [], $this->creditmemoPdfMock]
                ]
            );
        $this->creditmemoRepositoryMock->expects($this->once())
            ->method('get')
            ->with($creditmemoId)
            ->willReturn($this->creditmemoMock);
        $this->creditmemoPdfMock->expects($this->once())
            ->method('getPdf')
            ->with([$this->creditmemoMock])
            ->willReturn($this->pdfMock);
        $this->objectManagerMock->expects($this->once())
            ->method('get')
            ->with('Magento\Framework\Stdlib\DateTime\DateTime')
            ->willReturn($this->dateTimeMock);
        $this->dateTimeMock->expects($this->once())
            ->method('date')
            ->with('Y-m-d_H-i-s')
            ->willReturn($date);
        $this->pdfMock->expects($this->once())
            ->method('render')
            ->willReturn($fileContents);
        $this->fileFactoryMock->expects($this->once())
            ->method('create')
            ->with(
                $fileName,
                $fileContents,
                \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,
                'application/pdf'
            )
            ->willReturn($this->responseMock);

        $this->assertInstanceOf(
            'Magento\Framework\App\ResponseInterface',
            $this->printAction->executeInternal()
        );
    }
Example #26
0
 private function gerarCertificado($idEncontro, $array = array())
 {
     // include auto-loader class
     require_once 'Zend/Loader/Autoloader.php';
     // register auto-loader
     $loader = Zend_Loader_Autoloader::getInstance();
     $pdf = new Zend_Pdf();
     $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     $font = Zend_Pdf_Font::fontWithPath(APPLICATION_PATH . "/../public/font/UbuntuMono-R.ttf");
     $page1->setFont($font, Sige_Pdf_Certificado::TAM_FONTE);
     // configura o plano de fundo
     $this->background($page1, $idEncontro);
     for ($index = 0; $index < count($array); $index++) {
         $page1->drawText($array[$index], Sige_Pdf_Certificado::POS_X_INICIAL, Sige_Pdf_Certificado::POS_Y_INICIAL - $index * Sige_Pdf_Certificado::DES_Y, 'UTF-8');
     }
     // configura a(s) assinatura(s)
     $this->assinaturas($page1, $idEncontro);
     $pdf->pages[] = $page1;
     // salve apenas em modo debug!
     // $pdf->save(APPLICATION_PATH . '/../tmp/certificado-participante.pdf');
     // Get PDF document as a string
     return $pdf->render();
 }
Example #27
0
 /**
  * @see Pimcore_Image_Matrixcode_Renderer_Abstract::_renderMatrixcode()
  */
 protected function _renderMatrixcode()
 {
     $padding = $this->_matrixcode->getPadding();
     $this->_matrixcode->draw();
     $matrix_dimension = count($this->_matrixcode->getMatrix());
     $matrix_dim_with_padding_x = $matrix_dimension + $padding[1] + $padding[3];
     $matrix_dim_with_padding_y = $matrix_dimension + $padding[0] + $padding[2];
     // Scaling
     $scale = $this->getScale();
     $output_size_width = $matrix_dim_with_padding_x * $scale;
     $output_size_height = $matrix_dim_with_padding_y * $scale;
     // Set colors/transparency
     $fore_color = $this->_matrixcode->getForeColor();
     $back_color = $this->_matrixcode->getBackgroundColor();
     $pdf = new Zend_Pdf();
     $pdf->pages[] = $page = $pdf->newPage('A4');
     // Add credits
     if (!empty($this->_footnote)) {
         $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
         $page->setFont($font, 10)->setFillColor(Zend_Pdf_Color_Html::color('#000000'))->drawText($this->_footnote, 20, 20);
     }
     $page_width = $page->getWidth();
     $page_height = $page->getHeight();
     // Move center of coordination system (by default the lower left corner)
     $page->translate(floor($page_width - $output_size_width) / 2, ($page_height - $output_size_height) / 2);
     if (!empty($back_color)) {
         $back_color = new Zend_Pdf_Color_HTML('#' . $this->_decimalToHTMLColor($back_color));
         $page->setFillColor($back_color);
         $page->drawRectangle(0, 0, $output_size_width, $output_size_height, Zend_Pdf_Page::SHAPE_DRAW_FILL);
     }
     $page->setFillColor(new Zend_Pdf_Color_HTML('#' . $this->_decimalToHTMLColor($fore_color)));
     // Convert the matrix into pixels
     $matrix = $this->_matrixcode->getMatrix();
     for ($i = 0; $i < $matrix_dimension; $i++) {
         for ($j = 0; $j < $matrix_dimension; $j++) {
             if ($matrix[$i][$j]) {
                 $x = ($i + $padding[3]) * $scale;
                 $y = ($matrix_dimension - 1 - $j + $padding[2]) * $scale;
                 $page->drawRectangle($x, $y, $x + $scale, $y + $scale, Zend_Pdf_Page::SHAPE_DRAW_FILL);
             }
         }
     }
     if ($this->_send_result) {
         $this->_sendOutput($pdf->render());
     } else {
         return $pdf;
     }
     return;
 }
Example #28
0
 public function init()
 {
     //On récupère l'id du document que l'on doit afficher à partir de l'indexController
     $request = $this->getRequest();
     //Comme nous n'avons pas Active Directory, on suppose que l'ID utilisateur est de 6
     $this->user_ID = 6;
     // Etat concernant les documents que nous avons utilis� dans la base de donn�e oracle
     $this->etat_encours = 1;
     $this->etat_surtablette = 2;
     $this->etat_valide = 3;
     $this->etat_refuse = 4;
     $this->etat_enattente = 5;
     $this->etat_demandeur = 6;
     //On récupère l'ID du document que nous souhaitons afficher à partir de l'indexController
     $request = $this->getRequest();
     $this->id_document = $request->getParam('COURRIER_ID');
     $db = Zend_Db_Table::getDefaultAdapter();
     //Si l'utilisateur n'est pas habilit� � voir le document, il est renvoy� � la page d'acceuil.
     // On r�cup�re le lien entre l'utilisateur et le document.
     $sqlhabilitated = 'SELECT * FROM LIENINTERNE WHERE ID_COURRIER =' . $this->id_document . 'AND ID_ENTITEDESTINATAIRE = ' . $this->user_ID;
     $stmthabilitated = $db->query($sqlhabilitated);
     while ($rowhabilitated = $stmthabilitated->fetch()) {
         $etat_habilitated[] = $rowhabilitated['ID_ETATDESTINATAIRE'];
     }
     if ($etat_habilitated[0] == null || $etat_habilitated[0] == 0) {
         //Il n'existe de lien entre l'utilisateur et le document.
         $this->_helper->redirector('index', 'index');
     } else {
         if ($etat_habilitated[0] != $this->etat_encours && $etat_habilitated[0] != $this->etat_surtablette && $etat_habilitated[0] != $this->etat_demandeur) {
             //Le lien entre la personne et le document n'est plus valide.
             $this->_helper->redirector('index', 'index');
         }
     }
     //URL utilisé pour récupérer le document pour la liseuse
     $url = 'http://' . $_SERVER['HTTP_HOST'] . '/pdf/' . $this->id_document . '.pdf';
     //Fichier PDF qui est utilisé = useful for signature and images
     $this->filePath = APPLICATION_PATH . '/../public/pdf/' . $this->id_document . '.pdf';
     $this->view->pdfurl = $url;
     $this->pdf = new Zend_Pdf();
     $this->pdf = Zend_Pdf::load($this->filePath, null, true);
 }
Example #29
0
 /**
  * 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_Element_Dictionary       $pageDict,
  *                   Zend_Pdf_ElementFactory_Interface $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_ElementFactory_Interface $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_ElementFactory_Interface $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 Zend_Pdf_Element_Reference && $param1->getType() == Zend_Pdf_Element::TYPE_DICTIONARY && $param2 instanceof Zend_Pdf_ElementFactory_Interface && $param3 === null) {
         $this->_pageDictionary = $param1;
         $this->_objFactory = $param2;
         $this->_attached = true;
         $this->_safeGS = false;
         return;
     } else {
         if ($param1 instanceof Zend_Pdf_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 Zend_Pdf_Element_Dictionary());
             foreach ($param1->_pageDictionary->getKeys() as $key) {
                 if ($key == 'Contents') {
                     // Clone Contents property
                     $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
                     if ($param1->_pageDictionary->Contents->getType() != Zend_Pdf_Element::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 Zend_Pdf_ElementFactory_Interface) && $param3 === null) {
                 if ($param2 !== null) {
                     $this->_objFactory = $param2;
                 } else {
                     //require_once 'Zend/Pdf/ElementFactory.php';
                     $this->_objFactory = Zend_Pdf_ElementFactory::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 = Zend_Pdf_Page::SIZE_A4;
                         break;
                     case 'a4-landscape':
                         $param1 = Zend_Pdf_Page::SIZE_A4_LANDSCAPE;
                         break;
                     case 'letter':
                         $param1 = Zend_Pdf_Page::SIZE_LETTER;
                         break;
                     case 'letter-landscape':
                         $param1 = Zend_Pdf_Page::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"
                      */
                     //require_once 'Zend/Pdf/Exception.php';
                     throw new Zend_Pdf_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 Zend_Pdf_ElementFactory_Interface)) {
                     if ($param3 !== null) {
                         $this->_objFactory = $param3;
                     } else {
                         //require_once 'Zend/Pdf/ElementFactory.php';
                         $this->_objFactory = Zend_Pdf_ElementFactory::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 {
                     //require_once 'Zend/Pdf/Exception.php';
                     throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.');
                 }
             }
         }
     }
     $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
     $this->_pageDictionary->Type = new Zend_Pdf_Element_Name('Page');
     //require_once 'Zend/Pdf.php';
     $this->_pageDictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate());
     $this->_pageDictionary->Resources = new Zend_Pdf_Element_Dictionary();
     $this->_pageDictionary->MediaBox = new Zend_Pdf_Element_Array();
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight);
     $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
 }
Example #30
0
 /**
  * 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_Element_Dictionary       $pageDict,
  *                   Zend_Pdf_ElementFactory_Interface $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_ElementFactory_Interface $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_ElementFactory_Interface $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 Zend_Pdf_Element_Reference && $param1->getType() == Zend_Pdf_Element::TYPE_DICTIONARY && $param2 instanceof Zend_Pdf_ElementFactory_Interface && $param3 === null) {
         $this->_pageDictionary = $param1;
         $this->_objFactory = $param2;
         $this->_attached = true;
         return;
     } else {
         if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) {
             /** @todo implementation */
             throw new Zend_Pdf_Exception('Not implemented yet.');
         } else {
             if (is_string($param1) && ($param2 === null || $param2 instanceof Zend_Pdf_ElementFactory_Interface) && $param3 === null) {
                 $this->_objFactory = $param2 !== null ? $param2 : Zend_Pdf_ElementFactory::createFactory(1);
                 $this->_attached = false;
                 switch (strtolower($param1)) {
                     case 'a4':
                         $param1 = Zend_Pdf_Page::SIZE_A4;
                         break;
                     case 'a4-landscape':
                         $param1 = Zend_Pdf_Page::SIZE_A4_LANDSCAPE;
                         break;
                     case 'letter':
                         $param1 = Zend_Pdf_Page::SIZE_LETTER;
                         break;
                     case 'letter-landscape':
                         $param1 = Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE;
                         break;
                     default:
                         // should be in "x:y" form
                 }
                 $pageDim = explode(':', $param1);
                 if (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 Zend_Pdf_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 Zend_Pdf_ElementFactory_Interface)) {
                     $this->_objFactory = $param3 !== null ? $param3 : Zend_Pdf_ElementFactory::createFactory(1);
                     $this->_attached = false;
                     $pageWidth = $param1;
                     $pageHeight = $param2;
                 } else {
                     throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.');
                 }
             }
         }
     }
     $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary());
     $this->_pageDictionary->Type = new Zend_Pdf_Element_Name('Page');
     $this->_pageDictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate());
     $this->_pageDictionary->Resources = new Zend_Pdf_Element_Dictionary();
     $this->_pageDictionary->MediaBox = new Zend_Pdf_Element_Array();
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth);
     $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight);
     $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array();
 }