示例#1
0
文件: Pdf.php 项目: kemeice/Giftcards
 public function addNext($giftCard)
 {
     $template = $giftCard->getTemplate();
     if (!$template) {
         return false;
     }
     $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
     $draw = Mage::getModel('giftcard/giftcard_draw');
     $draw->setGiftCard($giftCard);
     $draw->setTemplate($template);
     $draw->drawGiftCard();
     if (!($imagePath = $draw->getImagePath())) {
         return false;
     }
     $image = Zend_Pdf_Image::imageWithPath($imagePath);
     $imgWidthPts = $image->getPixelWidth() * 72 / 96;
     $imgHeightPts = $image->getPixelHeight() * 72 / 96;
     $rate = $imgWidthPts / $page->getWidth();
     $imgWidthPts = $imgWidthPts / $rate;
     $imgHeightPts = $imgHeightPts / $rate;
     $pageHeight = $page->getHeight();
     $page->drawImage($image, 0, $pageHeight - $imgHeightPts, $imgWidthPts, $pageHeight);
     $this->addPage($page);
     unlink($imagePath);
     return true;
 }
示例#2
0
 /**
  *
  * @param Zend_Pdf_Page $page 
  * @return void Process drawImage on PDF page
  */
 protected function drawWaterMask(&$page)
 {
     if (Mage::getStoreConfig('advancedinvoiceprinting_options/general/enable') == 0) {
         return;
     }
     $pageWidth = $page->getWidth();
     $pageHeight = $page->getHeight();
     $image = $this->getImage();
     if (is_file($image)) {
         /* @var $image Zend_Pdf_Resource_Image */
         $image = Zend_Pdf_Image::imageWithPath($image);
         $imgWidth = $image->getPixelWidth();
         $imgHeight = $image->getPixelHeight();
         $percent = Mage::getStoreConfig('advancedinvoiceprinting_options/general/images_size');
         $imgWidth = $imgWidth * $percent / 100;
         $imgHeight = $imgHeight * $percent / 100;
         $x = ($pageWidth - $imgWidth) / 2;
         $y = ($pageHeight - $imgHeight) / 2;
         if (is_numeric(Mage::getStoreConfig('advancedinvoiceprinting_options/general/offset_x'))) {
             $x = $x + (int) Mage::getStoreConfig('advancedinvoiceprinting_options/general/offset_x');
         }
         if (is_numeric(Mage::getStoreConfig('advancedinvoiceprinting_options/general/offset_y'))) {
             $y = $y - (int) Mage::getStoreConfig('advancedinvoiceprinting_options/general/offset_y');
         }
         $page->drawImage($image, $x, $y, $x + $imgWidth, $y + $imgHeight);
     }
 }
 private function coordY($y)
 {
     return $this->page->getHeight() - $y - $this->_startpunkt['y'];
 }
 /**
  * Apply stamp on one page with given style.
  * 
  * @param Zend_Pdf_Page  $page
  * @param Zend_Pdf_Style $style
  * @param String         $stamp
  * 
  * @return void
  */
 protected function stampOnePage($page, $style, $stamp)
 {
     $height = $page->getHeight();
     $page->setStyle($style);
     $page->drawRectangle(40, 40, 60, $height - 40, Zend_Pdf_Page::SHAPE_DRAW_STROKE);
     $page->rotate(20, 20, 1.57);
     $page->drawText($stamp, 50, -10);
 }
示例#5
0
 /**
  * Generate a review portal pdf.
  *
  * @param integer $portalId
  * @return string The pdf name
  */
 protected function _generatePdf($portalId)
 {
     $portal = new Object_ReviewPortal($portalId);
     if (!$portal->getId()) {
         return false;
     }
     // Get the screenshots of all the portal pages.
     $pages = Repo_ReviewPortalPage::getInstance()->getPortalPages($portalId);
     if (!$pages || $pages->count() == 0) {
         return false;
     }
     $pdf = new Zend_Pdf();
     $pageNumber = 1;
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     $fontSize = 10;
     foreach ($pages as $_p) {
         $_images = array();
         $_page = new Object_Page($_p->id);
         // Try get static screenshots if the setting is set.
         if ($_page->screenshot_type == Repo_Page::SCREENSHOT_TYPE_STATIC) {
             $_images = $_page->getStaticScreenshots(true);
         }
         // Get dynamic one.
         if (empty($_images)) {
             $_images[] = Manager_ScreenCapture_Page::getInstance()->getScreenshot($_p->id);
         }
         foreach ($_images as $_image) {
             $_pdfImage = Zend_Pdf_Image::imageWithPath($_image);
             $_pdfPage = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE);
             $_pdfPage->drawImage($_pdfImage, 20, 36, $_pdfPage->getWidth() - 20, $_pdfPage->getHeight() - 20);
             $_pdfPage->setFont($font, 16);
             $_pdfPage->setFillColor(Zend_Pdf_Color_Html::color('#333333'))->drawText($pageNumber, $_pdfPage->getWidth() / 2, 10);
             $pageNumber++;
             $pdf->pages[] = $_pdfPage;
         }
     }
     $pdfName = $portalId . '_' . time() . '.pdf';
     $path = $this->_rootPath . DS . $pdfName;
     $pdf->save($path);
     return $pdfName;
 }
示例#6
0
 /**
  * Add the token to a pdf page
  *
  * @param \Zend_Pdf_Page $page
  * @param string $tokenId
  */
 protected function addTokenToPage(\Zend_Pdf_Page $page, $tokenId)
 {
     // Set $this->pageFont to false to prevent drawing of tokens on page.
     if ($this->pageFont) {
         $font = \Zend_Pdf_Font::fontWithName($this->pageFont);
         if ($this->pageXfromLeft) {
             $x = $this->pageX;
         } else {
             $x = $page->getWidth() - $this->pageX;
         }
         if ($this->pageYfromTop) {
             $y = $page->getHeight() - $this->pageY;
         } else {
             $y = $this->pageY;
         }
         $page->setFont($font, $this->pageFontSize);
         $page->drawText(strtoupper($tokenId), $x, $y, 'UTF-8');
     }
 }
 public function downloadAction()
 {
     if ($this->_loadValidVoucher()) {
         $voucherCode = $this->getRequest()->getParam('code');
         $text = Mage::helper('voucher');
         $_product = Mage::registry('current_product');
         $pdf = new Zend_Pdf();
         $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER);
         $pageHeight = $page->getHeight();
         $pageWidth = $page->getWidth();
         //$page->rotate(($pageWidth/2), ($pageHeight/2), 1);
         $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
         $logoImage = Zend_Pdf_Image::imageWithPath(Mage::getDesign()->getSkinBaseDir() . '/images/logo_small_en.jpg');
         //$footerImage = Zend_Pdf_Image::imageWithPath(Mage::getDesign()->getSkinBaseDir() . '/images/voucher_footer_en.png'); //VD
         $productImage = Zend_Pdf_Image::imageWithPath(Mage::getBaseDir() . '/media/catalog/product' . $_product->getVoucherImage());
         //$footerImageHeight = $footerImage->getPixelHeight();  //VD
         //$footerImageWidth = $footerImage->getPixelWidth();  //VD
         $logoImageHeight = 75;
         //VDEdit
         $logoImageWidth = 250;
         //VDEdit
         $tableWidth = 568;
         $startPoint = ($pageWidth - $tableWidth) / 2;
         $endPoint = $startPoint + $tableWidth;
         $botPoint = 10;
         $topPoint = $pageHeight - 30;
         $page->setLineWidth('0.3')->setLineDashingPattern(array(3, 3, 3, 3))->drawLine($startPoint, $topPoint, $startPoint, $botPoint)->drawLine($endPoint, $topPoint, $endPoint, $botPoint)->drawLine($startPoint, $topPoint, $endPoint, $topPoint)->drawLine($startPoint, $botPoint, $endPoint, $botPoint)->drawLine($startPoint, $pageHeight - $logoImageHeight - 235, $endPoint, $pageHeight - $logoImageHeight - 235)->drawLine($startPoint, $pageHeight - $logoImageHeight - 235 - 325, $endPoint, $pageHeight - $logoImageHeight - 235 - 325);
         $page->setFillColor(Zend_Pdf_Color_Html::color('#16599D'))->drawRectangle($startPoint + 2, $topPoint - $logoImageHeight - 2, $endPoint, $topPoint);
         $page->drawImage($logoImage, $startPoint, $topPoint - $logoImageHeight - 1, $startPoint + $logoImageWidth, $topPoint);
         //$page->drawImage($footerImage, $startPoint + 2, $botPoint, $startPoint + $footerImageWidth - 20, $botPoint + $footerImageHeight);
         $page->drawImage($productImage, $startPoint + 7, $topPoint - 55 - $productImage->getPixelHeight(), $startPoint + 7 + 246, $topPoint - 55 - $productImage->getPixelHeight() + 165);
         $page->setFillColor(Zend_Pdf_Color_Html::color('#FFFFFF'))->setLineDashingPattern(array(1, 0, 1, 0))->drawRectangle($endPoint - 205, $topPoint - 10, $endPoint - 15, $topPoint + 10)->setLineDashingPattern(array(0, 1000, 0, 1000))->setFillColor(Zend_Pdf_Color_Html::color('#EDF4FA'))->drawRectangle($startPoint + 0.3, $pageHeight - $logoImageHeight - 235, $endPoint, $pageHeight - $logoImageHeight - 235 - 325);
         $style = new Zend_Pdf_Style();
         $style->setFont($font, 15);
         $page->setFont($font, 12)->setFillColor(Zend_Pdf_Color_Html::color('#000000'))->drawText($text->__('Voucher Code: ' . $voucherCode), $endPoint - 193, $topPoint - 4)->setFont($font, 15);
         $lines = explode("\n", $this->getWrappedText($text->__('Voucher for ') . $_product->getName(), $style, 270));
         //var_dump($lines);
         foreach ($lines as $k => $line) {
             $page->drawText($line, $startPoint + $productImage->getPixelWidth() + 20, $topPoint - 70 - $k * 20);
         }
         //
         $pdf->pages[0] = $page;
         $pdf->save(Mage::getBaseDir() . '/media/vouchers/' . $voucherCode . '.pdf');
         $this->getResponse()->clearHeaders()->setHeader('content-type:', 'Application/pdf')->setHeader('Content-Type', 'application/force-download')->setHeader('Content-Disposition', 'attachment; filename="' . $voucherCode . '.pdf"')->setBody($pdf->render());
     }
 }
示例#8
0
 private function background(Zend_Pdf_Page $page, $idEncontro = 0)
 {
     if ($idEncontro > 0) {
         $file = APPLICATION_PATH . "/../public/img/certificados/{$idEncontro}/modelo.jpg";
         if (!file_exists($file)) {
             $file = APPLICATION_PATH . "/../public/img/certificados/default/modelo.jpg";
         }
         if (!file_exists($file)) {
             throw new Exception("É necessário que o arquivo {$file} exista.");
         }
         $height = $page->getHeight();
         $width = $page->getWidth();
         $image = Zend_Pdf_Image::imageWithPath($file);
         $page->drawImage($image, 0, 0, $width, $height);
     }
 }
示例#9
0
 public function getPdfFile()
 {
     $this->_isExport = true;
     $this->_prepareGrid();
     $this->getCollection()->getSelect()->limit();
     $this->getCollection()->setPageSize(0);
     $this->getCollection()->load();
     $this->_afterLoadCollection();
     $pdf = new Zend_Pdf();
     $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
     $page->setFont($font, 12);
     $width = $page->getWidth();
     $i = 20;
     $col = array();
     $header_arr = array();
     foreach ($this->_columns as $column) {
         if ($column->getData('renderer') && $column->getData('renderer') != "") {
             $renderer = $column->getData('renderer');
         } else {
             $renderer = false;
         }
         $col[$column->getIndex()] = array('width' => round($column->getWidth() / 1.2), 'render' => $renderer);
         if (!$column->getIsSystem()) {
             $header = $column->getExportHeader();
             $header_arr[] = array('header' => $header, 'width' => "{$i}");
             //$page->drawText($header, $i, $page->getHeight()-20);
             $i += round($column->getWidth() / 1.2);
         }
     }
     //Mage::log($col);
     $height = $page->getHeight() - 30;
     $j = 0;
     $totl = 0;
     foreach ($this->getCollection() as $coll) {
         $i = 20;
         $data = $coll->getData();
         $sorted = $this->sortArrayByArray($data, $col);
         if ($totl % 20 == 0) {
             $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
             $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
             $page->setFont($font, 12);
             $totl = 0;
             $height = $page->getHeight() - 30;
             $width = $page->getWidth();
             $pdf->pages[] = $page;
             foreach ($header_arr as $header) {
                 $page->drawText($header['header'], $header['width'], $height);
             }
         }
         $height -= 20;
         $totl++;
         foreach ($sorted as $key => $value) {
             if ($col[$key]['render'] != "") {
                 $value = $this->getLayout()->createBlock($col[$key]['render'])->render($coll);
             }
             $page->drawText($value, $i, $height);
             $i += $col[$key]['width'];
         }
         $j++;
         //if($j == 50) break;
     }
     //$pdf->pages[] = $page;
     return $pdf->render();
 }
示例#10
0
文件: custom.php 项目: Tetting/Shorty
		break;
		case 'GivareFadderbarn':
			$subSql = $r[2];
		break;
	}
	$row['TodaysDate'] = date("Y-m-d");
	$row['CustomText'] = str_replace('--EOL--',PHP_EOL,html_entity_decode($_REQUEST['CustomText'],ENT_QUOTES,'ISO-8859-1'));
	$row['PageNo'] = $pageNo;
	//do some injections....
	$pdfPage = new Zend_Pdf_Page($pdf->pages[$templatePage]);
	//bugfix: http://framework.zend.com/issues/browse/ZF-33
	// Rotate the coordinate system 90 degrees clockwise
	//$pdfPage->rotate(0, 0, deg2rad(90));
	// Calculate the x and y offsets to "shift the origin."
	$xOffset = 0;
	$yOffset = $pdfPage->getHeight();

	$textWidth2_20 = 36;
	$textWidth_28 = 20;
	$textWidth_20 = 36;
	$textWidth_16 = 36;
	//$pdf->drawText($pdfPage, "Felix Ongao",$textWidth_28, 46 , -60 ,96);
	//Felix Ongao
	//$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
	$font = Zend_Pdf_Font::fontWithPath($path.'/fonts/arial.ttf'); 

	$pdfPage->setFont($font, 22);
	if (isset($_REQUEST['Type'])) {
		switch($_REQUEST['Type']) {
			case 'Data':
				//print out the data...
示例#11
0
 /**
  * Get height of page ( without margins )
  *
  * @return int Page height
  * @api
  */
 public function getHeight()
 {
     return parent::getHeight() - $this->MARGIN['top'] - $this->MARGIN['bottom'];
 }