public static function get($font)
 {
     if (empty(Fonts::$loaded[$font])) {
         if (!isset(Fonts::$fonts[$font])) {
             exit('NO FONT SELECTED');
         }
         Fonts::$loaded[$font] = Zend_Pdf_Font::fontWithPath("__fonts/" . Fonts::$fonts[$font]);
     }
     return Fonts::$loaded[$font];
 }
 /**
  * Get or load font
  *
  * @param string $font Font name
  * @return Zend_Pdf_Font Selected font
  */
 public static function get($font)
 {
     if (empty(Model_Static_Fonts::$loaded[$font])) {
         if (!isset(Model_Static_Fonts::$Model_Static_Fonts[$font])) {
             exit('NO FONT SELECTED');
         }
         Model_Static_Fonts::$loaded[$font] = Zend_Pdf_Font::fontWithPath(APPLICATION_ROOT . '/files/pdf/fonts/' . Model_Static_Fonts::$Model_Static_Fonts[$font]);
     }
     return Model_Static_Fonts::$loaded[$font];
 }
Example #3
0
 protected function _buildPDFDocuments(Doc_Book $book)
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../_vendor/zf');
     $pdf = new Zend_Pdf();
     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
     $font = Zend_Pdf_Font::fontWithPath('c:\\windows\\fonts\\simkai.ttf');
     $page->setFont($font, 12);
     $pdf->pages[] = $page;
     $page->drawText('中文测试', 100, 430, 'UTF-8');
     $pdf->save('output.pdf');
 }
Example #4
0
 public function __construct()
 {
     $this->_page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
     $this->_yPosition = 40;
     $this->_leftMargin = 20;
     $this->_pageHeight = $this->_page->getHeight();
     //842 point
     $this->_pageWidth = $this->_page->getWidth();
     //595 point
     $this->_normalFont = Zend_Pdf_Font::fontWithPath(APPLICATION_PATH . '/templates/admin/fonts/times.ttf');
     $this->_boldFont = Zend_Pdf_Font::fontWithPath(APPLICATION_PATH . '/templates/admin/fonts/timesbd.ttf');
 }
Example #5
0
 private function gerarCertificado($idEncontro, $array = array())
 {
     // include auto-loader class
     require_once 'Zend/Loader/Autoloader.php';
     // register auto-loader
     $loader = Zend_Loader_Autoloader::getInstance();
     $pdf = new Zend_Pdf();
     $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     $font = Zend_Pdf_Font::fontWithPath(APPLICATION_PATH . "/../public/font/UbuntuMono-R.ttf");
     $page1->setFont($font, Sige_Pdf_Certificado::TAM_FONTE);
     // configura o plano de fundo
     $this->background($page1, $idEncontro);
     for ($index = 0; $index < count($array); $index++) {
         $page1->drawText($array[$index], Sige_Pdf_Certificado::POS_X_INICIAL, Sige_Pdf_Certificado::POS_Y_INICIAL - $index * Sige_Pdf_Certificado::DES_Y, 'UTF-8');
     }
     // configura a(s) assinatura(s)
     $this->assinaturas($page1, $idEncontro);
     $pdf->pages[] = $page1;
     // salve apenas em modo debug!
     // $pdf->save(APPLICATION_PATH . '/../tmp/certificado-participante.pdf');
     // Get PDF document as a string
     return $pdf->render();
 }
Example #6
0
 /**
  * Set font as italic
  *
  * @param  int $size
  * @return \Zend_Pdf_Resource_Font
  */
 protected function _setFontItalic($size = 7)
 {
     $font = \Zend_Pdf_Font::fontWithPath($this->_rootDirectory->getAbsolutePath('lib/internal/LinLibertineFont/LinLibertine_It-2.8.2.ttf'));
     $this->getPage()->setFont($font, $size);
     return $font;
 }
Example #7
0
function inject($a,$pdfPage,$row,$offsety = 0) {
	global $db,$path;
	foreach($a as $t) {
			switch($t['type']) {
				case 'text':
					$pdfPage
						->setFont($pdfPage->getFont(), $t['fontSize']);
					;
					//alignedText($t,trim(@$row[$t['fieldName']]),$pdfPage,$offsety);
					$fields = explode(",",$t['fieldName']);
					$txt = "";
					foreach($fields as $field) {
						$txt .= $row[$field] . PHP_EOL;
					}
					alignedText($t,$txt,$pdfPage,$offsety);
					
				break;
				case 'cmd':
					switch($t['cmdName']) {
						case 'extratext':
							$pdfPage->setFont($pdfPage->getFont(), $t['fontSize']);
							alignedText($t,$t['extratext'],$pdfPage,$offsety);
						break;
						case 'rotate':
							$pdfPage->rotate(0, 0, deg2rad((float)$t['degrees']));
						break;
						case 'fontSize':
							$pdfPage->setFont($font, (float)$t['fontSize']);
						break;
						case 'font':
							$font = Zend_Pdf_Font::fontWithPath($path.'/fonts/'. $t['typeface'] .'.ttf',Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION); 
							$pdfPage->setFont($font, 12);
						break;
						case 'color':
							$pdfPage->setFillColor(new Zend_Pdf_Color_HTML($t['color']));
						break;
						case 'subReport':
							$subDatFile = "${path}".$t['subReportId'].".dat";
							$result = $db->Query("select * from CustomReport where Id='${t['subReportId']}'");
							if (file_exists($subDatFile)) {
								$sub = unserialize(file_get_contents($subDatFile));
							} else {
								$sub = array(
									array('type'=>'jsonInfo','nextId'=>1,'reportName'=>'CustomPDF','ReportId'=>$t['subReportId'])
								);
							}
							$sub[0] = array_merge($sub[0],$db->GetRow($result));
							//the set of commands is then going to be injected into the current page...
							$r = getQuery($sub,$row['_id']);
							$reportName = $r[1];
							
							$subResult = $db->Query($r[0]);
							$subOffsety = (float)$t['y'];
							while ($subRow = $db->GetRow($subResult)) {
								$subOffsety = inject($sub,$pdfPage,$subRow,$subOffsety);
								$subOffsety += (float)$t['ySize'];
							}
						break;
					}
				break;
			}
		}
	return $offsety;
}
Example #8
0
 /**
  * Draw lines
  *
  * Draw items array format:
  * lines        array;array of line blocks (required)
  * shift        int; full line height (optional)
  * height       int;line spacing (default 10)
  *
  * line block has line columns array
  *
  * column array format
  * text         string|array; draw text (required)
  * feed         int; x position (required)
  * font         string; font style, optional: bold, italic, regular
  * font_file    string; path to font file (optional for use your custom font)
  * font_size    int; font size (default 7)
  * align        string; text align (also see feed parametr), optional left, right
  * height       int;line spacing (default 10)
  *
  * @param  \Zend_Pdf_Page $page
  * @param  array $draw
  * @param  array $pageSettings
  * @throws \Magento\Framework\Model\Exception
  * @return \Zend_Pdf_Page
  */
 public function drawLineBlocks(\Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
 {
     foreach ($draw as $itemsProp) {
         if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
             throw new \Magento\Framework\Model\Exception(__('We don\'t recognize the draw line data. Please define the "lines" array.'));
         }
         $lines = $itemsProp['lines'];
         $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
         if (empty($itemsProp['shift'])) {
             $shift = 0;
             foreach ($lines as $line) {
                 $maxHeight = 0;
                 foreach ($line as $column) {
                     $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                     if (!is_array($column['text'])) {
                         $column['text'] = array($column['text']);
                     }
                     $top = 0;
                     foreach ($column['text'] as $part) {
                         $top += $lineSpacing;
                     }
                     $maxHeight = $top > $maxHeight ? $top : $maxHeight;
                 }
                 $shift += $maxHeight;
             }
             $itemsProp['shift'] = $shift;
         }
         if ($this->y - $itemsProp['shift'] < 15) {
             $page = $this->newPage($pageSettings);
         }
         foreach ($lines as $line) {
             $maxHeight = 0;
             foreach ($line as $column) {
                 $fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
                 if (!empty($column['font_file'])) {
                     $font = \Zend_Pdf_Font::fontWithPath($column['font_file']);
                     $page->setFont($font, $fontSize);
                 } else {
                     $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
                     switch ($fontStyle) {
                         case 'bold':
                             $font = $this->_setFontBold($page, $fontSize);
                             break;
                         case 'italic':
                             $font = $this->_setFontItalic($page, $fontSize);
                             break;
                         default:
                             $font = $this->_setFontRegular($page, $fontSize);
                             break;
                     }
                 }
                 if (!is_array($column['text'])) {
                     $column['text'] = array($column['text']);
                 }
                 $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                 $top = 0;
                 foreach ($column['text'] as $part) {
                     if ($this->y - $lineSpacing < 15) {
                         $page = $this->newPage($pageSettings);
                     }
                     $feed = $column['feed'];
                     $textAlign = empty($column['align']) ? 'left' : $column['align'];
                     $width = empty($column['width']) ? 0 : $column['width'];
                     switch ($textAlign) {
                         case 'right':
                             if ($width) {
                                 $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
                             } else {
                                 $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
                             }
                             break;
                         case 'center':
                             if ($width) {
                                 $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
                             }
                             break;
                         default:
                             break;
                     }
                     $page->drawText($part, $feed, $this->y - $top, 'UTF-8');
                     $top += $lineSpacing;
                 }
                 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
             }
             $this->y -= $maxHeight;
         }
     }
     return $page;
 }
Example #9
0
 public function getPdf($invoices = array())
 {
     $this->_beforeGetPdf();
     $this->_initRenderer('invoice');
     $selected_font = Mage::getStoreConfig('estoreiq_options/messages/estoreiq_font_selected');
     if ($selected_font == 'courier') {
         $the_font = Zend_Pdf_font::fontWithName(Zend_pdf_font::FONT_COURIER);
     } else {
         if ($selected_font == 'times') {
             $the_font = Zend_Pdf_font::fontWithName(Zend_pdf_font::FONT_TIMES);
         } else {
             $the_font = Zend_Pdf_font::fontWithName(Zend_pdf_font::FONT_HELVETICA);
         }
     }
     $pdf = new Zend_Pdf();
     $style = new Zend_Pdf_Style();
     //$this->_setFontBold($style, 10);
     foreach ($invoices as $invoice) {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $invoice->getOrder();
         $page->setFont($the_font, 10);
         /* Add image */
         $this->insertLogo($page, $invoice->getStore());
         /* Add address */
         $this->insertAddress($page, $invoice->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
         /* Add image 2 */
         $this->insertLogo2($page, $invoice->getStore());
         $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
         //$this->_setFontBold($style, 26);
         $page->setFont($the_font, 24);
         $page->drawText('TAX INVOICE (regular invoice)', 335, 580, 'UTF-8');
         /* Add Barcode (custom: Matt Johnson 2008-06-13)*/
         /* convertToBarcodeString resides in extended abstract.php file*/
         $barcodeString = $this->convertToBarcodeString($order->getRealOrderId());
         $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
         $page->setFont(Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/' . 'Code128bWin.ttf'), 22);
         $qr_code_activated = Mage::getStoreConfig('estoreiq_options/messages/estoreiq_qr_detection_code_enabled');
         if ($qr_code_activated == '1') {
             $page->drawText($barcodeString, 420, 755, 'CP1252');
         }
         $this->y -= 50;
         $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
         $this->_setFontRegular($page);
         //$page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
         /* 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')->__('Product') . $qr_code_activated, 35, $this->y, 'UTF-8');
         //$page->drawText(Mage::helper('sales')->__('SKU'), 240, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('QTY'), 430, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
         $this->y -= 15;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($invoice->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             $shift = array();
             if ($this->y < 15) {
                 /* Add new table head */
                 $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
                 $pdf->pages[] = $page;
                 $this->y = 800;
                 $this->_setFontRegular($page);
                 $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
                 $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
                 $page->setLineWidth(0.5);
                 //$page->drawRectangle(25, $this->y, 570, $this->y-15);
                 $this->y -= 10;
                 $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
                 $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8');
                 //$page->drawText(Mage::helper('sales')->__('SKU'), 240, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('QTY'), 430, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
                 $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                 $this->y -= 20;
             }
             /* Draw item */
             $this->_drawItem($item, $page, $order);
         }
         /* Add totals */
         $this->insertTotals($page, $invoice);
     }
     $this->_afterGetPdf();
     return $pdf;
 }
Example #10
0
 /**
  * Set font as italic
  *
  * @param  int $size
  * @return Zend_Pdf_Resource_Font
  */
 protected function _setFontItalic($size = 7)
 {
     $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
     $this->getPage()->setFont($font, $size);
     return $font;
 }
Example #11
0
 /**
  * Draw lines
  *
  * draw items array format:
  * lines        array;array of line blocks (required)
  * shift        int; full line height (optional)
  * height       int;line spacing (default 10)
  *
  * line block has line columns array
  *
  * column array format
  * text         string|array; draw text (required)
  * feed         int; x position (required)
  * font         string; font style, optional: bold, italic, regular
  * font_file    string; path to font file (optional for use your custom font)
  * font_size    int; font size (default 7)
  * align        string; text align (also see feed parametr), optional left, right
  * height       int;line spacing (default 10)
  *
  * @param  Zend_Pdf_Page $page
  * @param  array $draw
  * @param  array $pageSettings
  * @throws Mage_Core_Exception
  * @return Zend_Pdf_Page
  */
 public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
 {
     foreach ($draw as $itemsProp) {
         if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
             Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
         }
         $lines = $itemsProp['lines'];
         $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
         if (empty($itemsProp['shift'])) {
             $shift = 0;
             foreach ($lines as $line) {
                 $maxHeight = 0;
                 foreach ($line as $column) {
                     $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                     if (!is_array($column['text'])) {
                         $column['text'] = array($column['text']);
                     }
                     $top = 0;
                     foreach ($column['text'] as $part) {
                         $top += $lineSpacing;
                     }
                     $maxHeight = $top > $maxHeight ? $top : $maxHeight;
                 }
                 $shift += $maxHeight;
             }
             $itemsProp['shift'] = $shift;
         }
         if ($this->y - $itemsProp['shift'] < 15) {
             $page = $this->newPage($pageSettings);
         }
         foreach ($lines as $line) {
             $maxHeight = 0;
             foreach ($line as $column) {
                 // type image
                 if (isset($column["type"])) {
                     if ("image" === $column["type"]) {
                         try {
                             $image = Zend_Pdf_Image::imageWithPath($column["file"]);
                         } catch (Exception $e) {
                         }
                         if (null === $image) {
                         } else {
                             $mw = 50;
                             $mh = 50;
                             $ratio = $image->getPixelWidth() / $mw;
                             $w = $image->getPixelWidth() / $ratio;
                             $h = $image->getPixelHeight() / $ratio;
                             if ($h > $mh) {
                                 $ratio = $image->getPixelHeight() / $mh;
                                 $w = $image->getPixelWidth() / $ratio;
                                 $h = $image->getPixelHeight() / $ratio;
                             }
                             $x1 = $column["feed"];
                             $y1 = $this->y - $h + 20;
                             $x2 = $x1 + $w;
                             $y2 = $y1 + $h;
                             $page->drawImage($image, $x1, $y1, $x2, $y2);
                         }
                     }
                 }
                 // type checker
                 if (isset($column["type"])) {
                     if ("check" === $column["type"]) {
                         $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.2));
                         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
                         // checker one
                         $x1 = $column["feed"];
                         $y1 = $this->y + 25;
                         $x2 = $column["feed"] + 48;
                         $y2 = $this->y - 48 + 25;
                         $page->drawRectangle($x1, $y1, $x2, $y2);
                         //
                         // checker two
                         /*
                         $x1 = $column["feed"] +50;
                         $y1 = $this->y -32;
                         $x2 = $column["feed"] +10 +50;
                         $y2 = $this->y +10 -32;				
                         $page->drawRectangle($x1, $y1, $x2, $y2);
                         			
                                 			$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                         $page->drawText("Für den erneuten Versand der Ware bitte ankreuzen:", 380, $y2 -6, 'UTF-8');
                         */
                         //
                         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                     }
                 }
                 $fontSize = empty($column['font_size']) ? 7 : $column['font_size'];
                 if (!empty($column['font_file'])) {
                     $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
                     $page->setFont($font, $fontSize);
                 } else {
                     $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
                     switch ($fontStyle) {
                         case 'bold':
                             $font = $this->_setFontBold($page, $fontSize);
                             break;
                         case 'italic':
                             $font = $this->_setFontItalic($page, $fontSize);
                             break;
                         default:
                             $font = $this->_setFontRegular($page, $fontSize);
                             break;
                     }
                 }
                 if (!is_array($column['text'])) {
                     $column['text'] = array($column['text']);
                 }
                 $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                 $top = 0;
                 $antitop = 0;
                 foreach ($column['text'] as $part) {
                     if ($this->y - $lineSpacing < 15) {
                         $page = $this->newPage($pageSettings);
                     }
                     $feed = $column['feed'];
                     $textAlign = empty($column['align']) ? 'left' : $column['align'];
                     $width = empty($column['width']) ? 0 : $column['width'];
                     switch ($textAlign) {
                         case 'right':
                             if ($width) {
                                 $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
                             } else {
                                 $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
                             }
                             break;
                         case 'center':
                             if ($width) {
                                 $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
                             }
                             break;
                     }
                     $page->drawText($part, $feed, $this->y - $antitop, 'UTF-8');
                     $antitop += 12;
                 }
                 $top += $lineSpacing;
                 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
             }
             $this->y -= $maxHeight;
         }
     }
     return $page;
 }
Example #12
0
 public function getFont($po_pdf, $ps_fontname, $ps_encoding = 'auto')
 {
     if ($this->getPDFLibrary() == __PDF_LIBRARY_ZEND__) {
         if (isset($this->opa_fonts[$ps_fontname])) {
             return $this->opa_fonts[$ps_fontname];
         }
         $o_font = null;
         // try loading it from configured font dir
         if ($vs_font_dir = $this->opo_config->get('fonts_directory')) {
             if (file_exists($vs_font_dir . '/' . $ps_fontname)) {
                 try {
                     $o_font = Zend_Pdf_Font::fontWithPath($vs_font_dir . '/' . $ps_fontname);
                 } catch (Exception $e) {
                     //noop
                 }
             }
         }
         if (!$o_font) {
             try {
                 $o_font = Zend_Pdf_Font::fontWithName($ps_fontname);
             } catch (Exception $e) {
                 $o_font = Zend_Pdf_Font::fontWithName('Courier');
             }
             $this->opa_fonts[$ps_fontname] = $o_font;
         }
         return $o_font;
     } else {
         if (isset($this->opa_fonts[$ps_fontname])) {
             return $this->opa_fonts[$ps_fontname];
         }
         if ($vn_font = $po_pdf->load_font($ps_fontname, 'winansi', "errorpolicy=return")) {
             return $this->opa_fonts[$ps_fontname] = $vn_font;
         }
         // try loading it from configured font dir
         if ($vs_font_dir = $this->opo_config->get('fonts_directory')) {
             $po_pdf->set_parameter('FontOutline', $ps_fontname . '=' . $vs_font_dir . '/' . $ps_fontname);
             $va_tmp = explode('.', $ps_fontname);
             array_pop($va_tmp);
             $vs_afm_name = join('.', $va_tmp) . '.afm';
             $po_pdf->set_parameter('FontAFM', $ps_fontname . '=' . $vs_font_dir . '/' . $vs_afm_name);
             if ($vn_font = $po_pdf->load_font($ps_fontname, 'winansi', "errorpolicy=return")) {
                 return $this->opa_fonts[$ps_fontname] = $vn_font;
             }
         }
     }
     $this->postError(2260, _t("Could not load font '%1'", $ps_fontname), "PrintForms->getFont()");
     return null;
 }
	public function ajaxpdfAction()
	{
		$this->_helper->layout()->disableLayout();
	//	$this->_helper->viewRenderer->setNoRender(true);
		
		$pdf = new Zend_Pdf();
		$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
		$font = Zend_Pdf_Font::fontWithPath('font/simkai.ttf',(Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION |
Zend_Pdf_Font::EMBED_DONT_COMPRESS));
		//put the personal information to the pdf
		$contacts = new Employee_Models_ContactMapper();
		$arrayContacts = $contacts->fetchAllJoin();
		$count = 1;//every page show approximately 20 pieces;
		//$arrayCount = count($arrayContacts);
		$totalItems = $arrayContacts->getTotalItemCount();
		$arrayContacts->setItemCountPerPage($totalItems);

		$pageNumber = ceil($totalItems / 25);
		$x = 0; $y = 750;
		$currentpage = 1;
		foreach($arrayContacts as $contact)
		{
			if($count == 1)
			{
				$page->setLineWidth(0.5);
				$page->drawLine(50, 770, 560, 770);
				$page->drawLine(50, 125, 560, 125);
				$page->setFont($font,13)
						->drawText("编号", 50, $y, 'UTF-8')
						->drawText("姓名", 100, $y, 'UTF-8')
						->drawText("性别", 145, $y, 'UTF-8')
						->drawText("生日", 195, $y, 'UTF-8')
						->drawText("部门", 275, $y, 'UTF-8')
						->drawText("职务", 335, $y, 'UTF-8')
						->drawText("入职时间", 415, $y, 'UTF-8')
						->drawText("手机号码", 495, $y, 'UTF-8');
				$time = Date("Y-m-d,H:i");
				$users = new System_Models_UserMapper();
				$contactId = $users->getContactId($this->getUserId());
				$contacts = new Employee_Models_ContactMapper();
				$contactName = $contacts->findContactName($contactId);
				$page->setFont($font,11)
						->drawText("公司员工信息总览", 250, 790, 'UTF-8')
						->drawText("导出人:".$contactName, 50, 100, 'UTF-8')
						->drawText("导出日期:".$time, 250, 100, 'UTF-8')
						->drawText("页数:".$currentpage."(".$pageNumber.")", 500, 100, 'UTF-8');
				}
				$y -= 25;$count++;
				$page->setFont($font, 11)
						->drawText($contact->contactId, $x+=50, $y, 'UTF-8')
						->drawText($contact->contactName, $x+=50, $y, 'UTF-8')
						->drawText($contact->gender, $x+=45, $y, 'UTF-8')
						->drawText($contact->birth, $x+=50, $y, 'UTF-8')
						->drawText($contact->deptName, $x+=80, $y, 'UTF-8')
						->drawText($contact->dutyName, $x+=60, $y, 'UTF-8')
						->drawText($contact->enroll, $x+=80, $y, 'UTF-8')
						->drawText($contact->phoneMob, $x+=80, $y, 'UTF-8');
			if($count >= 25)
			{
				$pdf->pages[] = $page;
				$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
				$count = 1;
				$y = 750;
				$currentpage++;
				}
			$x = 0;
			}
		$pdf->pages[] = $page;
		$name_string = "公司员工信息总览".time().".pdf";
		//server
		$base = General_Models_ServerInfo::$localUrl;
		$url = 'tmp/'.$name_string;
		$pdf->save($url);
		$murl = $base.'/'.$url;
		$this->view->murl = $murl;
		}
Example #14
0
 protected function setFont(\Zend_Pdf_Page $page, $size = 12)
 {
     $basePath = APPLICATION_PATH . "/../public/fonts/";
     $font = \Zend_Pdf_Font::fontWithPath($basePath . 'LiberationSans-Regular.ttf');
     $page->setFont($font, $size);
 }
Example #15
0
 public function testFontDrawing()
 {
     $pdf = new Zend_Pdf();
     $fontsList = array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_COURIER_BOLD, Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC, Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE, Zend_Pdf_Font::FONT_COURIER_ITALIC, Zend_Pdf_Font::FONT_COURIER_OBLIQUE, Zend_Pdf_Font::FONT_HELVETICA, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC, Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE, Zend_Pdf_Font::FONT_HELVETICA_ITALIC, Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE, Zend_Pdf_Font::FONT_TIMES, Zend_Pdf_Font::FONT_TIMES_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, Zend_Pdf_Font::FONT_TIMES_ITALIC, Zend_Pdf_Font::FONT_TIMES_ROMAN);
     $titleFont = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE);
     foreach ($fontsList as $fontName) {
         // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
         $font = Zend_Pdf_Font::fontWithName($fontName);
         $this->assertTrue($font instanceof Zend_Pdf_Resource_Font);
         $page->setFont($titleFont, 10);
         $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400);
         $page->setFont($font, 20);
         $page->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $ascent = $font->getAscent();
         $this->assertTrue(abs(1 - $font->getCoveredPercentage('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz')) < 1.0E-5);
         $descent = $font->getDescent();
         $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en');
         $type = $font->getFontType();
         $lineGap = $font->getLineGap();
         $lineHeight = $font->getLineHeight();
         $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object);
         $font->getStrikePosition();
         $font->getStrikeThickness();
         $font->getUnderlinePosition();
         $font->getUnitsPerEm();
         $font->widthForGlyph(10);
     }
     $nonAlphabeticalPhonts = array(Zend_Pdf_Font::FONT_SYMBOL => " !\"#\"%&\"\v()\"+,\"./0123456789:;<=>?\"E‘’§\"•¦", Zend_Pdf_Font::FONT_ZAPFDINGBATS => " ''''&''''\t&&'\f'\r'''''''''''''");
     foreach ($nonAlphabeticalPhonts as $fontName => $example) {
         // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
         $font = Zend_Pdf_Font::fontWithName($fontName);
         $this->assertTrue($font instanceof Zend_Pdf_Resource_Font);
         $page->setFont($titleFont, 10);
         $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400);
         $page->setFont($font, 20);
         $page->drawText($example, 100, 360, 'UTF-16BE');
         $ascent = $font->getAscent();
         $this->assertTrue(abs(1 - $font->getCoveredPercentage($example, 'UTF-16BE')) < 1.0E-5);
         $descent = $font->getDescent();
         $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en');
         $type = $font->getFontType();
         $lineGap = $font->getLineGap();
         $lineHeight = $font->getLineHeight();
         $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object);
         $font->getStrikePosition();
         $font->getStrikeThickness();
         $font->getUnderlinePosition();
         $font->getUnitsPerEm();
         $font->widthForGlyph(10);
     }
     $TTFFontsList = array('VeraBd.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMoBd.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraMono.ttf', 'VeraSeBd.ttf', 'VeraSe.ttf', 'Vera.ttf');
     foreach ($TTFFontsList as $fontName) {
         // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
         $font = Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/_fonts/' . $fontName);
         $this->assertTrue($font instanceof Zend_Pdf_Resource_Font);
         $page->setFont($titleFont, 10);
         $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400);
         $page->setFont($font, 20);
         $page->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $ascent = $font->getAscent();
         $this->assertTrue(abs(1 - $font->getCoveredPercentage('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz')) < 1.0E-5);
         $descent = $font->getDescent();
         $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en');
         $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en');
         $type = $font->getFontType();
         $lineGap = $font->getLineGap();
         $lineHeight = $font->getLineHeight();
         $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object);
         $font->getStrikePosition();
         $font->getStrikeThickness();
         $font->getUnderlinePosition();
         $font->getUnitsPerEm();
         $font->widthForGlyph(10);
     }
     $pdf->save(dirname(__FILE__) . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf');
     $this->assertTrue($pdf1 instanceof Zend_Pdf);
     unset($pdf1);
     unlink(dirname(__FILE__) . '/_files/output.pdf');
 }
 public function __construct()
 {
     parent::__construct();
     $this->Font = Zend_Pdf_Font::fontWithPath(zend_font_path() . 'ARIALUNI.TTF');
 }
Example #17
0
	public function generateAction()
	{
		$this->_helper->layout()->disableLayout();
	//	$this->_helper->viewRenderer->setNoRender(true);
		
		$pdf = new Zend_Pdf();
		$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
		$font = Zend_Pdf_Font::fontWithPath('font/simkai.ttf',(Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION |Zend_Pdf_Font::EMBED_DONT_COMPRESS));
		$target = $this->_getParam('page',0);
		if($target > 0)
		{
			$url = null;
			if($target == 1)
			{
				$url = $this->pageEmployeeIndex($pdf,$page,$font);
				}
				elseif($target == 2)
				{
					$url = $this->pageEmployeeDisplay($pdf,$page,$font);
					}
					elseif($target == 3)
					{
						$url = $this->pageEmployeeAjaxDisplay($pdf, $page, $font);
						}
						elseif($target == 4)
						{
							$url = $this->pageProjectIndex($pdf, $page, $font);
							}
							elseif($target == 5)
							{
								$url = $this->pageProjectAjaxDisplay($pdf, $page, $font);
								}
								elseif($target == 6)
								{
									$url = $this->pagePmentCpp($pdf, $page, $font);
									}
									elseif($target == 7)
									{
										$url = $this->pagePmentCppAjaxDisplay($pdf, $page, $font);
										}
										elseif($target == 8)
										{
											$url = $this->pagePmentMsprg($pdf, $page, $font);
											}
											elseif($target == 9)
											{
												$url = $this->pagePmentMsprgDisplay($pdf, $page, $font);
												
												}
												elseif($target == 10)
												{
													$url = $this->pagePmentPlogDisplay($pdf, $page, $font);
													}
													elseif($target == 11)
													{
														$url = $this->pagePmentTech($pdf, $page, $font);
														}
														elseif($target == 12)
														{
															$url = $this->pagePmentTechAjaxDisplay($pdf, $page, $font);
															}
															elseif($target == 13)
															{
																$url = $this->pagePmentTraining($pdf, $page, $font);
																}
																elseif($target == 14)
																{
																	$url = $this->pagePmentTrainingAjaxDisplay($pdf, $page, $font);
																	}
																	elseif($target == 15)
																	{
																		$url = $this->pagePmentMeasure($pdf, $page, $font);
																		}
																		elseif($target == 16)
																		{
																			$url = $this->pagePmentMeasureAjaxDisplay($pdf, $page,$font);
																			}
																			elseif($target == 17)
																			{
																				$url = $this->pagePmentRecord($pdf, $page, $font);
																				}
																				elseif($target == 18)
																				{
																					$url = $this->pagePmentRecordAjaxDisplay($pdf, $page, $font);
																					}
																					elseif($target == 19)
																					{
																						$url = $this->pagePmentSeal($pdf, $page, $font);
																						}
																						elseif($target == 20)
																						{
																							$url = $this->pagePmentSealAjaxDisplay($pdf, $page, $font);
																						}
			$base = General_Models_ServerInfo::$serverUrl;
			$murl = $base.'/'.$url;
			$this->view->murl = $murl;
			}
			else
			{
				$this->_redirect('/');
				}
		}
Example #18
0
 public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
 {
     if (Mage::getStoreConfig('advancedinvoiceprinting_options/general/enable') == 0) {
         return parent::drawLineBlocks($page, $draw, $pageSettings);
     }
     foreach ($draw as $itemsProp) {
         if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
             Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
         }
         $lines = $itemsProp['lines'];
         $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
         if (empty($itemsProp['shift'])) {
             $shift = 0;
             foreach ($lines as $line) {
                 $maxHeight = 0;
                 foreach ($line as $column) {
                     $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                     if (!is_array($column['text'])) {
                         $column['text'] = array($column['text']);
                     }
                     $top = 0;
                     foreach ($column['text'] as $part) {
                         $top += $lineSpacing;
                     }
                     $maxHeight = $top > $maxHeight ? $top : $maxHeight;
                 }
                 $shift += $maxHeight;
             }
             $itemsProp['shift'] = $shift;
         }
         if ($this->y - $itemsProp['shift'] < $this->calFooterTopArea()) {
             $page = $this->newPage($pageSettings);
         }
         foreach ($lines as $line) {
             $maxHeight = 0;
             foreach ($line as $column) {
                 $fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
                 if (!empty($column['font_file'])) {
                     $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
                     $page->setFont($font, $fontSize);
                 } else {
                     $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
                     switch ($fontStyle) {
                         case 'bold':
                             $font = $this->_setFontBold($page, $fontSize);
                             break;
                         case 'italic':
                             $font = $this->_setFontItalic($page, $fontSize);
                             break;
                         default:
                             $font = $this->_setFontRegular($page, $fontSize);
                             break;
                     }
                 }
                 if (!is_array($column['text'])) {
                     $column['text'] = array($column['text']);
                 }
                 $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                 $top = 0;
                 foreach ($column['text'] as $part) {
                     if ($this->y - $lineSpacing < $this->calFooterTopArea()) {
                         $page = $this->newPage($pageSettings);
                     }
                     $feed = $column['feed'];
                     $textAlign = empty($column['align']) ? 'left' : $column['align'];
                     $width = empty($column['width']) ? 0 : $column['width'];
                     switch ($textAlign) {
                         case 'right':
                             if ($width) {
                                 $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
                             } else {
                                 $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
                             }
                             break;
                         case 'center':
                             if ($width) {
                                 $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
                             }
                             break;
                     }
                     $page->drawText($part, $feed, $this->y - $top, 'UTF-8');
                     $top += $lineSpacing;
                 }
                 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
             }
             $this->y -= $maxHeight;
         }
     }
     return $page;
 }
 /**
  * the constructor
  *
  * @param   integer $_contentFontSize
  * @param   integer $_footerFontSize
  * @param   integer $_contentLineHeight
  * @param   integer $_contentBlockLineHeight
  *      */
 public function __construct($_additionalOptions = array(), $_contentFontSize = NULL, $_footerFontSize = NULL, $_contentLineHeight = NULL, $_contentBlockLineHeight = NULL)
 {
     parent::__construct();
     // get config
     $config = Tinebase_Core::getConfig()->pdfexport;
     // add first page
     $this->pages[] = $this->newPage(Zend_Pdf_Page::SIZE_A4);
     $this->_pageNumber = 0;
     // set params
     if ($_footerFontSize !== NULL) {
         $this->footerFontSize = $_footerFontSize;
     }
     if ($_contentFontSize !== NULL) {
         $this->contentFontSize = $_contentFontSize;
     }
     if ($_contentLineHeight !== NULL) {
         $this->contentLineHeight = $_contentLineHeight;
     }
     if ($_contentBlockLineHeight !== NULL) {
         $this->contentBlockLineHeight = $_contentBlockLineHeight;
     }
     // set fonts
     if (!empty($config->fontpath) && file_exists($config->fontpath)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' use font file: ' . $config->fontpath);
         }
         $boldpath = $config->get('fontboldpath', $config->fontpath);
         $embed = $config->fontembed ? 0 : Zend_Pdf_Font::EMBED_DONT_EMBED;
         // try to use ttf / type 1 / opentype / postscript fonts
         $this->_font = Zend_Pdf_Font::fontWithPath($config->fontpath, $embed);
         $this->_fontBold = Zend_Pdf_Font::fontWithPath($boldpath, $embed);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' use zend_pdf font: ' . $this->_fontName);
         }
         $this->_font = Zend_Pdf_Font::fontWithName($this->_fontName);
         $this->_fontBold = Zend_Pdf_Font::fontWithName($this->_fontNameBold);
     }
 }
 protected function drawFont($object)
 {
     $fontItem = $object->getItem();
     if ($fontItem->getFace() == 'bold') {
         $fontDecoration = 'bold';
     } else {
         $fontDecoration = 'regular';
     }
     $fontPath = SERVER_BASE . '/fonts/' . $fontItem->getName() . '.ttf';
     if (is_file($fontPath)) {
         $font = Zend_Pdf_Font::fontWithPath($fontPath, Zend_Pdf_Font::EMBED_SUPPRESS_EMBED_EXCEPTION);
     } else {
         if ($fontDecoration == "bold") {
             $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
         } else {
             $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
         }
     }
     if ($fontItem->getFace() == "invert") {
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));
         //schwarze farbe setzen fuer Hintergrund
         $width = $this->widthForStringUsingFontSize($object->getValue(), $font, $fontItem->getSize());
         $height = $fontItem->getSize();
         $this->page->drawRectangle($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())) + $height / 2, $this->coordX($this->mmToPts($object->getPosx())) + $width, $this->coordY($this->mmToPts($object->getPosy())) - $height / 2, Zend_Pdf_Page::SHAPE_DRAW_FILL);
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 1));
         //weiße farbe setzen fuer Text
     } else {
         $this->page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));
         //schwarze farbe setzen fuer text
     }
     $this->page->setFont($font, $fontItem->getSize());
     if ($fontItem->getRotation() !== null) {
         $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), deg2rad(360 - $fontItem->getRotation()));
     }
     $this->page->drawText($object->getValue(), $this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy()) + $fontItem->getSize() / 2), 'UTF-8');
     if ($fontItem->getRotation() !== null) {
         $this->page->rotate($this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy())), -deg2rad(360 - $fontItem->getRotation()));
     }
 }
Example #21
0
 /**
  * get italic font
  *
  * @return Zend_Pdf_Resource_Font
  */
 public function getFontItalic()
 {
     if ($this->getItalicFont() && $this->italicFontFileExists()) {
         return Zend_Pdf_Font::fontWithPath($this->getItalicFontFile());
     }
     return Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC);
 }
Example #22
0
 public function testFontExtracting()
 {
     if (PHP_OS == 'AIX') {
         $this->markTestSkipped('Not supported on AIX');
     }
     $pdf = new Zend_Pdf();
     $fontsList = array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC);
     foreach ($fontsList as $fontName) {
         // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
         $font = Zend_Pdf_Font::fontWithName($fontName);
         $page->setFont($font, 10)->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400);
         $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $type = $font->getFontType();
     }
     $TTFFontsList = array('VeraBd.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMoBd.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraMono.ttf', 'VeraSeBd.ttf', 'VeraSe.ttf', 'Vera.ttf');
     foreach ($TTFFontsList as $fontName) {
         // Add new page generated by Zend_Pdf object (page is attached to the specified the document)
         $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
         $font = Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/_fonts/' . $fontName);
         $page->setFont($font, 10)->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'CP1252') . ':', 100, 400);
         $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360);
         $type = $font->getFontType();
     }
     $pdf->save(dirname(__FILE__) . '/_files/output.pdf');
     unset($pdf);
     $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf');
     $newPages = array();
     $fontList = array();
     $fontNames = array();
     foreach ($pdf1->pages as $page) {
         $pageFonts = $page->extractFonts();
         foreach ($pageFonts as $font) {
             $fontList[] = $font;
             $fontNames[] = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
         }
     }
     $this->assertEquals(array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames);
     $pdf1->pages[] = $page = $pdf1->newPage(Zend_Pdf_Page::SIZE_A4);
     $yPosition = 700;
     foreach ($fontList as $font) {
         $page->setFont($font, 15)->drawText("The quick brown fox jumps over the lazy dog", 100, $yPosition);
         $yPosition -= 30;
     }
     $fontNames1 = array();
     foreach ($pdf1->extractFonts() as $font) {
         $fontNames1[] = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8');
     }
     $this->assertEquals(array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames1);
     $page = reset($pdf1->pages);
     $font = $page->extractFont(Zend_Pdf_Font::FONT_COURIER);
     $this->assertTrue($font instanceof Zend_Pdf_Resource_Font_Extracted);
     $font = $page->extractFont(Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC);
     $this->assertNull($font);
     $font = $pdf1->extractFont(Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC);
     $this->assertTrue($font instanceof Zend_Pdf_Resource_Font_Extracted);
     $font = $pdf1->extractFont(Zend_Pdf_Font::FONT_TIMES_ROMAN);
     $this->assertNull($font);
     $pdf1->save(dirname(__FILE__) . '/_files/output1.pdf');
     unset($pdf1);
     $pdf2 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output1.pdf');
     $this->assertTrue($pdf2 instanceof Zend_Pdf);
     unset($pdf2);
     unlink(dirname(__FILE__) . '/_files/output.pdf');
     unlink(dirname(__FILE__) . '/_files/output1.pdf');
 }
 public function getPdf($invoices = array())
 {
     $show_price = 0;
     $this->_beforeGetPdf();
     $this->_initRenderer('invoices');
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($invoices as $invoice) {
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->emulate($invoice->getStoreId());
         }
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $invoice->getOrder();
         /* Add image */
         $this->insertLogo($page, $order->getStore());
         /* Add address */
         $store_address = $this->insertAddress($page, 'top', $order->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
         $barcode = Mage::getStoreConfig('pickpack_options/wonder/pickpack_packbarcode');
         if ($barcode == 1) {
             $barcodeString = $this->convertToBarcodeString($order->getRealOrderId());
             $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
             $page->setFont(Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/' . 'Code128bWin.ttf'), 18);
             $page->drawText($barcodeString, 452, 800, 'CP1252');
         }
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page);
         //$page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
         /* Add products list table */
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.92));
         $this->_setFontItalic($page, 14);
         //                   ? xpos header rectangle  ? width            ? height header rectangle
         $page->drawRectangle(25, $this->y, 570, $this->y - 20);
         // HEIGHT PRODUCTS HEADER lINE
         $this->y -= 15;
         /* Add table head */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
         $page->drawText(Mage::helper('sales')->__('items'), 35, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('codes'), 255, $this->y, 'UTF-8');
         if ($show_price > 0) {
             $page->drawText(Mage::helper('sales')->__('Price'), 370, $this->y, 'UTF-8');
         }
         $page->drawText(Mage::helper('sales')->__('numbers'), 420, $this->y, 'UTF-8');
         // $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
         if ($show_price > 0) {
             $page->drawText(Mage::helper('sales')->__('Subtotal'), 525, $this->y, 'UTF-8');
         }
         $this->y -= 20;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($invoice->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             if ($this->y < 15) {
                 $page = $this->newPage(array('table_header' => true));
             }
             /* Draw item */
             $page = $this->_drawItem($item, $page, $order);
             $this->y -= 8;
         }
         /* Add totals */
         if ($show_price > 0) {
             $page = $this->insertTotals($page, $invoice);
         }
         // bottom address label
         $this->y = 115;
         /* Add table head */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
         /* Add bottom store address */
         $store_address = $this->insertAddress($page, 'bottom', $order->getStore());
         $this->y -= 20;
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->revert();
         }
     }
     $this->_afterGetPdf();
     return $pdf;
 }
Example #24
0
 /**
  * 
  * @param type $object
  * @param type $size
  * @return type
  */
 public function setFontItalic($object, $size = 7)
 {
     $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
     $object->setFont($font, $size);
     return $font;
 }
Example #25
0
 public function getPdf($shipments = array())
 {
     $this->_beforeGetPdf();
     $this->_initRenderer('shipment');
     $pdf = new Zend_Pdf();
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($shipments as $shipment) {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $shipment->getOrder();
         /* Add image */
         $this->insertLogo($page, $shipment->getStore());
         /* Add address */
         $this->insertAddress($page, $shipment->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID, $order->getStoreId()));
         /* Add Barcode (custom: Matt Johnson 2008-06-13)*/
         /* convertToBarcodeString resides in extended abstract.php file*/
         $barcodeString = $this->convertToBarcodeString($order->getRealOrderId());
         $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
         $page->setFont(Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/' . 'Code128bWin.ttf'), 18);
         $page->drawText($barcodeString, 250, 800, 'CP1252');
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page);
         $page->drawText(Mage::helper('sales')->__('Packingslip # ') . $shipment->getIncrementId(), 35, 780, 'UTF-8');
         /* 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, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('SKU'), 470, $this->y, 'UTF-8');
         $this->y -= 15;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($shipment->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             $shift = 10;
             $shift = array();
             if ($this->y < 15) {
                 /* Add new table head */
                 $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
                 $pdf->pages[] = $page;
                 $this->y = 800;
                 $this->_setFontRegular($page);
                 $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
                 $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
                 $page->setLineWidth(0.5);
                 $page->drawRectangle(25, $this->y, 570, $this->y - 15);
                 $this->y -= 10;
                 $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
                 $page->drawText(Mage::helper('sales')->__('QTY'), 35, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('Products'), 60, $this->y, 'UTF-8');
                 $page->drawText(Mage::helper('sales')->__('SKU'), 470, $this->y, 'UTF-8');
                 $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
                 $this->y -= 20;
             }
             /* Draw item */
             $this->_drawItem($item, $page, $order);
         }
     }
     $this->_afterGetPdf();
     return $pdf;
 }
Example #26
0
    }
} 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
    $boxes = array(array(p => 2, x => 89, y => 602, w => 114, h => 15, t => $stampText), array(p => 4, x => 174, y => 482, w => 114, h => 15, t => $stampText), array(p => 5, x => 169, y => 617, w => 114, h => 15, t => $stampText), array(p => 6, x => 51, y => 362, w => 114, h => 15, t => $stampText), array(p => 6, x => 120, y => 77, w => 152, h => 15, t => $stampTextD));
Example #27
0
 /**
  * Draw a text in the rendering resource
  * @param string $text
  * @param float $size
  * @param array $position
  * @param string $font
  * @param integer $color
  * @param string $alignment
  * @param float $orientation
  */
 protected function _drawText($text, $size, $position, $font, $color, $alignment = 'center', $orientation = 0)
 {
     $page = $this->_resource->pages[$this->_page];
     $color = new Zend_Pdf_Color_Rgb((($color & 0xff0000) >> 16) / 255.0, (($color & 0xff00) >> 8) / 255.0, ($color & 0xff) / 255.0);
     $page->setLineColor($color);
     $page->setFillColor($color);
     $page->setFont(Zend_Pdf_Font::fontWithPath($font), $size * $this->_moduleSize * 1.2);
     $width = $this->widthForStringUsingFontSize($text, Zend_Pdf_Font::fontWithPath($font), $size * $this->_moduleSize);
     $angle = pi() * $orientation / 180;
     $left = $position[0] * $this->_moduleSize + $this->_leftOffset;
     $top = $page->getHeight() - $position[1] * $this->_moduleSize - $this->_topOffset;
     switch ($alignment) {
         case 'center':
             $left -= $width / 2 * cos($angle);
             $top -= $width / 2 * sin($angle);
             break;
         case 'right':
             $left -= $width;
             break;
     }
     $page->rotate($left, $top, $angle);
     $page->drawText($text, $left, $top);
     $page->rotate($left, $top, -$angle);
 }
Example #28
0
 protected function _setFontRegular($object, $size = 7)
 {
     $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
     $object->setFont($font, $size);
     return $font;
 }
 public function setFontBold($type = Zend_Pdf_Font::FONT_TIMES_BOLD)
 {
     if ($this->isZendPdfFont($type)) {
         $this->_fontBold = Zend_Pdf_Font::fontWithName($type);
     } else {
         $this->_fontBold = Zend_Pdf_Font::fontWithPath(realpath(dirname(dirname(__FILE__))) . "/Fonts/" . $type);
     }
     return $this;
 }
Example #30
0
 public function getFontBold()
 {
     if ($this->getDi()->config->get('invoice_custom_ttfbold') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_ttfbold')))) {
         return Zend_Pdf_Font::fontWithPath($upload->getFullPath());
     } else {
         return Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
     }
 }