public function process() { $configuracao = Doctrine::getTable('Configuracao')->find(1); $this->document->pages[] = $page = $this->document->newPage(\Zend_Pdf_Page::SIZE_A4); //monta o cabecalho $color = array(); $color["black"] = new Zend_Pdf_Color_Html("#000000"); $fontTitle = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES_BOLD); $size = 12; $styleTitle = new Zend_Pdf_Style(); $styleTitle->setFont($fontTitle, $size); $styleTitle->setFillColor($color["black"]); $page->setStyle($styleTitle); $page->drawText($configuracao->instituicao, Documento::DOCUMENT_LEFT, Documento::DOCUMENT_TOP, 'UTF-8'); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $style = new Zend_Pdf_Style(); $style->setFont($font, $size); $style->setFillColor($color["black"]); $page->setStyle($style); $text = wordwrap($this->text, 95, "\n", false); $token = strtok($text, "\n"); $y = 665; while ($token != false) { if ($y < 100) { $this->document->pages[] = $page = $this->document->newPage(Zend_Pdf_Page::SIZE_A4); $page->setStyle($style); $y = 665; } else { $y -= 15; } $page->drawText($token, 60, $y, 'UTF-8'); $token = strtok("\n"); } }
public function getPdf($bidon = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice'); //on cree le pdf que si il n'est pas déja défini( ca permet de mettre plrs documents dans le mm pdf (genre une facture, un BL ....) if ($this->pdf == null) { $this->pdf = new Zend_Pdf(); } $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); //cree la nouvelle page $titre = mage::helper('purchase')->__('Picking List'); $settings = array(); $settings['title'] = $titre; $settings['store_id'] = 0; $page = $this->NewPage($settings); //affiche l'entete du tableau $this->drawTableHeader($page); $this->y -= 10; //Affiche le récap des produits $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); //charge la collection des produits $collection = Mage::getModel('Orderpreparation/ordertoprepare')->GetProductsSummary(); foreach ($collection as $product) { //dessine $page->drawText($product->getqty_to_prepare(), 15, $this->y, 'UTF-8'); $page->drawText($product->getAttributeText('manufacturer'), 70, $this->y, 'UTF-8'); $page->drawText($product->getSku(), 180, $this->y, 'UTF-8'); $page->drawText($product->getName(), 310, $this->y, 'UTF-8'); //rajoute une ligne de séparation $page->setLineWidth(0.5); $page->drawLine(10, $this->y - 4, $this->_BLOC_ENTETE_LARGEUR, $this->y - 4); $this->y -= $this->_ITEM_HEIGHT; //si on a plus la place de rajouter le footer, on change de page if ($this->y < $this->_BLOC_FOOTER_HAUTEUR + 40) { $this->drawFooter($page); $page = $this->NewPage($settings); $this->drawTableHeader($page); } } //dessine le pied de page $this->drawFooter($page); //rajoute la pagination $this->AddPagination($this->pdf); $this->_afterGetPdf(); return $this->pdf; }
public function __construct($labels = array()) { $cols = null; foreach ($labels as $label) { $col = new Core_Pdf_Table_Column(); $col->setText($label); $cols[] = $col; } if ($cols) { $this->setColumns($cols); } //set default alignment $this->_align = Core_Pdf::CENTER; //set default borders $style = new Zend_Pdf_Style(); $style->setLineWidth(2); $this->setBorder(Core_Pdf::BOTTOM, $style); $this->setCellPaddings(array(5, 5, 5, 5)); //set default font $this->_font = Zend_Pdf_Font::fontWithName(ZEND_Pdf_Font::FONT_HELVETICA_BOLD); $this->_fontSize = 12; }
public function getPdf($orders = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice'); //on cree le pdf que si il n'est pas déja défini( ca permet de mettre plrs documents dans le mm pdf (genre une facture, un BL ....) $this->pdf = new Zend_Pdf(); $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); //cree la nouvelle page $titre = mage::helper('purchase')->__('Order Comments'); $settings = array(); $settings['title'] = $titre; $settings['store_id'] = 0; $page = $this->NewPage($settings); $this->y -= $this->_ITEM_HEIGHT * 2; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); //Rajoute les commandes avec commentaires foreach ($orders as $order) { $comments = mage::helper('Organizer')->getEntityCommentsSummary('order', $order->getorder_id(), false); if ($comments != '') { $realOrder = mage::getModel('sales/order')->load($order->getorder_id()); $page->drawText(mage::helper('purchase')->__('Order # ') . $realOrder->getIncrementId(), 15, $this->y, 'UTF-8'); $comments = $this->WrapTextToWidth($page, $comments, 450); $offset = $this->DrawMultilineText($page, $comments, 150, $this->y, 10, 0.2, 11); $this->y -= 8 + $offset; $page->drawLine(10, $this->y, $this->_BLOC_ENTETE_LARGEUR, $this->y); $this->y -= 15; } } //dessine le pied de page $this->drawFooter($page); //rajoute la pagination $this->AddPagination($this->pdf); $this->_afterGetPdf(); return $this->pdf; }
public function setStyle() { $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); $style->setFillColor(new Zend_Pdf_Color_Html('#333333')); $style->setLineColor(new Zend_Pdf_Color_Html('#990033')); $style->setLineWidth(1); $this->_page->setStyle($style); }
public function remittanceInvoice($batch_id = 27, $shop_date_remittance = null) { $user = $this; $page_count = 0; $footer_added = 0; $pdf = new Zend_Pdf(); $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $page = $pdf->pages[$page_count]; $style = new Zend_Pdf_Style(); $style->setLineColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $style->setFont($font, 16); $page->setStyle($style); $page_height = $page->getHeight(); $page->drawText('RECIPIENT CREATED TAX INVOICE', 150, $page_height - 80); $style->setFont($font, 12); $page->setStyle($style); $company = trim($user->company) != '' ? $user->company : $user->first_name . ' ' . $user->last_name; $address1 = !empty($this->delivery_address1) ? $this->delivery_address1 . ' ' : null; $address1 .= !empty($this->delivery_address2) ? $this->delivery_address2 . ' ' : null; $address1 .= !empty($this->delivery_city) ? $this->delivery_city . ' ' : null; $address2 = !empty($this->delivery_state) ? $this->delivery_state . ', ' : null; $address2 .= !empty($this->delivery_postcode) ? $this->delivery_postcode : null; $page->drawText($company, 50, $page->getHeight() - 120); $page->drawText($address1, 50, $page->getHeight() - 133); $page->drawText($address2, 50, $page->getHeight() - 147); $page->drawText('ABN # ' . $this->abn, 50, $page->getHeight() - 160); $remittanceDate = !empty($shop_date_remittance) ? date('d/m/Y') : date('d/m/Y'); $invoice_number = $this->id . '-' . $batch_id; $page->drawText('Remittance Date: ' . $remittanceDate, 400, $page->getHeight() - 120); $page->drawText('Invoice number: ' . $invoice_number, 400, $page->getHeight() - 133); $style->setFont($font, 10); $page->setStyle($style); $page->drawText('Note: only items that were sold with GST applicable will appear on this invoice', 100, $page->getHeight() - 188); $head_row_height = 20; $row_height = 20; $line_height_start = $page_height - 200; $total_data_row = 30; $page_break_row = 25; $textline_height = 12; $spModel = Base::getModel('Shop_Products'); $select = $spModel->select()->setIntegrityCheck(false)->from(array('sp' => 'shop_products')); //join with common_items $select->join(array('ci' => 'common_items'), 'sp.client_product_id = ci.client_product_id', array('sum(ci.copies) as copies, sum(ci.copies*ci.shop_markup) as shop_markup, ci.registered_gst as gst', 'ci.registered_gst')); $select->where('ci.remittance_batch_id = ?', $batch_id); if (!empty($shop_date_remittance)) { $select->where('ci.shop_date_remittance = ?', $shop_date_remittance); } $select->where('sp.common_user_id = ?', $user->id); $select->where('ci.registered_gst = 1'); $select->group(array('sp.common_user_id', 'gst')); $shop_markup_inc_gst = $shop_markup_exc_gst = ''; //Zend_Debug::dump((string)$select); die(); $rows = $spModel->fetchAll($select); $total_data_row = $rows->count(); $i = 1; $j = 1; $total_copies = 0; $total_Ex_GST = $total_Inc_GST = 0.0; foreach ($rows as $row) { if ($i == 1) { $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES_BOLD); $style->setFont($font, 10); $page->setStyle($style); $page->drawLine(60, $line_height_start, 540, $line_height_start)->drawLine(60, $line_height_start, 60, $line_height_start - $head_row_height)->drawLine(300, $line_height_start, 300, $line_height_start - $head_row_height)->drawLine(360, $line_height_start, 360, $line_height_start - $head_row_height)->drawLine(450, $line_height_start, 450, $line_height_start - $head_row_height)->drawLine(60, $line_height_start - $head_row_height, 540, $line_height_start - $head_row_height)->drawLine(540, $line_height_start, 540, $line_height_start - $head_row_height)->drawText('Description', 68, $line_height_start - $textline_height)->drawText('Copies', 308, $line_height_start - $textline_height)->drawText('Ex-GST Amount', 368, $line_height_start - $textline_height)->drawText('Inc-GST Amount', 458, $line_height_start - $textline_height); // Table Headers $line_height_start = $line_height_start - $head_row_height; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $style->setFont($font, 10); $page->setStyle($style); } $shop_markup = sprintf("%01.2f", $row->shop_markup); $shop_markup_len = strlen($shop_markup); $num_pad = 5 * ($shop_markup_len - 4); $page->drawLine(60, $line_height_start, 540, $line_height_start)->drawLine(60, $line_height_start, 60, $line_height_start - $row_height)->drawLine(300, $line_height_start, 300, $line_height_start - $row_height)->drawLine(360, $line_height_start, 360, $line_height_start - $row_height)->drawLine(450, $line_height_start, 450, $line_height_start - $row_height)->drawLine(60, $line_height_start - $row_height, 540, $line_height_start - $row_height)->drawLine(540, $line_height_start, 540, $line_height_start - $row_height)->drawText($row->title, 68, $line_height_start - $textline_height)->drawText($row->copies, 330, $line_height_start - $textline_height)->drawText($row->gst == 1 ? sprintf("%01.2f", $shop_markup - $shop_markup / 11) : sprintf("%01.2f", $shop_markup), 425 - $num_pad, $line_height_start - $textline_height)->drawText(sprintf("%01.2f", $shop_markup), 515 - $num_pad, $line_height_start - $textline_height); // Table Headers $line_height_start = $line_height_start - $row_height; $total_copies += $row->copies; $total_Inc_GST += $shop_markup; if ($row->gst == 1) { $total_Ex_GST += $shop_markup - $shop_markup / 11; } else { $total_Ex_GST += $shop_markup; } $footer_added = 0; if ($j == $total_data_row) { $total_Ex_GST = sprintf("%01.2f", $total_Ex_GST); $total_Inc_GST = sprintf("%01.2f", $total_Inc_GST); $len = strlen($total_Ex_GST); $ex_gst_num_pad = 5 * ($len - 4); $len = strlen($total_Inc_GST); $inc_gst_num_pad = 5 * ($len - 4); $len = strlen($total_copies); $copies_num_pad = 5 * ($len - 1); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES_BOLD); $style->setFont($font, 10); $page->setStyle($style); $page->drawLine(60, $line_height_start, 540, $line_height_start)->drawLine(60, $line_height_start, 60, $line_height_start - $head_row_height)->drawLine(300, $line_height_start, 300, $line_height_start - $head_row_height)->drawLine(360, $line_height_start, 360, $line_height_start - $head_row_height)->drawLine(450, $line_height_start, 450, $line_height_start - $head_row_height)->drawLine(60, $line_height_start - $head_row_height, 540, $line_height_start - $head_row_height)->drawLine(540, $line_height_start, 540, $line_height_start - $head_row_height)->drawText('Total', 68, $line_height_start - $textline_height)->drawText($total_copies, 330 - $copies_num_pad, $line_height_start - $textline_height)->drawText($total_Ex_GST, 425 - $ex_gst_num_pad, $line_height_start - $textline_height)->drawText($total_Inc_GST, 515 - $inc_gst_num_pad, $line_height_start - $textline_height); // Table Headers $line_height_start = $line_height_start - $head_row_height; $footer_added = 1; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $style->setFont($font, 10); $page->setStyle($style); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOP/htdocs/images/logo.jpg'); $page->drawImage($image, 65, 40, 250, 80); $page->drawText('PO Box 140, Strawberry Hills NSW 2012', 68, 30); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOS/htdocs/images/logo.jpg'); $page->drawImage($image, 400, 40, 550, 80); } if ($i == $page_break_row) { if ($footer_added == 0) { $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOP/htdocs/images/logo.jpg'); $page->drawImage($image, 65, 40, 250, 80); $page->drawText('PO Box 140, Strawberry Hills NSW 2012', 68, 30); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOS/htdocs/images/logo.jpg'); $page->drawImage($image, 400, 40, 550, 80); $page_count++; $pdf->pages[$page_count] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $page = $pdf->pages[$page_count]; $style = new Zend_Pdf_Style(); $style->setLineColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $style->setFont($font, 10); $page->setStyle($style); $line_height_start = $page_height - 80; } $page_break_row = 30; $i = 1; } else { $i++; } $j++; } if ($footer_added == 0) { $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOP/htdocs/images/logo.jpg'); $page->drawImage($image, 65, 40, 250, 80); $page->drawText('PO Box 140, Strawberry Hills NSW 2012', 68, 30); $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../sites/MOS/htdocs/images/logo.jpg'); $page->drawImage($image, 400, 40, 550, 80); } if ($total_data_row > 0) { $pdf->save(APPLICATION_PATH . '/../tmp/remittance_invoice/' . $invoice_number . '.pdf'); } else { return false; } }
/** * Draws the cell to the PDF page. * * This function will parse the internal $_text field and draw the cell to the PDF page. */ public function write() { if (!$this->_page instanceof Zend_Pdf_Page) { throw new Zend_Pdf_Exception("The PDF page that the cell is attempting to write to is not a valid page."); } if (!$this->_font instanceof Zend_Pdf_Resource_Font) { throw new Zend_Pdf_Exception('No font has been set'); } if ($this->isAutoHeight()) { $this->_height = $this->_autoHeight; } if ($this->isAutoWidth()) { $this->_width = $this->_autoWidth; } //positions of the cell's box //initalize the diminsions to defaults $top = $this->_y; $left = $this->_x; $right = $left + $this->getWidth(); $bottom = $top + $this->getHeight(); if ($this->_position & Zend_Pdf_Cell::POSITION_BOTTOM) { $top = $this->getHeight(); $bottom = $top + $this->getHeight(); } if ($this->_position & Zend_Pdf_Cell::POSITION_CENTER_X) { $left = $this->_page->getWidth() / 2 - $this->getWidth() / 2 + $this->_x; $right = $left + $this->getWidth(); } if ($this->_position & Zend_Pdf_Cell::POSITION_CENTER_Y) { $top = $this->_page->getHeight() / 2 + $this->getHeight() / 2 - $this->_y; $bottom = $top - $this->getHeight(); } if ($this->_position & Zend_Pdf_Cell::POSITION_TOP) { $top = $this->_page->getHeight(); $bottom = $top + $this->getHeight(); } if ($this->_position & Zend_Pdf_Cell::POSITION_RIGHT) { $left = $this->_page->getWidth() - $this->getWidth(); $right = $left + $this->getWidth(); } $currentY = $top; //save the page's font so we can put it back after writing the cell $pageFont = $this->_page->getFont(); $fontSize = $this->_page->getFontSize(); //restore old size and font $this->_page->setFont($pageFont, $fontSize); //draw the border if ($this->_border['size'] > 0) { $style = new Zend_Pdf_Style(); $style->setLineColor($this->getBorderColor()); $style->setFillColor(new Zend_Pdf_Color_RGB(255, 255, 255)); $style->setLineDashingPattern($this->getBorderPattern()); $this->_page->setStyle($style); $this->_page->drawRectangle($right, $top, $left, $bottom); $style->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0)); $this->_page->setStyle($style); } //draw every section of every page. for ($i = 0; $i < count($this->_text); $i++) { $currentX = 0; switch ($this->_text[$i]['alignment']) { case Zend_Pdf_Cell::ALIGN_RIGHT: $currentX = $right - $this->_text[$i]['width']; break; case Zend_Pdf_Cell::ALIGN_CENTER: $currentX = ($right - $left) / 2 + $left - $this->_text[$i]['width'] / 2; break; case Zend_Pdf_Cell::ALIGN_JUSTIFY: //@todo break; default: $currentX = $left; break; } //add the offset $currentX += $this->_text[$i]['x']; $currentY -= $this->_text[$i]['height']; //count() - 4 because of the 4 properties to this text. for ($j = 0; $j < count($this->_text[$i]) - 4; $j++) { $this->_page->setFont($this->_text[$i][$j]['font'], $this->_text[$i][$j]['fontSize']); $this->_page->drawText($this->_text[$i][$j]['text'], $currentX, $currentY, $this->_text[$i][$j]['encoding']); $currentX += $this->_text[$i][$j]['width']; } } }
// save } } else { foreach ($pdf->pages as $num => $obj) { $obj->setStyle($bulletin_style); $obj->drawRectangle(30, 32, 150, 20); $obj->setFillColor($black); $obj->drawText($stamp, 32, 24); // stamp $pdf->pages[$num] = $obj; // save } } // 5a. note on the time exception if ($display_name == "A-Note-on-the-Time") { $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithPath($note_font_path), $note_font_size); $style->setFillColor($white); $boxes = array(); $stampText = date('Y M d g:i A', $now); $date1 = "2011-02-18 3:34"; // the time of writing $date2 = date('Y-M-d g:i', $now); $daylightSaving = date('I'); $diff = abs(strtotime($date2) - strtotime($date1)); $days = floor($diff / (60 * 60 * 24)); $hours = floor(($diff - $days * 60 * 60 * 24) / (60 * 60)); $minutes = floor(($diff - $days * 60 * 60 * 24 - $hours * 60 * 60) / 60); $hours = $hours + $daylightSaving; $stampTextD = $days . " days, " . $hours . " hours, " . $minutes . " minutes."; // 2d array -- page, x, y, w, h, text
/** * method to stamp each pdf page (add a banner with timestamp user real name and confidentiality level) * @param void * @return void */ public function stamp($values) { // Prepare stamp if ($values != null) { $first = true; foreach ($values as $value) { if ($first) { $sep = ''; $first = false; } else { $sep = ', '; } $valueTxt = $sep . $value->getName(); } } else { $valueTxt = ''; } $text = "Downloaded on " . date("d M Y H:i", $_SERVER['REQUEST_TIME']) . " by " . $this->user->getRealName() . " " . $valueTxt; $stamp = $text . " // " . $text; // Text and box style $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); $style->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); $style->setLineColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); //get pdf watermarking level based on number of pages in pdf document. $watermarkingLevel = $this->getWatermarkingLevelFromPdfSize(); // Stamp with adequate watermarking level switch ($watermarkingLevel) { case self::WATERMARK_EVERYPAGE: // Apply it on all pages foreach ($this->pdf->pages as $page) { $this->stampOnePage($page, $style, $stamp); } break; case self::WATERMARK_EVERY_TWO_PAGES: $count = 0; foreach ($this->pdf->pages as $page) { if ($count % 2 == 0) { $this->stampOnePage($page, $style, $stamp); } $count++; } break; case self::WATERMARK_THIRTY_PERCENT_OF_PAGES: $pagesToWatermark = $this->getPagesToWatermark(0.3, count($this->pdf->pages)); foreach ($pagesToWatermark as $pageNo) { $this->stampOnePage($this->pdf->pages[$pageNo], $style, $stamp); } break; case self::WATERMARK_TEN_PERCENT_OF_PAGES: default: $pagesToWatermark = $this->getPagesToWatermark(0.1, count($this->pdf->pages)); foreach ($pagesToWatermark as $pageNo) { $this->stampOnePage($this->pdf->pages[$pageNo], $style, $stamp); } break; } }
/** * Insert a claim details into a PDF. * * @param int $claimRefNo * * @return void */ public function populateAndOuputClaimStatusReport($claimRefNo, $agentSchemeNumber) { $claimDataSource = new Datasource_Insurance_KeyHouse_Claim(); $claimData = $claimDataSource->getClaim($claimRefNo, $agentSchemeNumber); $pdf = new Zend_Pdf_WrapText(); // create A4 page $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); // Add HomeLet logo $xcoord = 15; $ycoord = 780; $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../public/assets/common/images/logo-mid.png'); $page->drawImage($image, $xcoord, $ycoord, $xcoord + $image->getPixelWidth(), $ycoord + $image->getPixelHeight()); // define a style $claimHeaderFont = new Zend_Pdf_Style(); $claimHeaderFont->setFillColor(Zend_Pdf_Color_Html::color('#FF6F1C')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $claimHeaderFont->setFont($font, 14); // define another style $claimContentTitleFont = new Zend_Pdf_Style(); $claimContentTitleFont->setFillColor(Zend_Pdf_Color_Html::color('#0C2F6B')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); $claimContentTitleFont->setFont($font, 10); // define another style $claimContentFont = new Zend_Pdf_Style(); $claimContentFont->setFillColor(Zend_Pdf_Color_Html::color('#0C2F6B')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $claimContentFont->setFont($font, 10); // write title text to page $page->setStyle($claimHeaderFont)->drawText('Claim Status Report', 250, 810); // write content text to page $page->setStyle($claimContentTitleFont)->drawText('Claim Number', 15, 700); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimNo'], 200, 700); $page->setStyle($claimContentTitleFont)->drawText('Claim Handler', 15, 680); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimsHandler'], 200, 680); $page->setStyle($claimContentTitleFont)->drawText('Reference Number', 15, 660); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimNo'], 200, 660); $page->setStyle($claimContentTitleFont)->drawText('Start Date', 15, 640); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimDate'], 200, 640); $page->setStyle($claimContentTitleFont)->drawText('Date', 35, 590); $page->setStyle($claimContentTitleFont)->drawText('Action', 235, 590); $page->setStyle($claimContentTitleFont)->drawText('Status', 435, 590); // wrap text to avoid overlapping $zendWrapText = new Zend_Pdf_WrapText(); $sectionHeight = 0; $y = 570; for ($i = 0; $i < count($claimData); $i++) { $page->setStyle($claimContentFont)->drawText($claimData[$i]['ClaimDate'], 35, $y); $sectionHeight = $zendWrapText->drawWrappedText($page, 235, $y, $claimData[$i]['Activity'], 150, $claimContentFont); //$page->setStyle($claimContentFont)->drawTextBlock($claimData[$i]['Activitiy'], 235, 570, 200, 200, Zend_Pdf_Page::ALIGN_LEFT); $page->setStyle($claimContentFont)->drawText($claimData[$i]['OpenOrClosed'], 435, $y); $y -= $sectionHeight; } // add page to document $pdf->pages[] = $page; $filename = "claimstatus_" . md5($claimRefNo); // send to browser as download return $pdf->render(); }
// $page1->setStyle($style) // ->drawText($kh, 50,500 + $page, $charEncoding = 'UTF-8'); // $page = $page + 20; // } $page1->setStyle($style)->drawText('DAI HOC BACH KHOA TP.HO CHI MINH', 180, 800, $charEncoding = 'UTF-8'); // define image resource $image = Zend_Pdf_Image::imageWithPath('./public/image/logo1.png'); // write image to page $page1->drawImage($image, 240, 668, 360, 790); $diaChi = "Dia Chi: 268 Lý Thường Kiệt, Phường 9, Quận 10, TP. Hồ Chí Minh"; $sdt = "SDT: 08 3568256"; $page1->setStyle($style)->drawText($diaChi, 50, 650, $charEncoding = 'UTF-8'); $page1->setStyle($style)->drawText($sdt, 50, 630, $charEncoding = 'UTF-8'); $title = "THONG TIN DON XUAT"; // Create new Style $styleTitle = new Zend_Pdf_Style(); $styleTitle->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $styleTitle->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $styleTitle->setLineWidth(3); $styleTitle->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $fontTitle = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER); $styleTitle->setFont($fontTitle, 30); $page1->setStyle($styleTitle)->drawText($title, 130, 600, $charEncoding = 'UTF-8'); // add footer text $page1->drawLine(80, 25, $page2->getWidth() - 10, 25); $page1->drawImage($image, 20, 10, $image->getPixelWidth(), $image->getPixelHeight()); $page1->setStyle($style)->drawText('Copyright @HCMUT. All rights reserved.', 200, 10); $page1->drawLine(40, 580, $page2->getWidth() - 10, 580); // 25 --> 580 // Thông tin khach hang, Get thông tin theo mã khách hàng. Đơn xuất->Mã Đơn Hàng-> Mã Khách hàng $postMaKH = 1234;
public function getPdf($orders = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice'); if ($this->pdf == null) { $this->pdf = new Zend_Pdf(); } else { $this->firstPageIndex = count($this->pdf->pages); } $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); foreach ($orders as $order) { //cree la nouvelle page $titre = mage::helper('purchase')->__('Purchase Order'); $settings = array(); $settings['title'] = $titre; $settings['store_id'] = 0; $page = $this->NewPage($settings); //cartouche //$txt_date = "Date : ".mage::helper('core')->formatDate($order->getCreatedAt(), 'long'); $txt_date = "Date : " . date('d/m/Y', strtotime($order->getpo_date())); $txt_order = "PO# : " . $order->getpo_order_id(); $adresse_fournisseur = $order->getSupplier()->getAddressAsText(); if ($order->getShipTo() != '') { $adresse_client = $order->getShipTo(); } else { $adresse_client = Mage::getStoreConfig('sales/identity/address'); } $this->AddAddressesBlock($page, $adresse_fournisseur, $adresse_client, $txt_date, $txt_order); //affiche l'entete du tableau $this->drawTableHeader($page); $this->y -= 10; //Affiche les lignes produit foreach ($order->getProducts() as $item) { $productId = Mage::getModel('catalog/product')->getIdBySku($item->getSku()); $product = Mage::getModel('catalog/product')->load($productId); //Pour les produits "standards" $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); //this is our real SKU $caption = $this->WrapTextToWidth($page, $item->getSku(), 55); $offset = $this->DrawMultilineText($page, $caption, 15, $this->y, 10, 0.2, 11); //display SKU or picture if ($this->_showPictures == false) { $caption = $this->WrapTextToWidth($page, $item->getpop_supplier_ref(), 80); $offset = $this->DrawMultilineText($page, $caption, 80, $this->y, 10, 0.2, 11); } else { $product = mage::getModel('catalog/product')->load($item->getpop_product_id()); if ($product->getId()) { $productImagePath = Mage::getBaseDir() . '/media/catalog/product' . $product->getsmall_image(); if (is_file($productImagePath)) { try { $image = Zend_Pdf_Image::imageWithPath($productImagePath); $page->drawImage($image, 10, $this->y - $this->_pictureSize + 20, 5 + $this->_pictureSize, $this->y + 10); } catch (Exception $ex) { } } } } $caption = $this->WrapTextToWidth($page, $item->getpop_product_name(), 135); $offset = $this->DrawMultilineText($page, $caption, 160, $this->y, 10, 0.2, 11); //if ($order->getpo_status() != MDN_Purchase_Model_Order::STATUS_INQUIRY ) $this->drawTextInBlock($page, $product->getData('hts'), 300, $this->y, 60, 20, 'r'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($item->getpop_price_ht()), 415, $this->y, 60, 20, 'r'); $this->drawTextInBlock($page, (int) $item->getpop_qty(), 380, $this->y, 40, 20, 'c'); //if ($order->getpo_status() != MDN_Purchase_Model_Order::STATUS_INQUIRY ) //{ //$this->drawTextInBlock($page, $order->getCurrency()->formatTxt($item->getpop_eco_tax()), 365, $this->y, 40, 20, 'c'); //$this->drawTextInBlock($page, number_format($item->getpop_tax_rate(), 2).'%', 410, $this->y, 40, 20, 'c'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($item->getRowTotal()), 495, $this->y, 60, 20, 'r'); //$this->drawTextInBlock($page, $order->getCurrency()->formatTxt($item->getRowTotalWithTaxes($order->getpo_tax_rate())), 520, $this->y, 60, 20, 'r'); //} getProduct()->getsku() if ($this->_showPictures) { $this->y -= $this->_pictureSize; } else { $this->y -= $this->_ITEM_HEIGHT; } //si on a plus la place de rajouter le footer, on change de page if ($this->y < $this->_BLOC_FOOTER_HAUTEUR + 40) { $this->drawFooter($page); $page = $this->NewPage($settings); $this->drawTableHeader($page); } if ($product->getData('upc') != '') { $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE), 8); $this->drawTextInBlock($page, 'UPC: ' . $product->getData('upc'), 15, $this->y + 10, 60, 20, 'l'); $this->y -= 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); } } //rajoute les frais d'expédition if ($order->getpo_status() != MDN_Purchase_Model_Order::STATUS_INQUIRY) { $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); $this->DrawMultilineText($page, mage::helper('purchase')->__('Shipping costs'), 90, $this->y, 10, 0.2, 11); //$this->drawTextInBlock($page, number_format($order->getpo_tax_rate(), 2).'%', 410, $this->y, 40, 20, 'c'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getShippingAmountHt()), 450, $this->y, 60, 20, 'r'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getShippingAmountTtc()), 520, $this->y, 60, 20, 'r'); //rajoute les droits de douane //$this->y -= $this->_ITEM_HEIGHT; //$style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); //$this->DrawMultilineText($page, mage::helper('purchase')->__('Zoll costs'), 90, $this->y, 10, 0.2, 11); //$this->drawTextInBlock($page, number_format($order->getpo_tax_rate(), 2).'%', 410, $this->y, 40, 20, 'c'); //$this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getZollAmountHt()), 450, $this->y, 60, 20, 'r'); //$this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getZollAmountTtc()), 520, $this->y, 60, 20, 'r'); } //si on a plus la place de rajouter le footer, on change de page if ($this->y < 150) { $this->drawFooter($page); $page = $this->NewPage($settings); $this->drawTableHeader($page); } //barre grise début totaux $this->y -= 10; $page->drawLine(10, $this->y, $this->_BLOC_ENTETE_LARGEUR, $this->y); //barre verticale de séparation des totaux $VerticalLineHeight = 80; $page->drawLine($this->_PAGE_WIDTH / 2, $this->y, $this->_PAGE_WIDTH / 2, $this->y - $VerticalLineHeight); //rajoute les libellés & les totaux $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 14); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $this->y -= 20; //Zone commentaires $comments = Mage::getStoreConfig('purchase/general/pdf_comment'); if ($comments != '' && $comments != null) { $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.3)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 12); $page->drawText(mage::helper('purchase')->__('Bill To:'), 15, $this->y, 'UTF-8'); //$offset = $this->DrawMultilineText($page, $com, 15, $this->y - 15, 10, 0.3, 11); //$this->drawTextInBlock($page, $com, 15, $this->y - 15, 200, 200, 'l'); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.3)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 12); $comments = $this->WrapTextToWidth($page, $comments, $this->_PAGE_WIDTH / 2); $this->DrawMultilineText($page, $comments, 15, $this->y - 15, 10, 0.2, 11); } //if ($order->getpo_status() != MDN_Purchase_Model_Order::STATUS_INQUIRY ) //{ $page->drawText(mage::helper('purchase')->__('Sub Total.'), $this->_PAGE_WIDTH / 2 + 10, $this->y, 'UTF-8'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getTotalWithOutDuty()), $this->_PAGE_WIDTH / 2, $this->y, $this->_PAGE_WIDTH / 2 - 30, 40, 'r'); $this->y -= 20; $page->drawText('Estimated Duty.', $this->_PAGE_WIDTH / 2 + 10, $this->y, 'UTF-8'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getTaxAmount()), $this->_PAGE_WIDTH / 2, $this->y, $this->_PAGE_WIDTH / 2 - 30, 40, 'r'); $this->y -= 20; $page->drawText('Grand Total.', $this->_PAGE_WIDTH / 2 + 10, $this->y, 'UTF-8'); $this->drawTextInBlock($page, $order->getCurrency()->formatTxt($order->getTotalTtc()), $this->_PAGE_WIDTH / 2, $this->y, $this->_PAGE_WIDTH / 2 - 30, 40, 'r'); //} //barre grise fin totaux $this->y -= 20; $page->drawLine(10, $this->y, $this->_BLOC_ENTETE_LARGEUR, $this->y); //Rajoute le réglement et le transporteur $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); $this->y -= 20; $page->drawText(mage::helper('purchase')->__('Billing Method : ') . $order->getpo_payment_type(), 15, $this->y, 'UTF-8'); $this->y -= 20; $page->drawText(mage::helper('purchase')->__('Carrier : ') . $order->getpo_carrier(), 15, $this->y, 'UTF-8'); $this->y -= 20; $page->drawText('Shipping Method: ' . $order->getShipSpeed(), 15, $this->y, 'UTF-8'); //ligne de séparation $this->y -= 20; $page->drawLine(10, $this->y, $this->_BLOC_ENTETE_LARGEUR, $this->y); //Zone acceptation de la commande $this->y -= 20; $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 12); $page->drawText(mage::helper('purchase')->__('Comments : '), 15, $this->y, 'UTF-8'); $this->y -= 20; $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); $txt = $order->getpo_comments(); $txt = $this->WrapTextToWidth($page, $txt, $this->_PAGE_WIDTH - 100); $this->DrawMultilineText($page, $txt, 15, $this->y, 10, 0.2, 11); //dessine le pied de page $this->drawFooter($page); } //rajoute la pagination $this->AddPagination($this->pdf); $this->_afterGetPdf(); return $this->pdf; }
public function getPdf($invoices = array()) { $pdf = new Zend_Pdf(); $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); foreach ($invoices as $invoice) { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $order = $invoice->getOrder(); /* Add image */ $this->insertLogo($page); /* Add address */ $this->insertAddress($page); /* Add head */ $this->insertOrder($page, $order); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780); /* Add table */ $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; /* Add table head */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('QTY'), 35, $this->y); $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y); $page->drawText(Mage::helper('sales')->__('SKU'), 380, $this->y); $page->drawText(Mage::helper('sales')->__('Total(inc)'), 530, $this->y); $this->y -= 15; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); /* Add body */ foreach ($invoice->getAllItems() as $item) { $shift = 10; if ($this->y < 15) { /* Add new table head */ $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $this->y = 800; $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $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)); $page->drawText(Mage::helper('sales')->__('QTY'), 35, $this->y); $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y); $page->drawText(Mage::helper('sales')->__('SKU'), 380, $this->y); $page->drawText(Mage::helper('sales')->__('Price'), 530, $this->y); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->y -= 20; } /* Add products */ $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $page->drawText($item->getQty() * 1, 35, $this->y); $page->drawText($item->getName(), 60, $this->y); foreach (explode('</li>', $item->getDescription()) as $description) { $page->drawText(strip_tags($description), 65, $this->y - $shift); $shift += 10; } $page->drawText($item->getSku(), 380, $this->y); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); $row_total = $order->formatPriceTxt($item->getRowTotal() + $item->getTaxAmount() - $item->getDiscountAmount()); $page->drawText($row_total, 565 - $this->widthForStringUsingFontSize($row_total, $font, 7), $this->y); $this->y -= $shift; } /* Add totals */ $this->insertTotals($page, $invoice); } return $pdf; }
public function deploy() { $this->checkExportRights(); $this->setRecordsPerPage(0); parent::deploy(); $width = 0; $colors = array('title' => '#000000', 'subtitle' => '#111111', 'footer' => '#111111', 'header' => '#AAAAAA', 'row1' => '#EEEEEE', 'row2' => '#FFFFFF', 'sqlexp' => '#BBBBBB', 'lines' => '#111111', 'hrow' => '#E4E4F6', 'text' => '#000000', 'filters' => '#F9EDD2', 'filtersBox' => '#DEDEDE'); $this->_deploy['colors'] = array_merge($colors, (array) $this->_deploy['colors']); $la = ''; if (!isset($this->_deploy['save'])) { $this->_deploy['save'] = false; } if (!isset($this->_deploy['download'])) { $this->_deploy['download'] = false; } if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) { throw new Exception('Nothing to do. Please specify download&&|save options'); } if (empty($this->_deploy['name'])) { $this->_deploy['name'] = date('H_m_d_H_i_s'); } if (substr($this->_deploy['name'], -4) == '.xls') { $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4); } if (!isset($this->_deploy['noPagination'])) { $this->_deploy['noPagination'] = 0; } $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/'; if (!isset($this->_deploy['dir']) || !is_dir($this->_deploy['dir'])) { throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir'); } if (!is_writable($this->_deploy['dir'])) { throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable'); } $larg = self::calculateCellSize(); $lengthTotal = array_sum($larg); $cellFontSize = 8; //set font $titulos = parent::_buildTitles(); $sql = parent::_buildSqlExp(); $grid = parent::_BuildGrid(); if (!$this->getInfo('hRow,field')) { $this->_info['hRow']['field'] = ''; } if (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'A4') { $totalPaginas = ceil(count($grid) / 26); } elseif (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'LETTER') { $totalPaginas = ceil(count($grid) / 27); } else { $totalPaginas = ceil(count($grid) / 37); } if ($totalPaginas < 1) { $totalPaginas = 1; } $pdf = new Zend_Pdf(); // Create new Style $style = new Zend_Pdf_Style(); $style->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['lines'])); $topo = new Zend_Pdf_Style(); $topo->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['header'])); $td = new Zend_Pdf_Style(); $td->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row2'])); $styleFilters = new Zend_Pdf_Style(); $styleFilters->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filters'])); $styleFiltersBox = new Zend_Pdf_Style(); $styleFiltersBox->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filtersBox'])); $td2 = new Zend_Pdf_Style(); $td2->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row1'])); $hRowStyle = new Zend_Pdf_Style(); $hRowStyle->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['hrow'])); $styleSql = new Zend_Pdf_Style(); $styleSql->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['sqlexp'])); $styleText = new Zend_Pdf_Style(); $styleText->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['text'])); // Add new page to the document if (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); } elseif (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) != 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER); } elseif (strtoupper($this->_deploy['size'] != 'A4') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); } else { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); } $page->setStyle($style); $pdf->pages[] = $page; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $page->setFont($font, 14); //$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); if (file_exists($this->_deploy['logo'])) { $image = Zend_Pdf_Image::imageWithPath($this->_deploy['logo']); list($width, $height, $type, $attr) = getimagesize($this->_deploy['logo']); $page->drawImage($image, 40, $page->getHeight() - $height - 40, 40 + $width, $page->getHeight() - 40); } $page->drawText($this->__($this->_deploy['title']), $width + 70, $page->getHeight() - 70, $this->getCharEncoding()); $page->setFont($font, $cellFontSize); $page->drawText($this->__($this->_deploy['subtitle']), $width + 70, $page->getHeight() - 80, $this->getCharEncoding()); //Iniciar a contagem de páginas $pagina = 1; $page->drawText($this->_deploy['footer'], 40, 40, $this->getCharEncoding()); if (@$this->_deploy['noPagination'] != 1) { $page->drawText($this->__($this->_deploy['page']) . ' ' . $pagina . '/' . $totalPaginas, $page->getWidth() - strlen($this->__($this->_deploy['page'])) * $cellFontSize - 50, 40, $this->getCharEncoding()); } $page->setFont($font, $cellFontSize); $pl = $page->getWidth() - 80; $i = 0; foreach ($larg as $final) { $cell[$i] = round($final * $pl / $lengthTotal); $i++; } $cellsCount = count($titulos); if ($this->getInfo('hRow,title') != '') { $cellsCount--; } $largura = ($page->getWidth() - 80) / $cellsCount; $altura = $page->getHeight() - 120; $i = 0; $page->setFont($font, $cellFontSize + 1); foreach ($titulos as $value) { if ($value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') { if ((int) $la == 0) { $largura1 = 40; } else { $largura1 = $cell[$i - 1] + $largura1; } $page->setStyle($topo); $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12); $page->setStyle($styleText); $page->drawText($value['value'], $largura1 + 2, $altura, $this->getCharEncoding()); $la = $largura1; $i++; } } $page->setFont($font, $cellFontSize); $page->setStyle($style); if (is_array($grid)) { if ($this->getInfo('hRow,title') != '') { $bar = $grid; $hbar = trim($this->getInfo('hRow,field')); $p = 0; foreach ($grid[0] as $value) { if ($value['field'] == $hbar) { $hRowIndex = $p; } $p++; } $aa = 0; } $ia = 0; $aa = 0; foreach ($grid as $value) { if ($altura <= 80) { // Add new page to the document if (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); } elseif (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) != 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER); } elseif (strtoupper($this->_deploy['size'] != 'A4') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); } else { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); } $page->setStyle($style); $pdf->pages[] = $page; $pagina++; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $page->setFont($font, 14); //$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); if (file_exists($this->_deploy['logo'])) { $image = Zend_Pdf_Image::imageWithPath($this->_deploy['logo']); list($width, $height, $type, $attr) = getimagesize($this->_deploy['logo']); $page->drawImage($image, 40, $page->getHeight() - $height - 40, 40 + $width, $page->getHeight() - 40); } $page->drawText($this->__($this->_deploy['title']), $width + 70, $page->getHeight() - 70, $this->getCharEncoding()); $page->setFont($font, $cellFontSize); $page->drawText($this->__($this->_deploy['subtitle']), $width + 70, $page->getHeight() - 80, $this->getCharEncoding()); //set font $altura = $page->getHeight() - 120; $page->drawText($this->__($this->_deploy['footer']), 40, 40, $this->getCharEncoding()); if ($this->_deploy['noPagination'] != 1) { $page->drawText($this->__($this->_deploy['page']) . ' ' . $pagina . '/' . $totalPaginas, $page->getWidth() - strlen($this->__($this->_deploy['page'])) * $cellFontSize - 50, 40, $this->getCharEncoding()); } // reset($titulos); $i = 0; $largura1 = 40; $page->setFont($font, $cellFontSize + 1); foreach ($titulos as $title) { if ($title['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') { if ((int) $la == 0) { $largura1 = 40; } else { $largura1 = $cell[$i - 1] + $largura1; } $page->setStyle($topo); $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12); $page->setStyle($style); $page->drawText($title['value'], $largura1 + 2, $altura, $this->getCharEncoding()); $la = $largura1; $i++; } } $page->setFont($font, $cellFontSize); } $la = 0; $altura = $altura - 16; $i = 0; $tdf = $ia % 2 ? $td : $td2; $a = 1; //A linha horizontal if ($this->getInfo('hRow,title') != '') { if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) { $centrar = $page->getWidth() - 80; $centrar = round($centrar / 2) + 30; if ((int) $la == 0) { $largura1 = 40; } else { $largura1 = $cell[$i - 1] + $largura1; } $page->setStyle($hRowStyle); $page->drawRectangle($largura1, $altura - 4, $page->getWidth() - 40, $altura + 12); $page->setStyle($styleText); $page->drawText($bar[$aa][$hRowIndex]['value'], $centrar, $altura, $this->getCharEncoding()); $la = 0; $altura = $altura - 16; } } //////////// //Vamos saber qauntas linhas tem este registo $nlines = array(); $nl = 0; foreach ($value as $lines) { $line = $this->widthForStringUsingFontSize(strip_tags(trim($lines['value'])), $font, 8); $nlines[] = ceil($line / $cell[$nl]); $nl++; } sort($nlines); $totalLines = end($nlines); $nl = 0; foreach ($value as $value1) { $value1['value'] = strip_tags(trim($value1['value'])); if ($value1['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') { if ((int) $la == 0) { $largura1 = 40; } else { $largura1 = $cell[$i - 1] + $largura1; } $page->setStyle($tdf); $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12); $page->setStyle($styleText); $page->drawText($value1['value'], $largura1 + 2, $altura, $this->getCharEncoding()); $la = $largura1; $i++; $nl++; } $a++; } $aa++; $ia++; } } $la = 0; $altura = $altura - 16; $i = 0; if (is_array($sql)) { foreach ($sql as $value) { if ((int) $la == 0) { $largura1 = 40; } else { $largura1 = $cell[$i - 1] + $largura1; } $page->setStyle($styleSql); $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i], $altura + 12); $page->setStyle($styleText); $page->drawText($value['value'], $largura1 + 2, $altura, $this->getCharEncoding()); $la = $largura1; $la = $largura1; $i++; } } $la = 0; $altura = $altura - 16; $i = 0; if (is_array($this->_showFiltersInExport) || $this->_showFiltersInExport == true) { if (is_array($this->_showFiltersInExport) && is_array($this->_filtersValues)) { $this->_showFiltersInExport = array_merge($this->_showFiltersInExport, $this->_filtersValues); } elseif (is_array($this->_showFiltersInExport)) { $this->_showFiltersInExport = $this->_showFiltersInExport; } elseif (is_array($this->_filtersValues)) { $this->_showFiltersInExport = $this->_filtersValues; } if (count($this->_showFiltersInExport) > 0) { $page->setStyle($styleFilters); $page->drawRectangle(40, $altura - 4, array_sum($cell) + 41, $altura + 12); $page->setStyle($styleText); $tLarg = $this->widthForStringUsingFontSize($this->__('Filtered by:'), $font); $i = 0; $page->setStyle($styleFiltersBox); $page->drawRectangle(40, $altura - 4, $tLarg + 50, $altura + 12); $page->setStyle($styleText); $text = ' ' . $this->__('Filtered by:') . ' '; foreach ($this->_showFiltersInExport as $key => $value) { if ($keyHelper = $this->getField($key)) { $key = $keyHelper['title']; } if (is_array($value)) { foreach ($value as $newName => $newValue) { $text .= $this->__($key) . ' - ' . $this->__(ucfirst($newName)) . ': ' . $this->__($newValue) . ' | '; } } else { $text .= $this->__($key) . ': ' . $this->__($value) . ' | '; } $i++; } $page->drawText($text, $tLarg + 3, $altura, $this->getCharEncoding()); } } $pdf->save($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf'); if ($this->_deploy['download'] == 1) { header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.pdf"'); readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf'); } if ($this->_deploy['save'] != 1) { unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf'); } die; }
public function __construct($param1, $param2 = null, $param3 = null) { parent::__construct($param1, $param2, $param3); $style = new Zend_Pdf_Style(); $style->setLineColor(new Zend_Pdf_Color_Html("#000000")); $style->setFillColor(new Zend_Pdf_Color_Html("#000000")); $style->setLineWidth(0.5); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER); $style->setFont($font, 10); $style->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID); $this->_defaultStyle = $style; $this->setStyle($style); }
public function getPdf($order = array()) { $this->_beforeGetPdf(); $this->_initRenderer('invoice'); $this->pdf = new Zend_Pdf(); $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); //cree la nouvelle page $titre = mage::helper('purchase')->__('Order #') . $order->getincrement_id() . ' ' . mage::helper('purchase')->__('Comments'); $settings = array(); $settings['title'] = $titre; $settings['store_id'] = 0; $page = $this->NewPage($settings); //cartouche $txt_date = "Date : " . mage::helper('core')->formatDate($order->getCreatedAt(), 'long'); $txt_order = mage::helper('purchase')->__('Order #') . $order->getId(); //$adresse_fournisseur = Mage::getStoreConfig('sales/identity/address'); $customer = mage::getmodel('customer/customer')->load($order->getCustomerId()); $adresse_client = mage::helper('purchase')->__('Shipping Address') . ":\n" . $this->FormatAddress($order->getShippingAddress(), '', false, $customer->gettaxvat()); $adresse_fournisseur = mage::helper('purchase')->__('Billing Address') . ":\n" . $this->FormatAddress($order->getBillingAddress(), '', false, $customer->gettaxvat()); $this->AddAddressesBlock($page, $adresse_fournisseur, $adresse_client, $txt_date, $txt_order); //Rajoute le carrier et la date d'expe prévue & les commentaires $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); $this->y -= 15; $page->drawText(mage::helper('purchase')->__('Shipping') . ' : ' . $order->getShippingDescription(), 15, $this->y, 'UTF-8'); $this->y -= 15; $comments = $this->WrapTextToWidth($page, $order->getmdn_comments(), 550); $offset = $this->DrawMultilineText($page, $comments, 15, $this->y, 10, 0.2, 11); $this->y -= 10 + $offset; $page->drawLine(10, $this->y, $this->_BLOC_ENTETE_LARGEUR, $this->y); //affiche l'entete du tableau $this->drawTableHeader($page); $this->y -= 10; //Affiche le récap des produits $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.2)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); foreach ($order->getAllItems() as $item) { //recupere le produit $product = mage::getModel('catalog/product')->load($item->getproduct_id()); //dessine $page->drawText((int) $item->getqty_ordered(), 15, $this->y, 'UTF-8'); $page->drawText($product->getSku(), 70, $this->y, 'UTF-8'); $page->drawText($product->getName(), 200, $this->y, 'UTF-8'); $page->drawText($item->getreserved_qty(), 560, $this->y, 'UTF-8'); //rajoute les commentaires $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 8); $this->y -= $this->_ITEM_HEIGHT; $caption = $this->WrapTextToWidth($page, $item->getcomments(), 300); $offset = $this->DrawMultilineText($page, $caption, 200, $this->y, 10, 0.2, 11); $this->y -= $offset; //rajoute une ligne de séparation $page->setLineWidth(0.5); $page->drawLine(10, $this->y - 4, $this->_BLOC_ENTETE_LARGEUR, $this->y - 4); $this->y -= $this->_ITEM_HEIGHT; //si on a plus la place de rajouter le footer, on change de page if ($this->y < $this->_BLOC_FOOTER_HAUTEUR + 40) { $this->drawFooter($page); $page = $this->NewPage($settings); $this->drawTableHeader($page); } } //dessine le pied de page $this->drawFooter($page); //rajoute la pagination $this->AddPagination($this->pdf); $this->_afterGetPdf(); return $this->pdf; }
/** Zend_Pdf */ require_once 'Zend/Pdf.php'; if (!isset($argv[1])) { echo "USAGE: php demo.php <pdf_file> [<output_pdf_file>]\n"; exit; } if (file_exists($argv[1])) { $pdf = Zend_Pdf::load($argv[1]); } else { $pdf = new Zend_Pdf(); } //------------------------------------------------------------------------------------ // Reverse page order $pdf->pages = array_reverse($pdf->pages); // Create new Style $style = new Zend_Pdf_Style(); $style->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0.9)); $style->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $style->setLineWidth(3); $style->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $style->setFont(new Zend_Pdf_Font_Standard(Zend_Pdf_Const::FONT_HELVETICA_BOLD), 32); // Create new image object $stampImage = new Zend_Pdf_Image_JPEG(dirname(__FILE__) . '/stamp.jpg'); // Mark page as modified foreach ($pdf->pages as $page) { $page->saveGS(); $page->setStyle($style); $page->rotate(0, 0, M_PI_2 / 3); $page->saveGS(); $page->clipCircle(550, -10, 50); $page->drawImage($stampImage, 500, -60, 600, 40);
if (!isset($argv[2])) { // force complete file rewriting (instead of updating) $argv[2] = $argv[1]; } } else { // Throw an exception if it's not the "Can't open file" exception throw $e; } } //------------------------------------------------------------------------------------ // Reverse page order $pdf->pages = array_reverse($pdf->pages); // Create new Style $style = new Zend_Pdf_Style(); $style->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0.9)); $style->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $style->setLineWidth(3); $style->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32); try { // Create new image object require_once 'Zend/Pdf/Image.php'; $stampImage = Zend_Pdf_Image::imageWithPath(__DIR__ . '/stamp.jpg'); } catch (Zend_Pdf_Exception $e) { // Example of operating with image loading exceptions. if ($e->getMessage() != 'Image extension is not installed.' && $e->getMessage() != 'JPG support is not configured properly.') { throw $e;
protected function _getWrappedText($string, Zend_Pdf_Style $style, $max_width) { $wrappedText = ''; $lines = explode("\n", $string); foreach ($lines as $line) { $words = explode(' ', $line); $word_count = count($words); $i = 0; $wrappedLine = ''; while ($i < $word_count) { /* if adding a new word isn't wider than $max_width, we add the word */ if ($this->widthForStringUsingFontSize($wrappedLine . ' ' . $words[$i], $style->getFont(), $style->getFontSize()) < $max_width) { if (!empty($wrappedLine)) { $wrappedLine .= ' '; } $wrappedLine .= $words[$i]; } else { $wrappedText .= $wrappedLine . "\n"; $wrappedLine = $words[$i]; } $i++; } $wrappedText .= $wrappedLine . "\n"; } return $wrappedText; }
public function getPdf($shipments = array()) { $pdf = new Zend_Pdf(); $style = new Zend_Pdf_Style(); $style->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 10); foreach ($shipments as $shipment) { $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $order = $shipment->getOrder(); /* Add image */ $this->insertLogo($page); /* Add address */ $this->insertAddress($page); /* Add head */ $this->insertOrder($page, $order); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $page->drawText(Mage::helper('sales')->__('Packingslip # ') . $shipment->getIncrementId(), 35, 780); /* Add table */ $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); /* Add table head */ $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)); $page->drawText(Mage::helper('sales')->__('QTY'), 35, $this->y); $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y); $page->drawText(Mage::helper('sales')->__('SKU'), 470, $this->y); $this->y -= 15; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); /* Add body */ foreach ($shipment->getAllItems() as $item) { $shift = 10; if ($this->y < 15) { /* Add new table head */ $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $this->y = 800; $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $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)); $page->drawText(Mage::helper('sales')->__('QTY'), 35, $this->y); $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y); $page->drawText(Mage::helper('sales')->__('SKU'), 470, $this->y); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->y -= 20; } /* Add products */ $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); $page->drawText($item->getQty() * 1, 35, $this->y); $page->drawText($item->getName(), 60, $this->y); $page->drawText($item->getName(), 60, $this->y); foreach (explode('</li>', $item->getDescription()) as $description) { $page->drawText(strip_tags($description), 65, $this->y - $shift); $shift += 10; } $page->drawText($item->getSku(), 470, $this->y); $this->y -= $shift; } } return $pdf; }
public function byProduct($product, $for_catalog = false) { $category = $product->findManyToManyRowset("Model_DbTable_Categories", "Model_DbTable_CategoryXref")->current(); if ($category) { $this->category = $category->getBcnName(); } else { $this->category = "Неизвестно"; } $productParams = $product->getParams(); if (!$for_catalog) { $this->margins = array('top' => 35, 'right' => 20, 'bottom' => 35, 'left' => 20); } if (is_null($this->book)) { $page = $this->createBook(1, $for_catalog); } else { $page = $this->lastPage(); } $offset = $for_catalog == false ? 0 : $page->getHeight() - $page->getCurrentPosition() - 1; if (!$for_catalog) { $page->setMargins(35, 20, 35, 20); } $noteStyle = new Zend_Pdf_Style(); $noteStyle->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->format == 'A4' ? 6.5 : 4.5); $noteStyle->setLineWidth($page->getWidth() - 20); $style = new Zend_Pdf_Style(); $style->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->format == 'A4' ? 8.0 : 6.5); $style->setLineWidth($page->getWidth()); $paramsLinesCount = 0; foreach ($productParams as $param) { $paramsLinesCount += count(explode("\n", $param->value)); } $paramsLinesCount++; $subproductsModel = new Model_DbTable_Subproducts(); $select = $subproductsModel->select()->order('order ASC'); $subProducts = $product->findDependentRowset("Model_DbTable_Subproducts", 'SubproductsRel', $select); // расчет высоты всего продукта, проверка влезает ли он на страницу, если не влезает смотрим сколько именно не влезает и есть ли субпродукты, // которые мы може отрисовать на этой странице и перенести отстаток на другую страницу $productHeightWithoutTable = 10 + max(array(80, $this->format == 'A4' ? $paramsLinesCount * 12 : $paramsLinesCount * 8)) + ($product->description ? $page->getTextBlockHeight(trim($product->description), $style, 3) : 0); $productHeight = 20 + max(array(80, $this->format == 'A4' ? $paramsLinesCount * 12 : $paramsLinesCount * 8)) + ($product->description ? $page->getTextBlockHeight(trim($product->description), $style, 3) : 0) + (count($subProducts) <= 30 ? $this->format == 'A4' ? count($subProducts) * 12 + 10 : count($subProducts) * 8 + 12 + 15 : 0) + ($product->note ? $page->getTextBlockHeight($product->note, $noteStyle) + 10 : 0); // note*/ if ($offset) { if ($page->getHeight() - $offset - 10 < (count($subProducts) <= 30 ? $productHeight : intval($productHeight) + 40)) { if ($page->getPageNumber() > 1) { $page->drawCategory(isset($this->old_category) ? $this->old_category : $this->category); $this->old_category = NULL; $page = $this->addPage(); $offset = 0; } } else { if ($page->getCurrentPosition() < 700 && $for_catalog) { $offset -= 5; } $page->init($offset); $this->old_category = $this->category; } } else { $this->old_category = $this->category; } $this->product_page = $page->getPageNumber(); // DEBUG auto-height calculate if (isset($_REQUEST['DEBUG'])) { $page->drawHorizontalLine(-20, 575, $page->getHeight() - $offset, 1, new Zend_Pdf_Color_Html('green')); $page->drawHorizontalLine(-20, 575, $page->getHeight() - $offset - $productHeight, 2, new Zend_Pdf_Color_Html('red')); $page->drawTextBlock(count($subProducts), -20, $page->getHeight() - $offset - $productHeight); } // --- block / information $page->setFont(Model_Static_Fonts::get("Franklin Gothic Demi Cond"), 14); $page->drawTextBlock($product->sku, 5, $page->getHeight() - $offset); $page->setFont(Model_Static_Fonts::get("Franklin Gothic Demi Cond"), 10); $page->drawTextBlock($product->name, 5, $page->getHeight() - 10 - $offset); // --- block / images $images = array($product->image); if ($product->a_images) { $images[] = $product->a_images[0]; } $x = 0; if ($page->getPageNumber() % 2 == 0) { // если картинки справа (иконки слева) $images = array_reverse($images); // здесь нужно посчитать правильные ширины отступов начала изображений $x = $page->getWidth() - 5; foreach ($images as $image) { $sizes = $page->picSize($this->getProductImageFullpath($image), $this::IMAGE_SIZE, $this::IMAGE_SIZE, 2); //$x = $x - $this::IMAGE_SIZE * $sizes[0]; $x = $x - $this::IMAGE_SIZE; //echo $image." "; } $x = $x - 5 * (count($images) - 1); } else { // картинки слева - просто задаем базовый отступ по x $x += 5; } //echo $x." "; $count = 0; // count of images (x75) //в зависимости от задачи, выбираем папку с картинками, за это отвечает параметр $print foreach ($images as $image) { if ($this->print) { //$c = $page -> drawPic(APPLICATION_ROOT . '/files/images/product_tiff/' . substr($image, 0, strripos($image, ".")).'.tif', $x, $page -> getHeight() - 20 - $offset, $this::IMAGE_SIZE, $this::IMAGE_SIZE, isset($images[1]) ? 1 : 2,1); $c = $page->drawPic($this->getProductImageFullpath($image), $x, $page->getHeight() - 20 - $offset, $this::IMAGE_SIZE, $this::IMAGE_SIZE, 2, 1); } else { $c = $page->drawPic($this->getProductImageFullpath($image), $x, $page->getHeight() - 20 - $offset, $this::IMAGE_SIZE, $this::IMAGE_SIZE, isset($images[1]) ? 1 : 2, 1); } if ($page->getPageNumber() % 2 == 0) { // если картинки справа, то не считаем полную ширину $x += $this::IMAGE_SIZE + 5; } else { $x += $this::IMAGE_SIZE * $c + 5; } $count += $c; } // --- block / params $offsetX = $page->getPageNumber() % 2 ? $this::IMAGE_SIZE * $count + 15 : 10; $tableWidth = $page->getWidth() - $this::IMAGE_SIZE * $count - 25; if (count($productParams) > 0) { $params = array(); foreach ($productParams as $productParam) { $params[] = array($productParam->name, str_replace(array(' ' . chr('0x0D') . chr('0x0A'), chr('0x0D') . chr('0x0A')), ', ', $productParam->value)); } $page->drawTable($params, $offsetX, $page->getHeight() - 30 - $offset, $tableWidth); } // --- block / description if ($product->description) { $style = new Zend_Pdf_Style(); $style->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->format == 'A4' ? 8.0 : 6.5); $style->setLineWidth($page->getWidth()); if ($for_catalog) { $page->drawTextBlock(str_replace(array(' ', ' ', ' '), '. ', trim($product->description)), 5, $page->getCurrentPosition() + 25, $style, 3); //chr('0x0D').chr('0x0A') $page->setCurrentPosition($page->getCurrentPosition() + 10); } else { $page->drawTextBlock(str_replace(array(' ', ' ', ' '), chr('0x0D') . chr('0x0A'), trim($product->description)), 5, $page->getCurrentPosition() + 15, $style, 3); $page->setCurrentPosition($page->getCurrentPosition() + 15); } } // --- block / sub products $params = array(); $subproductParams = $product->getSubParams(); foreach ($subProducts as $subProduct) { $productParams = $subProduct->getParamsValues(); $row = array($subProduct->sku); foreach ($productParams as $productParam) { $row[] = $productParam->value; } $params[] = $row; } if (count($subProducts) > 0) { $header = array('Название'); foreach ($subproductParams as $subproductParam) { $header[] = $subproductParam->name; } } if ($product->note) { $noteHeight = $page->getTextBlockHeight($product->note, $noteStyle); } else { $noteHeight = 0; } // // $noteHeight = 0; $curRow = 0; if ($params) { $page->setCurrentPosition($page->getCurrentPosition() + 20); // move table-description while ($curRow !== NULL) { $curRow = $page->drawTable($params, 0, $page->getCurrentPosition(), $page->getWidth() - 5, $noteHeight, $header, $curRow, true, $product->note); if ($curRow !== NULL) { $page->drawCategory($this->category); } // else { // if ($product -> note && $for_catalog) { // $page -> drawTextBlock($product -> note, 5, $page -> getCurrentPosition() + 24, $noteStyle); // }elseif($product -> note){ // $page -> drawTextBlock($product -> note, 5, $page -> getCurrentPosition() + 62, $noteStyle); // } // } // $page -> drawTextBlock($curRow, -20, $page -> getHeight() - $offset - $productHeight); $page = $this->addPage(false); if ($curRow !== NULL) { $curRow++; } } } else { $this->AddPage(false); } return $this->book; }
private function drawGeneralLayout() { $recstyle = new Zend_Pdf_Style(); $recstyle->setLineWidth(0.5); $this->page->setStyle($recstyle); $this->page->drawRoundedRectangle($this->coordX(0), $this->coordY(0) - $this->mmToPts(150), $this->coordX(0) + $this->mmToPts(100), $this->coordY(0), $radius = array(15, 15, 15, 15), $fillType = Zend_Pdf_Page::SHAPE_DRAW_STROKE); //General GLS-Layout //x-achse | y-Achse | Länge | Dicke $ControlBar1 = array('x' => 1, 'y' => 2, 'length' => 98, 'thick' => 1, 'horizontal' => true); $ControlBar2 = array('x' => 1, 'y' => 15, 'length' => 98, 'thick' => 0.5, 'horizontal' => true); $ControlBar3 = array('x' => 1, 'y' => 27.5, 'length' => 98, 'thick' => 0.5, 'horizontal' => true); $ControlBar4 = array('x' => 1, 'y' => 56, 'length' => 98, 'thick' => 0.5, 'horizontal' => true); $Line1 = array('x' => 1, 'y' => 62.5, 'length' => 98, 'thick' => 0.25, 'horizontal' => true); $Line2 = array('x' => 1, 'y' => 90, 'length' => 81.5, 'thick' => 0.25, 'horizontal' => true); $Line3 = array('x' => 1, 'y' => 119, 'length' => 81.5, 'thick' => 0.25, 'horizontal' => true); $Line4 = array('x' => 1, 'y' => 134.5, 'length' => 98, 'thick' => 0.25, 'horizontal' => true); $Line5 = array('x' => 1, 'y' => 62.5, 'length' => 72, 'thick' => 0.25, 'horizontal' => false); $Line6 = array('x' => 82.5, 'y' => 62.5, 'length' => 72, 'thick' => 0.25, 'horizontal' => false); $Line7 = array('x' => 99, 'y' => 62.5, 'length' => 72, 'thick' => 0.25, 'horizontal' => false); $PrimaryCodeBorder1_1 = array('x' => 1, 'y' => 28.5, 'length' => 5, 'thick' => 1, 'horizontal' => true); $PrimaryCodeBorder1_2 = array('x' => 1.5, 'y' => 28.5, 'length' => 5, 'thick' => 1, 'horizontal' => false); $PrimaryCodeBorder2_1 = array('x' => 1, 'y' => 55, 'length' => 5, 'thick' => 1, 'horizontal' => true); $PrimaryCodeBorder2_2 = array('x' => 1.5, 'y' => 50, 'length' => 5, 'thick' => 1, 'horizontal' => false); $PrimaryCodeBorder3_1 = array('x' => 22.5, 'y' => 28.5, 'length' => 5, 'thick' => 1, 'horizontal' => true); $PrimaryCodeBorder3_2 = array('x' => 27, 'y' => 28.5, 'length' => 5, 'thick' => 1, 'horizontal' => false); $PrimaryCodeBorder4_1 = array('x' => 22.5, 'y' => 55, 'length' => 5, 'thick' => 1, 'horizontal' => true); $PrimaryCodeBorder4_2 = array('x' => 27, 'y' => 50, 'length' => 5, 'thick' => 1, 'horizontal' => false); $LayoutCollection = array($ControlBar1, $ControlBar2, $ControlBar3, $ControlBar4, $Line1, $Line2, $Line3, $Line4, $Line5, $Line6, $Line7, $PrimaryCodeBorder1_1, $PrimaryCodeBorder1_2, $PrimaryCodeBorder2_1, $PrimaryCodeBorder2_2, $PrimaryCodeBorder3_1, $PrimaryCodeBorder3_2, $PrimaryCodeBorder4_1, $PrimaryCodeBorder4_2); foreach ($LayoutCollection as $element) { // define a style $controlLayoutStyle = new Zend_Pdf_Style(); $controlLayoutStyle->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $controlLayoutStyle->setLineColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $controlLayoutStyle->setLineWidth($this->mmToPts($element['thick'])); $this->page->setStyle($controlLayoutStyle); if ($element['horizontal']) { $this->page->drawLine($this->coordX($this->mmToPts($element['x'])), $this->coordY($this->mmToPts($element['y'])), $this->coordX($this->mmToPts($element['x']) + $this->mmToPts($element['length'])), $this->coordY($this->mmToPts($element['y']))); } else { $this->page->drawLine($this->coordX($this->mmToPts($element['x'])), $this->coordY($this->mmToPts($element['y'])), $this->coordX($this->mmToPts($element['x'])), $this->coordY($this->mmToPts($element['y']) + $this->mmToPts($element['length']))); } } try { // Erstelle ein neues Grafikobjekt $imageFile = SERVER_BASE . '/images/Logo_GLS.jpg'; $stampImage = Zend_Pdf_Image::imageWithPath($imageFile); } catch (Zend_Pdf_Exception $e) { // Beispiel wie man mit Ladefehlern bei Grafiken umgeht. $stampImage = null; } if ($stampImage != null) { $this->page->drawImage($stampImage, $this->coordX(180), $this->coordY(0) - $this->mmToPts(149), $this->coordX($this->mmToPts(99)), $this->coordY($this->mmToPts(150)) + $this->mmToPts(14)); } $this->page->setStyle($this->defaultStyle); }
/** * Set the style to use for future drawing operations on this page * * @param Zend_Pdf_Style $style * @return Zend_Pdf_Page */ public function setStyle(Zend_Pdf_Style $style) { $this->_style = $style; $this->_addProcSet('Text'); $this->_addProcSet('PDF'); if ($style->getFont() !== null) { $this->setFont($style->getFont(), $style->getFontSize()); } $this->_contents .= $style->instructions($this->_pageDictionary->Resources); return $this; }
/** * Draw table or part of table by coordinates with or without header * * @param array[][] $table Table values * @param int $x x coordinate * @param int $y y coordinate * @param int $width Table width * @param int $max_y Minimal y coordinate * @param array[] $header Table header * @param int $start_row start row of table * * @return int End row * * @api */ function drawTable($table, $x, $y, $width, $max_y = 0, $header = NULL, $start_row = 0, $params = false, $note = '') { if (!$table) { return NULL; } if ($start_row > count($table) - 1) { if ($this->currentPosition > $y - $this->MARGIN['bottom']) { $this->currentPosition = $y - $this->MARGIN['bottom']; } return NULL; } $max_widths = $this->getTableColumnsMaxWidths($table, $params); $avg_widths = $this->getTableColumnsAverageWidths($table, $params); // parent::drawText(implode(',',$max_widths), $this -> MARGIN['left'], $this -> MARGIN['bottom'], 'UTF-8'); //вычисляем ширину столбцов, в зависимости от того, какую таблицу рисуем выбираем нужную формулу if ($params) { $awidth = array_sum($max_widths) - 0; } else { $awidth = array_sum($avg_widths) - $avg_widths[0] - 5; $widths = array($max_widths[0]); } // Подгоняем ширину под заданную, через процентные соотношения foreach ($avg_widths as $i => $a_w) { if ($params) { $widths[] = $a_w / $awidth * $width; } elseif ($i != 0) { $widths[] = $a_w / $awidth * ($width - $widths[0] - 10); } } // запомним наш $x и текущий $y $coords = array($x, $y); // write header ( if exists ) if ($header) { //создаем сностки для таблици с параметрами. В зависимости от количества столбцов и длинны названия параметра, заменяем его и записываем в сноски $snoski = ''; $s_number = 1; $widthSnoski = $width; $this->pageFormat == 'A4' ? $countChar = 30 : ($countChar = 10); foreach ($header as $i => $column) { if (count($header) > 7 && strlen($column) >= $countChar && $i != 0 || $column == 'Типоразмер') { if ($widthSnoski < $this->widthForStringUsingFontsize($s_number . '* - ' . $column . '; ', Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatSnoski) + $this->widthForStringUsingFontsize($snoski, Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatSnoski)) { $snoski .= chr('0x0D') . chr('0x0A'); $widthSnoski *= 2; } $snoski .= $s_number . '* - ' . $column . '; '; $header[$i] = $s_number . '*'; $s_number++; } elseif ($this->pageFormat == 'A5') { $header[$i] = str_replace('(', chr('0x0D') . chr('0x0A') . '(', $column); } } $snoski .= ' ' . $note; $this->saveGS(); $style = new Zend_Pdf_Style(); $style->setFillColor(new Zend_Pdf_Color_Html("white")); $style->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatHeader); // Bold $this->setStyle($style); // calculate height of header $height = 0; foreach ($header as $i => $column) { $style->setLineWidth($widths[$i]); $height = max($height, $this->getTextBlockHeight(trim($column), $style, 0, true)); } // if we can't write 2 line - exit if ($y - $height - $max_y < 16) { $this->restoreGS(); return 0; } // else - draw header background $this->drawHorizontalLine($coords[0] + 5, $coords[0] + $width, $this->pageFormat == 'A4' ? $y - $height / 2 + 5.5 : $y - $height / 2 + 3.5, $height, new Zend_Pdf_Color_Html("#0095da")); // here - write header // foreach ($header as $i => $col) { $style->setLineWidth($widths[$i]); $width_text = $this->widthForStringUsingFontsize($col, $style->getFont(), $style->getFontSize()); if ($widths[$i] > $width_text && $i != 0) { $iLeft = $x + ($widths[$i] - $width_text) / 2; } else { $iLeft = $x + 8; } $y = min($y, $this->drawTextBlock(str_replace(array(''), array(''), trim($col)), $iLeft + 1 * ($i == 0), $coords[1] - 3, $style, 0, true)); $x += $widths[$i]; } $this->restoreGS(); } // make offset(3) if ($this->pageFormat == 'A4') { $y -= 2; } elseif ($this->pageFormat == 'A5') { $y -= 0; } // write table data $coords[0] += 5; $width -= 5; for ($c_row = $start_row; $c_row < count($table); $c_row++) { $rowset = $table[$c_row]; $x = $coords[0]; $line_y = $y; // for table with headers odd lines have bg if ($c_row % 2 != 0 && $header) { $style = new Zend_Pdf_Style(); $style->setLineWidth($widths[$i] + 10); $style->setFont(Model_Static_Fonts::get("Arial Narrow" . ($i == 0 && !$header ? ' Bold' : '')), $this->fontSizeFormat); $height = 0; foreach ($rowset as $i => $col) { $style->setLineWidth($widths[$i]); $height = max($height, $this->getTextBlockHeight($col, $style)); } if ($this->pageFormat == 'A4') { $this->drawHorizontalLine($x, $x + $width, $y + (3 - intval(($height - 2) / 6 - 1.5) * 2), $height - 4, new Zend_Pdf_Color_Html("#e7e7e7")); } elseif ($this->pageFormat == 'A5') { $this->drawHorizontalLine($x, $x + $width, $y + (2 - intval(($height - 2) / 6 - 1) * 2), $height - 4, new Zend_Pdf_Color_Html("#e7e7e7")); } } foreach ($rowset as $i => $col) { $style = new Zend_Pdf_Style(); if ($params) { $style->setFont(Model_Static_Fonts::get("Arial Narrow" . ($i == 0 && !$header ? ' Bold' : '')), $this->fontSizeFormat); } else { $style->setFont(Model_Static_Fonts::get("Arial Narrow" . ($i == 0 && !$header ? ' Bold' : '')), $this->fontSizeFormatDiscription); } $style->setLineWidth($widths[$i]); // пишем клетку, и запоминаем макс высоту ( для многострочности ) // выравнивание по центру значения таблицы с параметрами $width_text = $this->widthForStringUsingFontsize(trim($col), $style->getFont(), $style->getFontSize()); if ($widths[$i] > $width_text && $params && $i != 0) { $iLeft = $x + ($widths[$i] - $width_text) / 2; $line_y = min($line_y, $this->drawTextBlock(str_replace(' ', ' ', trim($col)), $iLeft, $y, $style, -2)); } elseif ($params && $i == 0) { $iLeft = $x + 10; $line_y = min($line_y, $this->drawTextBlock(str_replace(' ', ' ', trim($col)), $iLeft, $y, $style, -2)); } else { $iLeft = $x; $line_y = min($line_y, $this->drawTextBlock(str_replace(' ', ' ', trim($col)), $iLeft, $y + 4, $style)); } $x += $widths[$i]; } $heightSnoski = 0; $y = $line_y; if ($header) { $style = new Zend_Pdf_Style(); $style->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatSnoski); $style->setLineWidth($width); $heightSnoski = $this->getTextBlockHeight($snoski, $style, 0, true); } // проверим, не вышли ли бы за границы высоты, но не в последнем элементе if ($y - 11 - $heightSnoski < 8 && count($table) == 1) { if ($header) { $this->drawTextBlock($snoski, 5, $y, $style); //$page -> setCurrentPosition($page -> getCurrentPosition()); } if ($this->currentPosition > $y - $this->MARGIN['bottom']) { $this->currentPosition = $y - $this->MARGIN['bottom']; } return NULL; } if ($y - $max_y - $heightSnoski < 8 && $c_row != count($table) - 1) { // if ($header) { $this->drawTextBlock($snoski, 5, $y, $style); //$page -> setCurrentPosition($page -> getCurrentPosition()); } if ($this->currentPosition > $y - $this->MARGIN['bottom']) { $this->currentPosition = $y - $this->MARGIN['bottom']; } return $c_row; } } //$this -> drawTextBlock($y, -20, $y + 10, $style); if ($this->currentPosition > $y - $this->MARGIN['bottom']) { $this->currentPosition = $y - $this->MARGIN['bottom']; } // пишем сноски в конце блока с парамаетрами if ($header) { $style = new Zend_Pdf_Style(); $style->setFont(Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatSnoski); $style->setLineWidth($width); $this->drawTextBlock($snoski, 5, $y, $style); // $this -> drawTextBlock( $note, 5, $this -> getCurrentPosition() + 25, $style); //$this -> setCurrentPosition($this -> getCurrentPosition()); } return NULL; }