1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: abstract class Mage_Sales_Model_Order_Pdf_Abstract extends Varien_Object
35: {
36: 37: 38: 39: 40:
41: public $y;
42:
43: 44: 45: 46: 47: 48: 49: 50:
51: protected $_renderers = array();
52:
53: 54: 55:
56: const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id';
57: const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id';
58: const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id';
59:
60: 61: 62: 63: 64:
65: protected $_pdf;
66:
67: 68: 69: 70: 71:
72: protected $_defaultTotalModel = 'sales/order_pdf_total_default';
73:
74: 75: 76: 77: 78:
79: abstract public function getPdf();
80:
81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
95: public function widthForStringUsingFontSize($string, $font, $fontSize)
96: {
97: $drawingString = '"libiconv"' == ICONV_IMPL ?
98: iconv('UTF-8', 'UTF-16BE//IGNORE', $string) :
99: @iconv('UTF-8', 'UTF-16BE', $string);
100:
101: $characters = array();
102: for ($i = 0; $i < strlen($drawingString); $i++) {
103: $characters[] = (ord($drawingString[$i++]) << 8) | ord($drawingString[$i]);
104: }
105: $glyphs = $font->glyphNumbersForCharacters($characters);
106: $widths = $font->widthsForGlyphs($glyphs);
107: $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
108: return $stringWidth;
109:
110: }
111:
112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122:
123: public function getAlignRight($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize, $padding = 5)
124: {
125: $width = $this->widthForStringUsingFontSize($string, $font, $fontSize);
126: return $x + $columnWidth - $width - $padding;
127: }
128:
129: 130: 131: 132: 133: 134: 135: 136: 137: 138:
139: public function getAlignCenter($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize)
140: {
141: $width = $this->widthForStringUsingFontSize($string, $font, $fontSize);
142: return $x + round(($columnWidth - $width) / 2);
143: }
144:
145: 146: 147: 148: 149: 150:
151: protected function insertLogo(&$page, $store = null)
152: {
153: $this->y = $this->y ? $this->y : 815;
154: $image = Mage::getStoreConfig('sales/identity/logo', $store);
155: if ($image) {
156: $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image;
157: if (is_file($image)) {
158: $image = Zend_Pdf_Image::imageWithPath($image);
159: $top = 830;
160: $widthLimit = 270;
161: $heightLimit = 270;
162: $width = $image->getPixelWidth();
163: $height = $image->getPixelHeight();
164:
165:
166: $ratio = $width / $height;
167: if ($ratio > 1 && $width > $widthLimit) {
168: $width = $widthLimit;
169: $height = $width / $ratio;
170: } elseif ($ratio < 1 && $height > $heightLimit) {
171: $height = $heightLimit;
172: $width = $height * $ratio;
173: } elseif ($ratio == 1 && $height > $heightLimit) {
174: $height = $heightLimit;
175: $width = $widthLimit;
176: }
177:
178: $y1 = $top - $height;
179: $y2 = $top;
180: $x1 = 25;
181: $x2 = $x1 + $width;
182:
183:
184: $page->drawImage($image, $x1, $y1, $x2, $y2);
185:
186: $this->y = $y1 - 10;
187: }
188: }
189: }
190:
191: 192: 193: 194: 195: 196:
197: protected function insertAddress(&$page, $store = null)
198: {
199: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
200: $font = $this->_setFontRegular($page, 10);
201: $page->setLineWidth(0);
202: $this->y = $this->y ? $this->y : 815;
203: $top = 815;
204: foreach (explode("\n", Mage::getStoreConfig('sales/identity/address', $store)) as $value){
205: if ($value !== '') {
206: $value = preg_replace('/<br[^>]*>/i', "\n", $value);
207: foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
208: $page->drawText(trim(strip_tags($_value)),
209: $this->getAlignRight($_value, 130, 440, $font, 10),
210: $top,
211: 'UTF-8');
212: $top -= 10;
213: }
214: }
215: }
216: $this->y = ($this->y > $top) ? $top : $this->y;
217: }
218:
219: 220: 221: 222: 223: 224:
225: protected function _formatAddress($address)
226: {
227: $return = array();
228: foreach (explode('|', $address) as $str) {
229: foreach (Mage::helper('core/string')->str_split($str, 45, true, true) as $part) {
230: if (empty($part)) {
231: continue;
232: }
233: $return[] = $part;
234: }
235: }
236: return $return;
237: }
238:
239: 240: 241: 242: 243: 244:
245: protected function _calcAddressHeight($address)
246: {
247: $y = 0;
248: foreach ($address as $value){
249: if ($value !== '') {
250: $text = array();
251: foreach (Mage::helper('core/string')->str_split($value, 55, true, true) as $_value) {
252: $text[] = $_value;
253: }
254: foreach ($text as $part) {
255: $y += 15;
256: }
257: }
258: }
259: return $y;
260: }
261:
262: 263: 264: 265: 266: 267: 268:
269: protected function insertOrder(&$page, $obj, $putOrderId = true)
270: {
271: if ($obj instanceof Mage_Sales_Model_Order) {
272: $shipment = null;
273: $order = $obj;
274: } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) {
275: $shipment = $obj;
276: $order = $shipment->getOrder();
277: }
278:
279: $this->y = $this->y ? $this->y : 815;
280: $top = $this->y;
281:
282: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
283: $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
284: $page->drawRectangle(25, $top, 570, $top - 55);
285: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
286: $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55));
287: $this->_setFontRegular($page, 10);
288:
289: if ($putOrderId) {
290: $page->drawText(
291: Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, ($top -= 30), 'UTF-8'
292: );
293: }
294: $page->drawText(
295: Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate(
296: $order->getCreatedAtStoreDate(), 'medium', false
297: ),
298: 35,
299: ($top -= 15),
300: 'UTF-8'
301: );
302:
303: $top -= 10;
304: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
305: $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
306: $page->setLineWidth(0.5);
307: $page->drawRectangle(25, $top, 275, ($top - 25));
308: $page->drawRectangle(275, $top, 570, ($top - 25));
309:
310:
311:
312:
313: $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));
314:
315:
316: $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())
317: ->setIsSecureMode(true)
318: ->toPdf();
319: $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
320: $payment = explode('{{pdf_row_separator}}', $paymentInfo);
321: foreach ($payment as $key=>$value){
322: if (strip_tags(trim($value)) == '') {
323: unset($payment[$key]);
324: }
325: }
326: reset($payment);
327:
328:
329: if (!$order->getIsVirtual()) {
330:
331: $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
332: $shippingMethod = $order->getShippingDescription();
333: }
334:
335: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
336: $this->_setFontBold($page, 12);
337: $page->drawText(Mage::helper('sales')->__('Sold to:'), 35, ($top - 15), 'UTF-8');
338:
339: if (!$order->getIsVirtual()) {
340: $page->drawText(Mage::helper('sales')->__('Ship to:'), 285, ($top - 15), 'UTF-8');
341: } else {
342: $page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, ($top - 15), 'UTF-8');
343: }
344:
345: $addressesHeight = $this->_calcAddressHeight($billingAddress);
346: if (isset($shippingAddress)) {
347: $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
348: }
349:
350: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
351: $page->drawRectangle(25, ($top - 25), 570, $top - 33 - $addressesHeight);
352: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
353: $this->_setFontRegular($page, 10);
354: $this->y = $top - 40;
355: $addressesStartY = $this->y;
356:
357: foreach ($billingAddress as $value){
358: if ($value !== '') {
359: $text = array();
360: foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
361: $text[] = $_value;
362: }
363: foreach ($text as $part) {
364: $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
365: $this->y -= 15;
366: }
367: }
368: }
369:
370: $addressesEndY = $this->y;
371:
372: if (!$order->getIsVirtual()) {
373: $this->y = $addressesStartY;
374: foreach ($shippingAddress as $value){
375: if ($value!=='') {
376: $text = array();
377: foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
378: $text[] = $_value;
379: }
380: foreach ($text as $part) {
381: $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
382: $this->y -= 15;
383: }
384: }
385: }
386:
387: $addressesEndY = min($addressesEndY, $this->y);
388: $this->y = $addressesEndY;
389:
390: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
391: $page->setLineWidth(0.5);
392: $page->drawRectangle(25, $this->y, 275, $this->y-25);
393: $page->drawRectangle(275, $this->y, 570, $this->y-25);
394:
395: $this->y -= 15;
396: $this->_setFontBold($page, 12);
397: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
398: $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8');
399: $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y , 'UTF-8');
400:
401: $this->y -=10;
402: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
403:
404: $this->_setFontRegular($page, 10);
405: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
406:
407: $paymentLeft = 35;
408: $yPayments = $this->y - 15;
409: }
410: else {
411: $yPayments = $addressesStartY;
412: $paymentLeft = 285;
413: }
414:
415: foreach ($payment as $value){
416: if (trim($value) != '') {
417:
418: $value = preg_replace('/<br[^>]*>/i', "\n", $value);
419: foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
420: $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
421: $yPayments -= 15;
422: }
423: }
424: }
425:
426: if ($order->getIsVirtual()) {
427:
428: $yPayments = min($addressesEndY, $yPayments);
429: $page->drawLine(25, ($top - 25), 25, $yPayments);
430: $page->drawLine(570, ($top - 25), 570, $yPayments);
431: $page->drawLine(25, $yPayments, 570, $yPayments);
432:
433: $this->y = $yPayments - 15;
434: } else {
435: $topMargin = 15;
436: $methodStartY = $this->y;
437: $this->y -= 15;
438:
439: foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) {
440: $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
441: $this->y -= 15;
442: }
443:
444: $yShipments = $this->y;
445: $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " "
446: . $order->formatPriceTxt($order->getShippingAmount()) . ")";
447:
448: $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
449: $yShipments -= $topMargin + 10;
450:
451: $tracks = array();
452: if ($shipment) {
453: $tracks = $shipment->getAllTracks();
454: }
455: if (count($tracks)) {
456: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
457: $page->setLineWidth(0.5);
458: $page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
459: $page->drawLine(400, $yShipments, 400, $yShipments - 10);
460:
461:
462: $this->_setFontRegular($page, 9);
463: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
464:
465: $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8');
466: $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8');
467:
468: $yShipments -= 20;
469: $this->_setFontRegular($page, 8);
470: foreach ($tracks as $track) {
471:
472: $CarrierCode = $track->getCarrierCode();
473: if ($CarrierCode != 'custom') {
474: $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode);
475: $carrierTitle = $carrier->getConfigData('title');
476: } else {
477: $carrierTitle = Mage::helper('sales')->__('Custom Value');
478: }
479:
480:
481: $maxTitleLen = 45;
482: $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
483: $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
484:
485: $page->drawText($truncatedTitle, 292, $yShipments , 'UTF-8');
486: $page->drawText($track->getNumber(), 410, $yShipments , 'UTF-8');
487: $yShipments -= $topMargin - 5;
488: }
489: } else {
490: $yShipments -= $topMargin - 5;
491: }
492:
493: $currentY = min($yPayments, $yShipments);
494:
495:
496: $page->drawLine(25, $methodStartY, 25, $currentY);
497: $page->drawLine(25, $currentY, 570, $currentY);
498: $page->drawLine(570, $currentY, 570, $methodStartY);
499:
500: $this->y = $currentY;
501: $this->y -= 15;
502: }
503: }
504:
505: 506: 507: 508: 509: 510: 511:
512: public function insertDocumentNumber(Zend_Pdf_Page $page, $text)
513: {
514: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
515: $this->_setFontRegular($page, 10);
516: $docHeader = $this->getDocHeaderCoordinates();
517: $page->drawText($text, 35, $docHeader[1] - 15, 'UTF-8');
518: }
519:
520: 521: 522: 523: 524: 525: 526:
527: protected function _sortTotalsList($a, $b) {
528: if (!isset($a['sort_order']) || !isset($b['sort_order'])) {
529: return 0;
530: }
531:
532: if ($a['sort_order'] == $b['sort_order']) {
533: return 0;
534: }
535:
536: return ($a['sort_order'] > $b['sort_order']) ? 1 : -1;
537: }
538:
539: 540: 541: 542: 543: 544:
545: protected function _getTotalsList($source)
546: {
547: $totals = Mage::getConfig()->getNode('global/pdf/totals')->asArray();
548: usort($totals, array($this, '_sortTotalsList'));
549: $totalModels = array();
550: foreach ($totals as $index => $totalInfo) {
551: if (!empty($totalInfo['model'])) {
552: $totalModel = Mage::getModel($totalInfo['model']);
553: if ($totalModel instanceof Mage_Sales_Model_Order_Pdf_Total_Default) {
554: $totalInfo['model'] = $totalModel;
555: } else {
556: Mage::throwException(
557: Mage::helper('sales')->__('PDF total model should extend Mage_Sales_Model_Order_Pdf_Total_Default')
558: );
559: }
560: } else {
561: $totalModel = Mage::getModel($this->_defaultTotalModel);
562: }
563: $totalModel->setData($totalInfo);
564: $totalModels[] = $totalModel;
565: }
566:
567: return $totalModels;
568: }
569:
570: 571: 572: 573: 574: 575: 576:
577: protected function insertTotals($page, $source){
578: $order = $source->getOrder();
579: $totals = $this->_getTotalsList($source);
580: $lineBlock = array(
581: 'lines' => array(),
582: 'height' => 15
583: );
584: foreach ($totals as $total) {
585: $total->setOrder($order)
586: ->setSource($source);
587:
588: if ($total->canDisplay()) {
589: $total->setFontSize(10);
590: foreach ($total->getTotalsForDisplay() as $totalData) {
591: $lineBlock['lines'][] = array(
592: array(
593: 'text' => $totalData['label'],
594: 'feed' => 475,
595: 'align' => 'right',
596: 'font_size' => $totalData['font_size'],
597: 'font' => 'bold'
598: ),
599: array(
600: 'text' => $totalData['amount'],
601: 'feed' => 565,
602: 'align' => 'right',
603: 'font_size' => $totalData['font_size'],
604: 'font' => 'bold'
605: ),
606: );
607: }
608: }
609: }
610:
611: $this->y -= 20;
612: $page = $this->drawLineBlocks($page, array($lineBlock));
613: return $page;
614: }
615:
616: 617: 618: 619: 620: 621:
622: protected function _parseItemDescription($item)
623: {
624: $matches = array();
625: $description = $item->getDescription();
626: if (preg_match_all('/<li.*?>(.*?)<\/li>/i', $description, $matches)) {
627: return $matches[1];
628: }
629:
630: return array($description);
631: }
632:
633: 634: 635:
636: protected function _beforeGetPdf() {
637: $translate = Mage::getSingleton('core/translate');
638:
639: $translate->setTranslateInline(false);
640: }
641:
642: 643: 644:
645: protected function _afterGetPdf() {
646: $translate = Mage::getSingleton('core/translate');
647:
648: $translate->setTranslateInline(true);
649: }
650:
651: 652: 653: 654: 655: 656: 657:
658: protected function _formatOptionValue($value, $order)
659: {
660: $resultValue = '';
661: if (is_array($value)) {
662: if (isset($value['qty'])) {
663: $resultValue .= sprintf('%d', $value['qty']) . ' x ';
664: }
665:
666: $resultValue .= $value['title'];
667:
668: if (isset($value['price'])) {
669: $resultValue .= " " . $order->formatPrice($value['price']);
670: }
671: return $resultValue;
672: } else {
673: return $value;
674: }
675: }
676:
677: 678: 679: 680: 681:
682: protected function _initRenderer($type)
683: {
684: $node = Mage::getConfig()->getNode('global/pdf/' . $type);
685: foreach ($node->children() as $renderer) {
686: $this->_renderers[$renderer->getName()] = array(
687: 'model' => (string)$renderer,
688: 'renderer' => null
689: );
690: }
691: }
692:
693: 694: 695: 696: 697: 698: 699:
700: protected function _getRenderer($type)
701: {
702: if (!isset($this->_renderers[$type])) {
703: $type = 'default';
704: }
705:
706: if (!isset($this->_renderers[$type])) {
707: Mage::throwException(Mage::helper('sales')->__('Invalid renderer model'));
708: }
709:
710: if (is_null($this->_renderers[$type]['renderer'])) {
711: $this->_renderers[$type]['renderer'] = Mage::getSingleton($this->_renderers[$type]['model']);
712: }
713:
714: return $this->_renderers[$type]['renderer'];
715: }
716:
717: 718: 719: 720: 721: 722: 723: 724:
725: public function getRenderer($type)
726: {
727: return $this->_getRenderer($type);
728: }
729:
730: 731: 732: 733: 734: 735: 736: 737:
738: protected function _drawItem(Varien_Object $item, Zend_Pdf_Page $page, Mage_Sales_Model_Order $order)
739: {
740: $type = $item->getOrderItem()->getProductType();
741: $renderer = $this->_getRenderer($type);
742: $renderer->setOrder($order);
743: $renderer->setItem($item);
744: $renderer->setPdf($this);
745: $renderer->setPage($page);
746: $renderer->setRenderedModel($this);
747:
748: $renderer->draw();
749:
750: return $renderer->getPage();
751: }
752:
753: 754: 755: 756: 757: 758: 759:
760: protected function _setFontRegular($object, $size = 7)
761: {
762: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
763: $object->setFont($font, $size);
764: return $font;
765: }
766:
767: 768: 769: 770: 771: 772: 773:
774: protected function _setFontBold($object, $size = 7)
775: {
776: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
777: $object->setFont($font, $size);
778: return $font;
779: }
780:
781: 782: 783: 784: 785: 786: 787:
788: protected function _setFontItalic($object, $size = 7)
789: {
790: $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
791: $object->setFont($font, $size);
792: return $font;
793: }
794:
795: 796: 797: 798: 799: 800:
801: protected function _setPdf(Zend_Pdf $pdf)
802: {
803: $this->_pdf = $pdf;
804: return $this;
805: }
806:
807: 808: 809: 810: 811: 812:
813: protected function _getPdf()
814: {
815: if (!$this->_pdf instanceof Zend_Pdf) {
816: Mage::throwException(Mage::helper('sales')->__('Please define PDF object before using.'));
817: }
818:
819: return $this->_pdf;
820: }
821:
822: 823: 824: 825: 826: 827:
828: public function newPage(array $settings = array())
829: {
830: $pageSize = !empty($settings['page_size']) ? $settings['page_size'] : Zend_Pdf_Page::SIZE_A4;
831: $page = $this->_getPdf()->newPage($pageSize);
832: $this->_getPdf()->pages[] = $page;
833: $this->y = 800;
834:
835: return $page;
836: }
837:
838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862:
863: public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
864: {
865: foreach ($draw as $itemsProp) {
866: if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
867: Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
868: }
869: $lines = $itemsProp['lines'];
870: $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
871:
872: if (empty($itemsProp['shift'])) {
873: $shift = 0;
874: foreach ($lines as $line) {
875: $maxHeight = 0;
876: foreach ($line as $column) {
877: $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
878: if (!is_array($column['text'])) {
879: $column['text'] = array($column['text']);
880: }
881: $top = 0;
882: foreach ($column['text'] as $part) {
883: $top += $lineSpacing;
884: }
885:
886: $maxHeight = $top > $maxHeight ? $top : $maxHeight;
887: }
888: $shift += $maxHeight;
889: }
890: $itemsProp['shift'] = $shift;
891: }
892:
893: if ($this->y - $itemsProp['shift'] < 15) {
894: $page = $this->newPage($pageSettings);
895: }
896:
897: foreach ($lines as $line) {
898: $maxHeight = 0;
899: foreach ($line as $column) {
900: $fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
901: if (!empty($column['font_file'])) {
902: $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
903: $page->setFont($font, $fontSize);
904: } else {
905: $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
906: switch ($fontStyle) {
907: case 'bold':
908: $font = $this->_setFontBold($page, $fontSize);
909: break;
910: case 'italic':
911: $font = $this->_setFontItalic($page, $fontSize);
912: break;
913: default:
914: $font = $this->_setFontRegular($page, $fontSize);
915: break;
916: }
917: }
918:
919: if (!is_array($column['text'])) {
920: $column['text'] = array($column['text']);
921: }
922:
923: $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
924: $top = 0;
925: foreach ($column['text'] as $part) {
926: if ($this->y - $lineSpacing < 15) {
927: $page = $this->newPage($pageSettings);
928: }
929:
930: $feed = $column['feed'];
931: $textAlign = empty($column['align']) ? 'left' : $column['align'];
932: $width = empty($column['width']) ? 0 : $column['width'];
933: switch ($textAlign) {
934: case 'right':
935: if ($width) {
936: $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
937: }
938: else {
939: $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
940: }
941: break;
942: case 'center':
943: if ($width) {
944: $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
945: }
946: break;
947: }
948: $page->drawText($part, $feed, $this->y-$top, 'UTF-8');
949: $top += $lineSpacing;
950: }
951:
952: $maxHeight = $top > $maxHeight ? $top : $maxHeight;
953: }
954: $this->y -= $maxHeight;
955: }
956: }
957:
958: return $page;
959: }
960: }
961: