public function testDrawing() { $pdf = new Zend_Pdf(); // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page1 = $pdf->newPage('A4'); // Add new page generated by Zend_Pdf_Page object (page is not attached to the document) $pdf->pages[] = $page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); // Create new font $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Apply font and draw text $page1->setFont($font, 36); $page1->setFillColor(Zend_Pdf_Color_Html::color('#9999cc')); $page1->drawText('Helvetica 36 text string', 60, 500); // Use font object for another page $page2->setFont($font, 24); $page2->drawText('Helvetica 24 text string', 60, 500); // Use another font $page2->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 32); $page2->drawText('Times-Roman 32 text string', 60, 450); // Draw rectangle $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)); $page2->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $page2->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $page2->drawRectangle(60, 400, 400, 350); // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); $page2->drawCircle(85, 375, 25); // Draw sectors $page2->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6); $page2->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0)); $page2->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0)); $page2->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6); // Draw ellipse $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); $page2->drawEllipse(250, 400, 400, 350); $page2->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0)); $page2->drawEllipse(250, 400, 400, 350, M_PI / 6, 2 * M_PI / 3); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0)); $page2->drawEllipse(250, 400, 400, 350, -M_PI / 6, M_PI / 6); // Draw and fill polygon $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1)); $x = array(); $y = array(); for ($count = 0; $count < 8; $count++) { $x[] = 140 + 25 * cos(3 * M_PI_4 * $count); $y[] = 375 + 25 * sin(3 * M_PI_4 * $count); } $page2->drawPolygon($x, $y, Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, Zend_Pdf_Page::FILL_METHOD_EVEN_ODD); // Draw line $page2->setLineWidth(0.5); $page2->drawLine(60, 375, 400, 375); $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
/** * Draw header for page * * @param Zend_Pdf_Page $page * @return void */ protected function insertHeaderText(Zend_Pdf_Page $page) { /* Add page header */ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $font = $this->_setFontBold($page, 12); $page->drawText("Retail/Tax Invoice/Cash Memorandum", 25, 800, 'UTF-8'); }
/** * Draw header for page * * @param Zend_Pdf_Page $page * @return void */ protected function insertHeaderText(Zend_Pdf_Page $page) { /* Add page header */ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $font = $this->_setFontBold($page, 13); $page->drawText("Order Details", 25, 815, 'UTF-8'); }
/** * Add Product Content Code * * @param string $code * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder * @throws Zend_Pdf_Exception * @throws InvalidArgumentException */ public function addProductContentCode($code) { $this->_page->saveGS(); $codes = array('TDK' => 0, 'TDE' => 1, 'TDL' => 0, 'TDM' => 1, 'TDT' => 0, 'TDY' => 1, 'XPD' => 0, 'DOX' => 0, 'WPX' => 1, 'ECX' => 0, 'DOM' => 0); if (!key_exists($code, $codes)) { throw new InvalidArgumentException(Mage::helper('usa')->__('Product content code is invalid')); } $font = null; if ($codes[$code]) { $this->_page->drawRectangle($this->_x(140), $this->_y(0), $this->_x(190), $this->_y(28), Zend_Pdf_Page::SHAPE_DRAW_FILL); $this->_page->setFillColor(new Zend_Pdf_Color_Html("#ffffff")); $font = $this->_fontBold; } else { $font = $this->_fontNormal; } $this->_page->setFont($font, 17); $this->_page->drawText($code, $this->_x(146), $this->_y(21)); $this->_page->restoreGS(); return $this; }
protected function drawFont($object) { $fontItem = $object->getItem(); if ($fontItem->getFace() == 'bold') { $fontDecoration = 'bold'; } else { $fontDecoration = 'regular'; } $fontPath = SERVER_BASE . '/fonts/' . $fontItem->getName() . '.ttf'; if (is_file($fontPath)) { $font = Zend_Pdf_Font::fontWithPath($fontPath, Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION); } else { if ($fontDecoration == "bold") { $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); } else { $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); } } if ($fontItem->getFace() == "invert") { $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); //schwarze farbe setzen fuer Hintergrund $width = $this->widthForStringUsingFontSize($object->getValue(), $font, $fontItem->getSize()); $height = $fontItem->getSize(); $this->page->drawRectangle($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())) + $height / 2, $this->coordX($this->mmToPts($object->getPosx())) + $width, $this->coordY($this->mmToPts($object->getPosy())) - $height / 2, Zend_Pdf_Page::SHAPE_DRAW_FILL); $this->page->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 1)); //weiße farbe setzen fuer Text } else { $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); //schwarze farbe setzen fuer text } $this->page->setFont($font, $fontItem->getSize()); if ($fontItem->getRotation() !== null) { $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), deg2rad(360 - $fontItem->getRotation())); } $this->page->drawText($object->getValue(), $this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy()) + $fontItem->getSize() / 2), 'UTF-8'); if ($fontItem->getRotation() !== null) { $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), -deg2rad(360 - $fontItem->getRotation())); } }
/** * insert the table header of the shipment * * @param Zend_Pdf_Page $page page to write on */ protected function insertTableHeader($page) { $page->setFillColor($this->colors['grey1']); $page->setLineColor($this->colors['grey1']); $page->setLineWidth(1); $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'] - 10, $this->y - 15); $page->setFillColor($this->colors['black']); $this->_setFontRegular($page, 9); $this->y -= 11; $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'], $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 105, $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 450, $this->y, $this->encoding); }
/** * Insert Table Header for Items * * @param Zend_Pdf_Page $page current page object of Zend_PDF * * @return void */ protected function insertTableHeader(&$page) { $page->setFillColor($this->colors['grey1']); $page->setLineColor($this->colors['grey1']); $page->setLineWidth(1); $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15); $page->setFillColor($this->colors['black']); $font = $this->_setFontRegular($page, 9); $this->y -= 11; $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 130, $this->y, $this->encoding); $columns = array(); $columns['price'] = array('label' => Mage::helper('firegento_pdf')->__('Price'), '_width' => 60); $columns['price_incl_tax'] = array('label' => Mage::helper('firegento_pdf')->__('Price (incl. tax)'), '_width' => 60); $columns['qty'] = array('label' => Mage::helper('firegento_pdf')->__('Qty'), '_width' => 40); $columns['tax'] = array('label' => Mage::helper('firegento_pdf')->__('Tax'), '_width' => 50); $columns['tax_rate'] = array('label' => Mage::helper('firegento_pdf')->__('Tax rate'), '_width' => 50); $columns['subtotal'] = array('label' => Mage::helper('firegento_pdf')->__('Total'), '_width' => 50); $columns['subtotal_incl_tax'] = array('label' => Mage::helper('firegento_pdf')->__('Total (incl. tax)'), '_width' => 70); // draw price, tax, and subtotal in specified order $columnsOrder = explode(',', Mage::getStoreConfig('sales_pdf/invoice/item_price_column_order')); // draw starting from right $columnsOrder = array_reverse($columnsOrder); $columnOffset = 0; foreach ($columnsOrder as $columnName) { $columnName = trim($columnName); if (array_key_exists($columnName, $columns)) { $column = $columns[$columnName]; $labelWidth = $this->widthForStringUsingFontSize($column['label'], $font, 9); $page->drawText($column['label'], $this->margin['right'] - $columnOffset - $labelWidth, $this->y, $this->encoding); $columnOffset += $column['_width']; } } }
// Apply font and draw text $page1->setFont($font, 36) ->setFillColor(Zend_Pdf_Color_Html::color('#9999cc')) ->drawText('Helvetica 36 text string', 60, 500); // Use font object for another page $page2->setFont($font, 24) ->drawText('Helvetica 24 text string', 60, 500); // Use another font $page2->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 32) ->drawText('Times-Roman 32 text string', 60, 450); // Draw rectangle $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)) ->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)) ->setLineDashingPattern(array(3, 2, 3, 4), 1.6) ->drawRectangle(60, 400, 400, 350); // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)) ->drawCircle(85, 375, 25); // Draw sectors $page2->drawCircle(200, 375, 25, 2*M_PI/3, -M_PI/6) ->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0)) ->drawCircle(200, 375, 25, M_PI/6, 2*M_PI/3) ->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0)) ->drawCircle(200, 375, 25, -M_PI/6, M_PI/6);
/** * Insert address to pdf page * * @param Zend_Pdf_Page $page * @param null $store */ protected function insertAddress(&$page, $store = null) { $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $font = $this->_setFontRegular($page, 10); $page->setLineWidth(0); $this->y = $this->y ? $this->y : 815; $top = 815; $collection = Mage::getModel('marketplace/userprofile')->getCollection()->addFieldToFilter('mageuserid', array('eq' => Mage::getSingleton('customer/session')->getCustomerId())); foreach ($collection as $row) { $address = $row->getOthersInfo(); } foreach (explode("\n", $address) as $value) { if ($value !== '') { $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(trim(strip_tags($_value)), $this->getAlignRight($_value, 130, 440, $font, 10), $top, 'UTF-8'); $top -= 10; } } } $this->y = $this->y > $top ? $top : $this->y; }
/** * Generate a review portal pdf. * * @param integer $portalId * @return string The pdf name */ protected function _generatePdf($portalId) { $portal = new Object_ReviewPortal($portalId); if (!$portal->getId()) { return false; } // Get the screenshots of all the portal pages. $pages = Repo_ReviewPortalPage::getInstance()->getPortalPages($portalId); if (!$pages || $pages->count() == 0) { return false; } $pdf = new Zend_Pdf(); $pageNumber = 1; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $fontSize = 10; foreach ($pages as $_p) { $_images = array(); $_page = new Object_Page($_p->id); // Try get static screenshots if the setting is set. if ($_page->screenshot_type == Repo_Page::SCREENSHOT_TYPE_STATIC) { $_images = $_page->getStaticScreenshots(true); } // Get dynamic one. if (empty($_images)) { $_images[] = Manager_ScreenCapture_Page::getInstance()->getScreenshot($_p->id); } foreach ($_images as $_image) { $_pdfImage = Zend_Pdf_Image::imageWithPath($_image); $_pdfPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); $_pdfPage->drawImage($_pdfImage, 20, 36, $_pdfPage->getWidth() - 20, $_pdfPage->getHeight() - 20); $_pdfPage->setFont($font, 16); $_pdfPage->setFillColor(Zend_Pdf_Color_Html::color('#333333'))->drawText($pageNumber, $_pdfPage->getWidth() / 2, 10); $pageNumber++; $pdf->pages[] = $_pdfPage; } } $pdfName = $portalId . '_' . time() . '.pdf'; $path = $this->_rootPath . DS . $pdfName; $pdf->save($path); return $pdfName; }
// Add new page generated by Zend_Pdf_Page object (page is not attached to the document) $pdf->pages[] = $page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); // Create new font $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Apply font and draw text $page1->setFont($font, 36); $page1->setFillColor(Zend_Pdf_Color_HTML::color('#9999cc')); $page1->drawText('Helvetica 36 text string', 60, 500); // Use font object for another page $page2->setFont($font, 24); $page2->drawText('Helvetica 24 text string', 60, 500); // Use another font $page2->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 32); $page2->drawText('Times-Roman 32 text string', 60, 450); // Draw rectangle $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)); $page2->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $page2->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $page2->drawRectangle(60, 400, 400, 350); // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID); $page2->setFillColor(new Zend_Pdf_Color_RGB(1, 0, 0)); $page2->drawCircle(85, 375, 25); // Draw sectors $page2->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6); $page2->setFillColor(new Zend_Pdf_Color_CMYK(1, 0, 0, 0)); $page2->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3); $page2->setFillColor(new Zend_Pdf_Color_RGB(1, 1, 0)); $page2->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6); // Draw ellipse $page2->setFillColor(new Zend_Pdf_Color_RGB(1, 0, 0));
/** * Insert Header * * @param Zend_Pdf_Page $page Current page object of Zend_Pdf * @param Mage_Sales_Model_Order $order Order object * @param object $document Document object * * @return void */ protected function insertHeader(&$page, $order, $document) { $page->setFillColor($this->colors['black']); $mode = $this->getMode(); $this->_setFontBold($page, 15); if ($mode == 'invoice') { $title = 'Invoice'; } elseif ($mode == 'shipment') { $title = 'Shipment'; } else { $title = 'Creditmemo'; } $page->drawText(Mage::helper('firegento_pdf')->__($title), $this->margin['left'], $this->y, $this->encoding); $this->_setFontRegular($page); $this->y += 80; $labelRightOffset = 180; $valueRightOffset = 10; $font = $this->_setFontRegular($page, 10); $width = 80; $numberOfLines = 0; // Invoice/shipment/creditmemo Number if ($mode == 'invoice') { $numberTitle = 'Invoice number:'; } elseif ($mode == 'shipment') { $numberTitle = 'Shipment number:'; } else { $numberTitle = 'Creditmemo number:'; } $page->drawText(Mage::helper('firegento_pdf')->__($numberTitle), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $incrementId = $document->getIncrementId(); $page->drawText($incrementId, $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($incrementId, $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; // Order Number $putOrderId = $this->_putOrderId($order); if ($putOrderId) { $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $page->drawText($putOrderId, $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } // Customer Number if ($this->_showCustomerNumber($order->getStore())) { $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $numberOfLines++; if ($order->getCustomerId() != '') { $prefix = Mage::getStoreConfig('sales_pdf/invoice/customeridprefix'); if (!empty($prefix)) { $customerid = $prefix . $order->getCustomerId(); } else { $customerid = $order->getCustomerId(); } $page->drawText($customerid, $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerid, $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } else { $page->drawText('-', $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize('-', $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } } // Customer IP if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $customerIP = $order->getData('remote_ip'); $font = $this->_setFontRegular($page, 10); $page->drawText($customerIP, $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($customerIP, $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } $page->drawText(Mage::helper('firegento_pdf')->__($mode == 'invoice' ? 'Invoice date:' : 'Date:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); $page->drawText($documentDate, $this->margin['right'] - $valueRightOffset - $this->widthForStringUsingFontSize($documentDate, $font, 10), $this->y, $this->encoding); $this->Ln(); $numberOfLines++; // Payment method. $putPaymentMethod = $mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER; if ($putPaymentMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $paymentMethodArray = $this->_prepareText($order->getPayment()->getMethodInstance()->getTitle(), $page, $font, 10, $width); $page->drawText(array_shift($paymentMethodArray), $this->margin['right'] - $valueRightOffset - $width, $this->y, $this->encoding); $this->Ln(); $numberOfLines++; $paymentMethodArray = $this->_prepareText(implode(" ", $paymentMethodArray), $page, $font, 10, 2 * $width); foreach ($paymentMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } } // Shipping method. $putShippingMethod = $mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER || $mode == 'shipment' && Mage::getStoreConfig('sales_pdf/shipment/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER; if ($putShippingMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $shippingMethodArray = $this->_prepareText($order->getShippingDescription(), $page, $font, 10, $width); $page->drawText(array_shift($shippingMethodArray), $this->margin['right'] - $valueRightOffset - $width, $this->y, $this->encoding); $this->Ln(); $numberOfLines++; $shippingMethodArray = $this->_prepareText(implode(" ", $shippingMethodArray), $page, $font, 10, 2 * $width); foreach ($shippingMethodArray as $methodString) { $page->drawText($methodString, $this->margin['right'] - $labelRightOffset, $this->y, $this->encoding); $this->Ln(); $numberOfLines++; } } $this->y -= $numberOfLines * 2; }
/** * Insert Header * * @param Zend_Pdf_Page $page Current page object of Zend_Pdf * @param object $order Order object * @param object $document Document object * @return void */ protected function insertHeader(&$page, $order, $document) { $page->setFillColor($this->colors['black']); $mode = $this->getMode(); $this->_setFontBold($page, 15); $page->drawText(Mage::helper('firegento_pdf')->__($mode == 'invoice' ? 'Invoice' : 'Creditmemo'), $this->margin['left'], $this->y, $this->encoding); $this->_setFontRegular($page); $this->y += 80; $rightoffset = 180; $page->drawText(Mage::helper('firegento_pdf')->__($mode == 'invoice' ? 'Invoice number:' : 'Creditmemo number:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus = 15; $putOrderId = $this->_putOrderId($order); if ($putOrderId) { $page->drawText(Mage::helper('firegento_pdf')->__('Order number:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } if ($order->getCustomerId() != '') { $page->drawText(Mage::helper('firegento_pdf')->__('Customer number:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { $page->drawText(Mage::helper('firegento_pdf')->__('Customer IP:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } $page->drawText(Mage::helper('firegento_pdf')->__($mode == 'invoice' ? 'Invoice date:' : 'Date:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; // Draw payment method. $putPaymentMethod = $mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/payment_method_position') == FireGento_Pdf_Model_System_Config_Source_Payment::POSITION_HEADER; if ($putPaymentMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Payment method:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } // Draw shipping method. $putShippingMethod = $mode == 'invoice' && Mage::getStoreConfig('sales_pdf/invoice/shipping_method_position') == FireGento_Pdf_Model_System_Config_Source_Shipping::POSITION_HEADER; if ($putShippingMethod) { $page->drawText(Mage::helper('firegento_pdf')->__('Shipping method:'), $this->margin['right'] - $rightoffset, $this->y, $this->encoding); $this->Ln(); $yPlus += 15; } $this->y += $yPlus; $rightoffset = 10; $font = $this->_setFontRegular($page, 10); $incrementId = $document->getIncrementId(); $page->drawText($incrementId, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($incrementId, $font, 10), $this->y, $this->encoding); $this->Ln(); if ($putOrderId) { $page->drawText($putOrderId, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($putOrderId, $font, 10), $this->y, $this->encoding); $this->Ln(); } if ($order->getCustomerId() != '') { $prefix = Mage::getStoreConfig('sales_pdf/invoice/customeridprefix'); if (!empty($prefix)) { $customerid = $prefix . $order->getCustomerId(); } else { $customerid = $order->getCustomerId(); } $page->drawText($customerid, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($customerid, $font, 10), $this->y, $this->encoding); $this->Ln(); } if (!Mage::getStoreConfigFlag('sales/general/hide_customer_ip', $order->getStoreId())) { $customerIP = $order->getData('remote_ip'); $font = $this->_setFontRegular($page, 10); $page->drawText($customerIP, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($customerIP, $font, 10), $this->y, $this->encoding); $this->Ln(); } $documentDate = Mage::helper('core')->formatDate($document->getCreatedAtDate(), 'medium', false); $page->drawText($documentDate, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($documentDate, $font, 10), $this->y, $this->encoding); $this->Ln(); if ($putPaymentMethod) { $paymentMethod = $order->getPayment()->getMethodInstance()->getTitle(); $page->drawText($paymentMethod, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($paymentMethod, $font, 10), $this->y, $this->encoding); $this->Ln(); } if ($putShippingMethod) { $shippingMethod = $order->getShippingDescription(); $page->drawText($shippingMethod, $this->margin['right'] - $rightoffset - $this->widthForStringUsingFontSize($shippingMethod, $font, 10), $this->y, $this->encoding); $this->Ln(); } }
protected static function DrawItems(Zend_Pdf_Page $objPage, $objContributionAmountArray, $intY) { $intXArray = array(20, 92, 200, 308, 465); $objPage->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $objPage->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $objPage->drawRectangle($intXArray[0] - 6, $intY, $intXArray[4] + 6, $intY - 10); $intY -= 7.5; $objPage->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 7); $objPage->drawText('POSTED DATE', $intXArray[0], $intY, 'UTF-8'); $objPage->drawText('CONTRIBUTED BY', $intXArray[1], $intY, 'UTF-8'); $objPage->drawText('FUND', $intXArray[2], $intY, 'UTF-8'); $objPage->drawText('TRANSACTION', $intXArray[3], $intY, 'UTF-8'); self::DrawTextRight($objPage, $intXArray[4], $intY, 'AMOUNT'); $objPage->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $intY -= 3.5; $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 9); foreach ($objContributionAmountArray as $objAmount) { $intY -= 10; $objPage->drawText($objAmount->StewardshipContribution->DateCredited->ToString('MMM D YYYY'), $intXArray[0], $intY, 'UTF-8'); $objPage->drawText($objAmount->StewardshipContribution->Person->Name, $intXArray[1], $intY, 'UTF-8'); $objPage->drawText($objAmount->StewardshipFund->Name, $intXArray[2], $intY, 'UTF-8'); $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7.5); $objPage->drawText($objAmount->StewardshipContribution->TransactionShort, $intXArray[3], $intY, 'UTF-8'); $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 9); $strAmount = QApplication::DisplayCurrency($objAmount->Amount); if ($objAmount->StewardshipContribution->NonDeductibleFlag) { $strAmount = $strAmount . ' (*)'; } self::DrawTextRight($objPage, $intXArray[4], $intY, $strAmount); } }
/** * Insert order to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Order $obj * @param bool $putOrderId */ protected function insertOrder(&$page, $obj, $putOrderId = true) { if ($obj instanceof Mage_Sales_Model_Order) { $shipment = null; $order = $obj; } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) { $shipment = $obj; $order = $shipment->getOrder(); } $this->y = $this->y ? $this->y : 815; $top = $this->y; //$theitemm = Mage::getStoreConfig('system_config_name/groups/estoreiq_logo'); //$eye_logo_image = Mage::getStoreConfig('estoreiq_options/messages/estoreiq_logo'); //$theitemm = Mage::getBaseDir('media') . '/estoreiq-logo/' . $eye_logo_image; //$page->drawText( //'img: '.$theitemm, //35, //($top -= 15), // 'UTF-8' // ); $top -= 15; $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, $top, 275, ($top - 25)); //$page->drawRectangle(275, $top, 570, ($top - 25)); /* Calculate blocks info */ /* Billing Address */ /* $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf')); */ /* Payment */ /* $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment()) ->setIsSecureMode(true) ->toPdf(); $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES); $payment = explode('{{pdf_row_separator}}', $paymentInfo); foreach ($payment as $key=>$value){ if (strip_tags(trim($value)) == '') { unset($payment[$key]); } } reset($payment); */ /* Shipping Address and Method */ if (!$order->getIsVirtual()) { /* Shipping Address */ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf')); $shippingMethod = $order->getShippingDescription(); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontBold($page, 12); //$page->drawText(Mage::helper('sales')->__('Sold to:'), 35, ($top - 15), 'UTF-8'); if (!$order->getIsVirtual()) { //$page->drawText(Mage::helper('sales')->__('Ship to:'), 285, ($top - 15), 'UTF-8'); } else { //$page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, ($top - 15), 'UTF-8'); } $addressesHeight = $this->_calcAddressHeight($billingAddress); if (isset($shippingAddress)) { $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress)); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); //$page->drawRectangle(25, ($top - 25), 570, $top - 33 - $addressesHeight); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontRegular($page, 10); $this->y = $top + 40; $addressesStartY = $this->y; foreach ($billingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { if (strpos($part, "F:") === false) { $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8'); $this->y -= 15; } } } } $addressesEndY = $this->y; if (!$order->getIsVirtual()) { $this->y = $addressesStartY; foreach ($shippingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { if (strpos($part, "F:") === false) { $page->drawText(strip_tags(ltrim($part)), 235, $this->y, 'UTF-8'); $this->y -= 15; } } } } $addressesEndY = min($addressesEndY, $this->y); $this->y = $addressesEndY; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); //$page->drawRectangle(25, $this->y, 275, $this->y-25); //$page->drawRectangle(275, $this->y, 570, $this->y-25); $this->y -= 15; $this->_setFontBold($page, 12); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); //$page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8'); //$page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y , 'UTF-8'); $this->y -= 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page, 10); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $paymentLeft = 35; $yPayments = $this->y - 15; } else { $yPayments = $addressesStartY; $paymentLeft = 285; } /* foreach ($payment as $value){ if (trim($value) != '') { //Printing "Payment Method" lines $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8'); $yPayments -= 15; } } } */ /* if ($order->getIsVirtual()) { // replacement of Shipments-Payments rectangle block $yPayments = min($addressesEndY, $yPayments); //$page->drawLine(25, ($top - 25), 25, $yPayments); //$page->drawLine(570, ($top - 25), 570, $yPayments); //$page->drawLine(25, $yPayments, 570, $yPayments); $this->y = $yPayments - 15; } else { $topMargin = 15; $methodStartY = $this->y; $this->y -= 15; foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8'); $this->y -= 15; } $yShipments = $this->y; $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " " . $order->formatPriceTxt($order->getShippingAmount()) . ")"; $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8'); $yShipments -= $topMargin + 10; $tracks = array(); if ($shipment) { $tracks = $shipment->getAllTracks(); } if (count($tracks)) { $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); //$page->drawRectangle(285, $yShipments, 510, $yShipments - 10); //$page->drawLine(400, $yShipments, 400, $yShipments - 10); //$page->drawLine(510, $yShipments, 510, $yShipments - 10); $this->_setFontRegular($page, 9); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8'); $yShipments -= 20; $this->_setFontRegular($page, 8); foreach ($tracks as $track) { $CarrierCode = $track->getCarrierCode(); if ($CarrierCode != 'custom') { $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode); $carrierTitle = $carrier->getConfigData('title'); } else { $carrierTitle = Mage::helper('sales')->__('Custom Value'); } //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : ''); $maxTitleLen = 45; $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : ''; $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle; //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8'); $page->drawText($truncatedTitle, 292, $yShipments , 'UTF-8'); $page->drawText($track->getNumber(), 410, $yShipments , 'UTF-8'); $yShipments -= $topMargin - 5; } } else { $yShipments -= $topMargin - 5; } $currentY = min($yPayments, $yShipments); // replacement of Shipments-Payments rectangle block //$page->drawLine(25, $methodStartY, 25, $currentY); //left //$page->drawLine(25, $currentY, 570, $currentY); //bottom //$page->drawLine(570, $currentY, 570, $methodStartY); //right $this->y = $currentY; $this->y -= 15; } */ if ($putOrderId) { $page->drawText(Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, $top -= 195, 'UTF-8'); } $page->drawText(Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'medium', false), 35, $top -= 15, 'UTF-8'); }
$page->drawText('Modified by Zend Framework!', 150, 0)->restoreGS(); } // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page1 = $pdf->newPage('A4'); // Add new page generated by Zend_Pdf_Page object (page is not attached to the document) $pdf->pages[] = $page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); // Create new font $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Apply font and draw text $page1->setFont($font, 36)->setFillColor(Zend_Pdf_Color_Html::color('#9999cc'))->drawText('Helvetica 36 text string', 60, 500); // Use font object for another page $page2->setFont($font, 24)->drawText('Helvetica 24 text string', 60, 500); // Use another font $page2->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 32)->drawText('Times-Roman 32 text string', 60, 450); // Draw rectangle $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8))->setLineColor(new Zend_Pdf_Color_GrayScale(0.2))->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->drawRectangle(60, 400, 400, 350); // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID)->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))->drawCircle(85, 375, 25); // Draw sectors $page2->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6)->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6); // Draw ellipse $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))->drawEllipse(250, 400, 400, 350)->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))->drawEllipse(250, 400, 400, 350, M_PI / 6, 2 * M_PI / 3)->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))->drawEllipse(250, 400, 400, 350, -M_PI / 6, M_PI / 6); // Draw and fill polygon $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1)); $x = array(); $y = array(); for ($count = 0; $count < 8; $count++) { $x[] = 140 + 25 * cos(3 * M_PI_4 * $count); $y[] = 375 + 25 * sin(3 * M_PI_4 * $count); } $page2->drawPolygon($x, $y, Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, Zend_Pdf_Page::FILL_METHOD_EVEN_ODD);
/** * Insert address to pdf page * * @param Zend_Pdf_Page $page * @param null $store */ protected function insertAddress(&$page, $store = null) { $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $font = $this->_setFontRegular($page, 9); $page->setLineWidth(0); $this->y = $this->y ? $this->y : 815; $top = $this->y; $page->drawText(Mage::helper('sales')->__('Sold By'), 35, $top - 35, 'UTF-8'); foreach (explode("\n", Mage::getStoreConfig('sales/identity/address', $store)) as $value) { if ($value !== '') { $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(trim(strip_tags($_value)), 35, $top - 50, 'UTF-8'); $top -= 10; } } } $this->y = $this->y > $top ? $top : $this->y; }
public function testPageCloning() { $pdf = Zend_Pdf::load(dirname(__FILE__) . '/_files/pdfarchiving.pdf'); $srcPageCount = count($pdf->pages); try { $newPage = clone reset($pdf->pages); } catch (Zend_Pdf_Exception $e) { if (strpos($e->getMessage(), 'Cloning Zend_Pdf_Page object using \'clone\' keyword is not supported.') !== 0) { throw $e; } // Exception is thrown } $outputPageSet = array(); foreach ($pdf->pages as $srcPage) { $page = new Zend_Pdf_Page($srcPage); $outputPageSet[] = $srcPage; $outputPageSet[] = $page; $page->saveGS(); // Create new Style $page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0.9))->setLineColor(new Zend_Pdf_Color_GrayScale(0.2))->setLineWidth(3)->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32); $page->rotate(0, 0, M_PI_2 / 3); $page->drawText('Modified by Zend Framework!', 150, 0); $page->restoreGS(); } // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages = $outputPageSet; $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); $this->assertEquals($srcPageCount * 2, count($pdf1->pages)); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
/** * @refactor big method, code from 'if' can move to helper * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Order $obj * @param bool $putOrderId */ protected function insertOrder(&$page, $obj, $putOrderId = true) { if (version_compare(Mage::getVersion(), '1.7.0', '<')) { if ($obj instanceof Mage_Sales_Model_Order) { $shipment = null; $order = $obj; } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) { $shipment = $obj; $order = $shipment->getOrder(); } /* @var $order Mage_Sales_Model_Order */ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->drawRectangle(25, 790, 570, 755); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); if ($putOrderId) { $page->drawText(Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, 770, 'UTF-8'); } //$page->drawText(Mage::helper('sales')->__('Order Date: ') . date( 'D M j Y', strtotime( $order->getCreatedAt() ) ), 35, 760, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'medium', false), 35, 760, 'UTF-8'); $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, 755, 275, 730); $page->drawRectangle(275, 755, 570, 730); /* Calculate blocks info */ /* Billing Address */ $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf')); /* Payment */ $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf(); $payment = explode('{{pdf_row_separator}}', $paymentInfo); foreach ($payment as $key => $value) { if (strip_tags(trim($value)) == '') { unset($payment[$key]); } } reset($payment); /* Shipping Address and Method */ if (!$order->getIsVirtual()) { /* Shipping Address */ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf')); $shippingMethod = $order->getShippingDescription(); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontRegular($page); $page->drawText(Mage::helper('sales')->__('SOLD TO:'), 35, 740, 'UTF-8'); if (!$order->getIsVirtual()) { $page->drawText(Mage::helper('sales')->__('SHIP TO:'), 285, 740, 'UTF-8'); } else { $page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, 740, 'UTF-8'); } if (!$order->getIsVirtual()) { $y = 730 - (max(count($billingAddress), count($shippingAddress)) * 10 + 5); } else { $y = 730 - (count($billingAddress) * 10 + 5); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(25, 730, 570, $y); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontRegular($page); $this->y = 720; foreach ($billingAddress as $value) { if ($value !== '') { $page->drawText(strip_tags(ltrim($value)), 35, $this->y, 'UTF-8'); $this->y -= 10; } } if (!$order->getIsVirtual()) { if (Mage::helper('aitconfcheckout')->getShippingEnabled() || Mage::getStoreConfig('aitconfcheckout/shipping/copytoshipping')) { $this->y = 720; } foreach ($shippingAddress as $value) { if ($value !== '') { $page->drawText(strip_tags(ltrim($value)), 285, $this->y, 'UTF-8'); $this->y -= 10; } } $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 275, $this->y - 25); $page->drawRectangle(275, $this->y, 570, $this->y - 25); $this->y -= 15; $this->_setFontBold($page); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y, 'UTF-8'); $this->y -= 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $paymentLeft = 35; $yPayments = $this->y - 15; } else { $yPayments = 720; $paymentLeft = 285; } foreach ($payment as $value) { if (trim($value) !== '') { $page->drawText(strip_tags(trim($value)), $paymentLeft, $yPayments, 'UTF-8'); $yPayments -= 10; } } if (!$order->getIsVirtual()) { $this->y -= 15; $page->drawText($shippingMethod, 285, $this->y, 'UTF-8'); if (Mage::helper('core')->isModuleEnabled('AdjustWare_Deliverydate')) { if ($order->getDeliveryDate()) { $delivery_date = Mage::helper('adjdeliverydate')->formatDate($order->getDeliveryDate(), 'medium', Mage::getStoreConfig('checkout/adjdeliverydate/show_time')); $page->drawText(strip_tags(trim(Mage::helper('adjdeliverydate')->__('Delivery Date: ') . $delivery_date)), 285, $this->y, 'UTF-8'); $this->y -= 15; } } $yShipments = $this->y; $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " " . $order->formatPriceTxt($order->getShippingAmount()) . ")"; $page->drawText($totalShippingChargesText, 285, $yShipments - 7, 'UTF-8'); $yShipments -= 10; $tracks = array(); if ($shipment) { $tracks = $shipment->getAllTracks(); } if (count($tracks)) { $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(285, $yShipments, 510, $yShipments - 10); $page->drawLine(380, $yShipments, 380, $yShipments - 10); //$page->drawLine(510, $yShipments, 510, $yShipments - 10); $this->_setFontRegular($page); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Number'), 385, $yShipments - 7, 'UTF-8'); $yShipments -= 17; $this->_setFontRegular($page, 6); foreach ($tracks as $track) { $CarrierCode = $track->getCarrierCode(); if ($CarrierCode != 'custom') { $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode); $carrierTitle = $carrier->getConfigData('title'); } else { $carrierTitle = Mage::helper('sales')->__('Custom Value'); } //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : ''); $truncatedTitle = substr($track->getTitle(), 0, 45) . (strlen($track->getTitle()) > 45 ? '...' : ''); //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8'); $page->drawText($truncatedTitle, 300, $yShipments, 'UTF-8'); $page->drawText($track->getNumber(), 395, $yShipments, 'UTF-8'); $yShipments -= 7; } } else { $yShipments -= 7; } $currentY = min($yPayments, $yShipments); // replacement of Shipments-Payments rectangle block $page->drawLine(25, $this->y + 15, 25, $currentY); $page->drawLine(25, $currentY, 570, $currentY); $page->drawLine(570, $currentY, 570, $this->y + 15); $this->y = $currentY; $this->y -= 15; } if ((string) Mage::getConfig()->getModuleConfig('Aitoc_Aitcheckoutfields')->active == 'true') { $this->_drawCheckoutAttributes($page, $obj); } } else { parent::insertOrder($page, $obj, $putOrderId = true); } }
/** * Insert title and number for concrete document type * * @param \Zend_Pdf_Page $page * @param string $text * @return void */ public function insertDocumentNumber(\Zend_Pdf_Page $page, $text) { $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page, 10); $docHeader = $this->getDocHeaderCoordinates(); $page->drawText($text, 35, $docHeader[1] - 15, 'UTF-8'); }
/** * Draw table header for product items * * @param Zend_Pdf_Page $page page to draw on * * @return void */ protected function _drawHeader(Zend_Pdf_Page $page) { $page->setFillColor($this->colors['grey1']); $page->setLineColor($this->colors['grey1']); $page->setLineWidth(1); $page->drawRectangle($this->margin['left'], $this->y, $this->margin['right'], $this->y - 15); $page->setFillColor($this->colors['black']); $font = $this->_setFontRegular($page, 9); $this->y -= 11; $page->drawText(Mage::helper('firegento_pdf')->__('Pos'), $this->margin['left'] + 3, $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('No.'), $this->margin['left'] + 25, $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('Description'), $this->margin['left'] + 120, $this->y, $this->encoding); $singlePrice = Mage::helper('firegento_pdf')->__('Price (excl. tax)'); $page->drawText($singlePrice, $this->margin['right'] - 153 - $this->widthForStringUsingFontSize($singlePrice, $font, 9), $this->y, $this->encoding); $page->drawText(Mage::helper('firegento_pdf')->__('Qty'), $this->margin['left'] + 360, $this->y, $this->encoding); $taxLabel = Mage::helper('firegento_pdf')->__('Tax'); $page->drawText($taxLabel, $this->margin['right'] - 65 - $this->widthForStringUsingFontSize($taxLabel, $font, 9), $this->y, $this->encoding); $totalLabel = Mage::helper('firegento_pdf')->__('Total'); $page->drawText($totalLabel, $this->margin['right'] - 10 - $this->widthForStringUsingFontSize($totalLabel, $font, 10), $this->y, $this->encoding); }
/** * Draw packages block * * @param \Zend_Pdf_Page $page * @return \Magento\Shipping\Model\Order\Pdf\Packaging * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _drawPackageBlock(\Zend_Pdf_Page $page) { if ($this->getPackageShippingBlock()) { $packaging = $this->getPackageShippingBlock(); } else { $packaging = $this->_layout->getBlockSingleton('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging'); } $packages = $packaging->getPackages(); $packageNum = 1; foreach ($packages as $package) { $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->setFillColor(new \Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(520, $this->y + 15, 570, $this->y - 5); $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); $packageText = __('Package') . ' ' . $packageNum; $page->drawText($packageText, 525, $this->y, 'UTF-8'); $packageNum++; $package = new \Magento\Framework\DataObject($package); $params = new \Magento\Framework\DataObject($package->getParams()); $dimensionUnits = $this->_carrierHelper->getMeasureDimensionName($params->getDimensionUnits()); $typeText = __('Type') . ' : ' . $packaging->getContainerTypeByCode($params->getContainer()); $page->drawText($typeText, 35, $this->y, 'UTF-8'); if ($params->getLength() != null) { $lengthText = $params->getLength() . ' ' . $dimensionUnits; } else { $lengthText = '--'; } $lengthText = __('Length') . ' : ' . $lengthText; $page->drawText($lengthText, 200, $this->y, 'UTF-8'); if ($params->getDeliveryConfirmation() != null) { $confirmationText = __('Signature Confirmation') . ' : ' . $packaging->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation()); $page->drawText($confirmationText, 355, $this->y, 'UTF-8'); } $this->y = $this->y - 10; if ($packaging->displayCustomsValue() != null) { $customsValueText = __('Customs Value') . ' : ' . $packaging->displayPrice($params->getCustomsValue()); $page->drawText($customsValueText, 35, $this->y, 'UTF-8'); } if ($params->getWidth() != null) { $widthText = $params->getWidth() . ' ' . $dimensionUnits; } else { $widthText = '--'; } $widthText = __('Width') . ' : ' . $widthText; $page->drawText($widthText, 200, $this->y, 'UTF-8'); if ($params->getContentType() != null) { if ($params->getContentType() == 'OTHER') { $contentsValue = $params->getContentTypeOther(); } else { $contentsValue = $packaging->getContentTypeByCode($params->getContentType()); } $contentsText = __('Contents') . ' : ' . $contentsValue; $page->drawText($contentsText, 355, $this->y, 'UTF-8'); } $this->y = $this->y - 10; $weightText = __('Total Weight') . ' : ' . $params->getWeight() . ' ' . $this->_carrierHelper->getMeasureWeightName($params->getWeightUnits()); $page->drawText($weightText, 35, $this->y, 'UTF-8'); if ($params->getHeight() != null) { $heightText = $params->getHeight() . ' ' . $dimensionUnits; } else { $heightText = '--'; } $heightText = __('Height') . ' : ' . $heightText; $page->drawText($heightText, 200, $this->y, 'UTF-8'); $this->y = $this->y - 10; if ($params->getSize()) { $sizeText = __('Size') . ' : ' . ucfirst(strtolower($params->getSize())); $page->drawText($sizeText, 35, $this->y, 'UTF-8'); } if ($params->getGirth() != null) { $dimensionGirthUnits = $this->_carrierHelper->getMeasureDimensionName($params->getGirthDimensionUnits()); $girthText = __('Girth') . ' : ' . $params->getGirth() . ' ' . $dimensionGirthUnits; $page->drawText($girthText, 200, $this->y, 'UTF-8'); } $this->y = $this->y - 5; $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(25, $this->y, 570, $this->y - 30 - count($package->getItems()) * 12); $this->y = $this->y - 10; $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); $page->drawText(__('Items in the Package'), 30, $this->y, 'UTF-8'); $txtIndent = 5; $itemCollsNumber = $packaging->displayCustomsValue() ? 5 : 4; $itemCollsX[0] = 30; // coordinate for Product name $itemCollsX[1] = 250; // coordinate for Product name $itemCollsXEnd = 565; $itemCollsXStep = round(($itemCollsXEnd - $itemCollsX[1]) / ($itemCollsNumber - 1)); // calculate coordinates for all other cells (Weight, Customs Value, Qty Ordered, Qty) for ($i = 2; $i <= $itemCollsNumber; $i++) { $itemCollsX[$i] = $itemCollsX[$i - 1] + $itemCollsXStep; } $i = 0; $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsXEnd, $this->y - 15); $this->y = $this->y - 12; $i = 0; $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); $page->drawText(__('Product'), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText(__('Weight'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); if ($packaging->displayCustomsValue()) { $page->drawText(__('Customs Value'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $page->drawText(__('Qty Ordered'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText(__('Qty'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $i = 0; foreach ($package->getItems() as $itemId => $item) { $item = new \Magento\Framework\DataObject($item); $i = 0; $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsXEnd, $this->y - 15); $this->y = $this->y - 12; $i = 0; $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0)); $page->drawText($item->getName(), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText($item->getWeight(), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); if ($packaging->displayCustomsValue()) { $page->drawText($packaging->displayPrice($item->getCustomsValue()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $page->drawText($packaging->getQtyOrderedItem($item->getOrderItemId()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText($item->getQty() * 1, $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $this->y = $this->y - 30; } return $this; }
public function downloadAction() { if ($this->_loadValidVoucher()) { $voucherCode = $this->getRequest()->getParam('code'); $text = Mage::helper('voucher'); $_product = Mage::registry('current_product'); $pdf = new Zend_Pdf(); $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER); $pageHeight = $page->getHeight(); $pageWidth = $page->getWidth(); //$page->rotate(($pageWidth/2), ($pageHeight/2), 1); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $logoImage = Zend_Pdf_Image::imageWithPath(Mage::getDesign()->getSkinBaseDir() . '/images/logo_small_en.jpg'); //$footerImage = Zend_Pdf_Image::imageWithPath(Mage::getDesign()->getSkinBaseDir() . '/images/voucher_footer_en.png'); //VD $productImage = Zend_Pdf_Image::imageWithPath(Mage::getBaseDir() . '/media/catalog/product' . $_product->getVoucherImage()); //$footerImageHeight = $footerImage->getPixelHeight(); //VD //$footerImageWidth = $footerImage->getPixelWidth(); //VD $logoImageHeight = 75; //VDEdit $logoImageWidth = 250; //VDEdit $tableWidth = 568; $startPoint = ($pageWidth - $tableWidth) / 2; $endPoint = $startPoint + $tableWidth; $botPoint = 10; $topPoint = $pageHeight - 30; $page->setLineWidth('0.3')->setLineDashingPattern(array(3, 3, 3, 3))->drawLine($startPoint, $topPoint, $startPoint, $botPoint)->drawLine($endPoint, $topPoint, $endPoint, $botPoint)->drawLine($startPoint, $topPoint, $endPoint, $topPoint)->drawLine($startPoint, $botPoint, $endPoint, $botPoint)->drawLine($startPoint, $pageHeight - $logoImageHeight - 235, $endPoint, $pageHeight - $logoImageHeight - 235)->drawLine($startPoint, $pageHeight - $logoImageHeight - 235 - 325, $endPoint, $pageHeight - $logoImageHeight - 235 - 325); $page->setFillColor(Zend_Pdf_Color_Html::color('#16599D'))->drawRectangle($startPoint + 2, $topPoint - $logoImageHeight - 2, $endPoint, $topPoint); $page->drawImage($logoImage, $startPoint, $topPoint - $logoImageHeight - 1, $startPoint + $logoImageWidth, $topPoint); //$page->drawImage($footerImage, $startPoint + 2, $botPoint, $startPoint + $footerImageWidth - 20, $botPoint + $footerImageHeight); $page->drawImage($productImage, $startPoint + 7, $topPoint - 55 - $productImage->getPixelHeight(), $startPoint + 7 + 246, $topPoint - 55 - $productImage->getPixelHeight() + 165); $page->setFillColor(Zend_Pdf_Color_Html::color('#FFFFFF'))->setLineDashingPattern(array(1, 0, 1, 0))->drawRectangle($endPoint - 205, $topPoint - 10, $endPoint - 15, $topPoint + 10)->setLineDashingPattern(array(0, 1000, 0, 1000))->setFillColor(Zend_Pdf_Color_Html::color('#EDF4FA'))->drawRectangle($startPoint + 0.3, $pageHeight - $logoImageHeight - 235, $endPoint, $pageHeight - $logoImageHeight - 235 - 325); $style = new Zend_Pdf_Style(); $style->setFont($font, 15); $page->setFont($font, 12)->setFillColor(Zend_Pdf_Color_Html::color('#000000'))->drawText($text->__('Voucher Code: ' . $voucherCode), $endPoint - 193, $topPoint - 4)->setFont($font, 15); $lines = explode("\n", $this->getWrappedText($text->__('Voucher for ') . $_product->getName(), $style, 270)); //var_dump($lines); foreach ($lines as $k => $line) { $page->drawText($line, $startPoint + $productImage->getPixelWidth() + 20, $topPoint - 70 - $k * 20); } // $pdf->pages[0] = $page; $pdf->save(Mage::getBaseDir() . '/media/vouchers/' . $voucherCode . '.pdf'); $this->getResponse()->clearHeaders()->setHeader('content-type:', 'Application/pdf')->setHeader('Content-Type', 'application/force-download')->setHeader('Content-Disposition', 'attachment; filename="' . $voucherCode . '.pdf"')->setBody($pdf->render()); } }