protected function createHeader(\Zend_Pdf_Page $page) { $filename = APPLICATION_PATH . "/../public/images/invoice-logo.png"; $image = new \Zend_Pdf_Resource_Image_Png($filename); $page->drawImage($image, 30, 533, 210, 560); $this->createSeller($page); }
protected function drawDatamatrix($object) { $matrixItem = $object->getItem(); $x = 214 / 2; // barcode center $y = 214 / 2; // barcode center $height = 40; // barcode height in 1D ; module size in 2D $width = 40; // barcode height in 1D ; not use in 2D // datamatrix creator expects iso 8859-1 code $code = str_replace("?", "|", $this->utf8ToIso88591($object->getValue())); $type = 'datamatrix'; $im = imagecreatetruecolor(214, 214); $black = ImageColorAllocate($im, 0x0, 0x0, 0x0); $white = ImageColorAllocate($im, 0xff, 0xff, 0xff); imagefilledrectangle($im, 0, 0, 214, 214, $white); $data = $matrixItem::gd($im, $black, $x, $y, 0, $type, array('code' => $code)); ob_start(); imagepng($im); $imagestring = ob_get_contents(); ob_end_clean(); imagedestroy($im); $temp = tempnam(sys_get_temp_dir(), 'DMX'); //tmpfile(); $handle = fopen($temp, 'w+b'); fwrite($handle, $imagestring); fseek($handle, 0); $image = new Zend_Pdf_Resource_Image_Png($temp); fclose($handle); //statt drawImage($image, $x1, $y1, $x2, $y2) nun drawImage($image, $x1, $y2, $x2, $y1) $this->page->drawImage($image, $this->coordX($this->mmToPts($object->getPosx())), $this->coordY($this->mmToPts($object->getPosy() + $matrixItem->getDimension())), $this->coordX($this->mmToPts($object->getPosx() + $matrixItem->getDimension())), $this->coordY($this->mmToPts($object->getPosy()))); }
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; }
/** * Add Piece Id Barcode * * @param string $dataIdentifier * @param string $licensePlate * @param string $barCode * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder * @throws InvalidArgumentException * @throws Zend_Pdf_Exception */ public function addPieceIdBarcode($dataIdentifier, $licensePlate, $barCode) { $this->_page->saveGS(); if (!strlen($barCode)) { throw new InvalidArgumentException(Mage::helper('usa')->__('Piece Id barcode is missing')); } $image = new Zend_Pdf_Resource_Image_Png('data://image/png;base64,' . $barCode); $this->_page->drawImage($image, $this->_x(29), $this->_y(476), $this->_x(261), $this->_y(555)); $this->_page->setFont($this->_fontNormal, 9); $routingText = '(' . $dataIdentifier . ')' . $licensePlate; $this->_page->drawText($routingText, $this->_x(144), $this->_y(563), '', Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page::ALIGN_CENTER); $this->_page->restoreGS(); return $this; }
/** * 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; }
/** * Insert logo to pdf page * * @param Zend_Pdf_Page $page * @param null $store */ protected function insertLogo(&$page, $store = null) { $this->y = $this->y ? $this->y : 815; $image = Mage::getStoreConfig('sales/identity/logo', $store); if ($image) { $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image; if (is_file($image)) { $image = Zend_Pdf_Image::imageWithPath($image); $top = 830; //top border of the page $widthLimit = 270; //half of the page width $heightLimit = 270; //assuming the image is not a "skyscraper" $width = $image->getPixelWidth(); $height = $image->getPixelHeight(); //preserving aspect ratio (proportions) $ratio = $width / $height; if ($ratio > 1 && $width > $widthLimit) { $width = $widthLimit; $height = $width / $ratio; } elseif ($ratio < 1 && $height > $heightLimit) { $height = $heightLimit; $width = $height * $ratio; } elseif ($ratio == 1 && $height > $heightLimit) { $height = $heightLimit; $width = $widthLimit; } $y1 = $top - $height; $y2 = $top; $x1 = 25; $x2 = $x1 + $width; //coordinates after transformation are rounded by Zend $page->drawImage($image, $x1, $y1, $x2, $y2); $this->y = $y1 - 10; } } }
/** * * @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); } }
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()); } }
/** * Insert logo to PDF object * * @param Zend_Pdf_Page $page * @param null $store */ protected function insertLogo(&$page, $store = null) { $this->y = $this->y ? $this->y : 815; $image = Mage::getStoreConfig('sales/identity/logo', $store); $collection = Mage::getModel('marketplace/userprofile')->getCollection()->addFieldToFilter('mageuserid', array('eq' => Mage::getSingleton('customer/session')->getCustomerId())); foreach ($collection as $row) { $image = $row->getLogopic(); } if ($image) { $image = Mage::getBaseDir('media') . '/avatar/' . $image; if (is_file($image)) { $extension = pathinfo($image, PATHINFO_EXTENSION); $extension_allowed = array("jpeg", "tiff", "png"); if (in_array($extension, $extension_allowed)) { $image = Zend_Pdf_Image::imageWithPath($image); $top = 830; //top border of the page $widthLimit = 270; //half of the page width $heightLimit = 270; //assuming the image is not a "skyscraper" $width = $image->getPixelWidth(); $height = $image->getPixelHeight(); //preserving aspect ratio (proportions) $ratio = $width / $height; if ($ratio > 1 && $width > $widthLimit) { $width = $widthLimit; $height = $width / $ratio; } elseif ($ratio < 1 && $height > $heightLimit) { $height = $heightLimit; $width = $height * $ratio; } elseif ($ratio == 1 && $height > $heightLimit) { $height = $heightLimit; $width = $widthLimit; } $y1 = $top - $height; $y2 = $top; $x1 = 25; $x2 = $x1 + $width; //coordinates after transformation are rounded by Zend $page->drawImage($image, $x1, $y1, $x2, $y2); $this->y = $y1 - 10; } } } }
function pdfdisplayAction() { $convertdate = new App_Model_dateConvertor(); // echo '<pre>'; print_r($this->_request->getParam('accNum')); $this->view->details = $this->view->loanModel->searchaccounts($this->_request->getParam('accNum')); //echo '<pre>'; print_r($this->view->details); $this->view->tran = $this->view->loanModel->loanInstalments($this->_request->getParam('accNum')); $this->view->paid = $this->view->loanModel->paid($this->_request->getParam('accNum')); $this->view->unpaid = $this->view->loanModel->unpaid($this->_request->getParam('accNum')); // $loansearch = new Loandetailsg_Form_Search(); // $loantransactions = new Loandisbursmentg_Model_loan(); $app = $this->view->baseUrl(); $word = explode('/', $app); $projname = $word[1]; $pdf = new Zend_Pdf(); $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); $page->drawImage($image, 30, 770, 130, 820); $page->setLineWidth(1)->drawLine(25, 25, 570, 25); //bottom horizontal $page->setLineWidth(1)->drawLine(25, 25, 25, 820); //left vertical $page->setLineWidth(1)->drawLine(570, 25, 570, 820); //right vertical $page->setLineWidth(1)->drawLine(570, 820, 25, 820); //top horizontal $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 8); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $page->drawText('( LOAN LEDGER )', 237, 780); $text = array("Member details"); $x0 = 50; $x3 = 310; $x1 = 150; $x2 = 220; $page->drawLine(50, 740, 290, 740); $page->drawLine(50, 720, 290, 720); $page->drawText($text[0], 90, 727); $y1 = 700; foreach ($this->view->details as $details) { $page->drawText('Name : ' . $details->name, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Branch : ' . $details->officename, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Code : ' . $details->code, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Account code : ' . $details->number, $x0, $y1); $text1 = array("Loan details"); $y1 = $y1 - 25; $page->drawLine(50, $y1, 290, $y1); $y1 = $y1 - 20; $page->drawLine(50, $y1, 290, $y1); $y1 = $y1 + 7; $page->drawText($text1[0], 90, $y1); $y1 = $y1 - 25; $page->drawText('Loan name : ' . $details->loanname, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Loan amount Rs : ' . $details->amount, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Interest rate % : ' . $details->interest, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Installments : ' . $details->installments, $x0, $y1); $y1 = $y1 - 20; $page->drawText('Sanctioned date : ' . $details->sanctioned, $x0, $y1); $y1 = $y1 - 20; } $y1 = 740; $text2 = array("Installment status No Amount"); $page->drawLine(310, $y1, 550, $y1); $y1 = $y1 - 20; $page->drawLine(310, $y1, 550, $y1); $y1 = $y1 + 7; $page->drawText($text2[0], $x3, $y1); foreach ($this->view->paid as $paid) { $y1 = $y1 - 25; $page->drawText('Paid' . $paid->paidAmt, 320, $y1); $page->drawText($paid->paidCount, 390, $y1); } foreach ($this->view->unpaid as $unpaid) { $y1 = $y1 - 20; $page->drawText('Due', 320, $y1); $page->drawText($unpaid->unpaidCount, 390, $y1); $page->drawText($unpaid->unpaidAmt, 430, $y1); } $y1 = 480; $text3 = array("GL.LF no Transaction date Creidt Debit Payment mode Transacted by "); $page->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 20; $page->drawLine(50, $y1, 550, $y1); $y1 = $y1 + 7; $page->drawText($text3[0], $x0, $y1); foreach ($this->view->tran as $transaction) { $y1 = $y1 - 20; $page->drawText($transaction->id, 60, $y1); $page->drawText($transaction->date, 120, $y1); $page->drawText($transaction->cr, 160, $y1); $page->drawText($transaction->dt, 250, $y1); $page->drawText($transaction->mode, 330, $y1); $page->drawText($transaction->name, 420, $y1); $y1 = $y1 - 5; $page->drawLine(50, $y1, 550, $y1); } $pdf->pages[] = $page; $pdfData = $pdf->render(); $pdf->save('/var/www/' . $projname . '/reports/loanledger.pdf'); $path = '/var/www/' . $projname . '/reports/loanledger.pdf'; chmod($path, 0777); }
function pdfdisplayAction() { $declarationform = new Externalloan_Model_Dec(); $this->view->form = $declarationform; $postdata = $this->_request->getpost(); //echo '<pre>'; print_r($postdata); $this->view->membercode = $memcode = $postdata['membercode']; //echo $this->view->membercode.'<br>'; $this->view->moduleid = $moduleid = $postdata['module_id']; $this->view->groupresult = $results = $this->view->dbobj->groupDeatils($memcode, $moduleid); $this->view->groupmember = $membername = $this->view->dbobj->getmember($memcode); $this->view->represent = $repname = $this->view->dbobj->represent($memcode); $this->view->loans = $loans = $this->view->dbobj->getgrouploans($memcode); $app = $this->view->baseUrl(); $word = explode('/', $app); $projname = $word[1]; $pdf = new Zend_Pdf(); $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); //$page->drawImage($image, 25, 770, 570, 820); $page->drawImage($image, 30, 770, 130, 820); $page->setLineWidth(1)->drawLine(25, 25, 570, 25); //bottom horizontal $page->setLineWidth(1)->drawLine(25, 25, 25, 820); //left vertical $page->setLineWidth(1)->drawLine(570, 25, 570, 820); //right vertical $page->setLineWidth(1)->drawLine(570, 820, 25, 820); //top horizonta // define font resource $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); $x1 = 72; $x2 = 410; $y1 = 670; //$y2=; $memcode = $this->_request->getParam('membercode'); $moduleid = $this->_request->getParam('module_id'); // echo '<pre>'; print_r($this->view->groupresult); $dateconvert = new App_Model_dateConvertor(); foreach ($this->view->groupresult as $result) { foreach ($this->view->represent as $name) { foreach ($this->view->groupmember as $memberview) { // write text to page $page->setFont($font, 10)->drawText('( EXTERNAL LOAN REQUEST )', 237, 720); $page->setFont($font, 9)->drawText('Group name :' . $result['name'] . '', $x1, $y1); $page->setFont($font, 9)->drawText('Date :' . date('d-m-Y') . '', $x2, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('Group Address :' . $result['address1'] . '', $x1, $y1); $page->setFont($font, 9)->drawText('Group code :' . $result['groupcode'] . '', $x2, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('' . $result['city'] . '', 137, $y1); $page->setFont($font, 9)->drawText('Savings A/c :' . $result['account_number'] . '', $x2, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('' . $result['state'] . '', 137, $y1); foreach ($this->view->loans as $loan) { $page->setFont($font, 9)->drawText('Loan A/c :' . $loan['loanaccount'] . '', $x2, $y1); } // // $y1=$y1-15; // // $page->setFont($font, 9) // // ->drawText('Communication:phone/mobile :'.$loan['mobile'].'',$x1, $y1); $y1 = $y1 - 10; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 25; $page->setFont($font, 9)->drawText('1...' . $result['purpose'] . '...(PURPOSE)sfjhkjh kjhjhjdhfjn dhfjkasdhfjh..' . $result['bankname'] . '..(BANK)afd/saa/sdb', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('..' . $result['branchname'] . '..(Branch name) asdbnhhjh saoinm (LOAN AMOUNT)..' . $result['amount'] . '...ajjnsabvcui uwepiyqwne bodaftutguy nhgqwe.', $x1, $y1); $y1 = $y1 - 20; $page->setFont($font, 9)->drawText('2. aujhhjuoer uiuhjn jhsfduio uyhuasmuiohjos iuiowsmhns8u ujmnasusm sjuhm,asdfiu ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('1) ' . $name['memnames'] . '', 150, $y1); $y1 = $y1 - 25; $page->setFont($font, 9)->drawText('aujhhjuoer uiuhjn jhsfduio uyhuasmuiohjos iuiowsmhns8u ujmnasusm sjuhm,asdfiu ', $x1, $y1); $y1 = $y1 - 15; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('S.No', 80, $y1); $page->setFont($font, 9)->drawText('Member Name', 150, $y1); $page->setFont($font, 9)->drawText('Purpose', 270, $y1); $page->setFont($font, 9)->drawText('Loan request', 360, $y1); $page->setFont($font, 9)->drawText('Signature', 450, $y1); $y1 = $y1 - 10; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('' . $memberview['memname'] . '', 150, $y1); $page->setFont($font, 9)->drawText('' . $memberview['purposename'] . '', 260, $y1); $page->setFont($font, 9)->drawText('' . $memberview['Amount'] . '', 365, $y1); $y1 = $y1 - 10; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 50; $pdf->pages[] = $page; $pdfData = $pdf->render(); $pdfData = $pdf->render(); $pdf->save('/var/www/' . $projname . '/reports/externalloan.pdf'); $path = '/var/www/' . $projname . '/reports/externalloan.pdf'; chmod($path, 0777); } } } }
function pdfdisplayAction() { $app = $this->view->baseUrl(); $word = explode('/', $app); $projname = $word[1]; $pdf = new Zend_Pdf(); $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); //$page->drawImage($image, 25, 770, 570, 820); $page->drawImage($image, 30, 770, 130, 820); $page->setLineWidth(1)->drawLine(25, 25, 570, 25); //bottom horizontal // $page->setLineWidth(1)->drawLine(25, 640, 25, 500); $page->setLineWidth(1)->drawLine(25, 25, 25, 820); //left vertical $page->setLineWidth(1)->drawLine(570, 25, 570, 820); //right vertical $page->setLineWidth(1)->drawLine(570, 820, 25, 820); //top horizonta // define font resource $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); $x1 = 72; $x2 = 410; $y1 = 690; $Declaration = new Declaration_Model_Dec(); $code = $this->_request->getParam('groupcode'); $this->view->result = $this->view->loan->groupDeatils($code); $this->view->groupmembers = $this->view->loan->getgroupmembers($code); $dateconvert = new App_Model_dateConvertor(); foreach ($this->view->result as $result) { // // write text to page $page->setFont($font, 12)->drawText('Group bye law', 240, 720); $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimulate local development by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimulate local development by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimulate local development by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimulate ' . $result['dayname'] . 'The vision of Ourbank is to stimulate ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to ' . $result['place'] . ' stimulate local development by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimulate ' . $result['saving_perweek'] . ' pment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimu ' . $result['rateinterest'] . ' velopment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stim ' . $result['penalty_latecoming'] . ' evelopment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stim ' . $result['penalty_notcoming'] . ' velopment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to st ' . $result['group_created_date'] . ' elopment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('The vision of Ourbank is to stimu ' . $result['name'] . ' elopment by offering small and medium ', $x1, $y1); $y1 = $y1 - 15; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('Member name', 72, $y1); $page->setFont($font, 9)->drawText('UID', 160, $y1); $page->setFont($font, 9)->drawText('Father name', 200, $y1); $page->setFont($font, 9)->drawText('Nominee', 280, $y1); $page->setFont($font, 9)->drawText('Nominee relationship', 350, $y1); $page->setFont($font, 9)->drawText('Signature', 460, $y1); $y1 = $y1 - 10; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); foreach ($this->view->groupmembers as $member) { $y1 = $y1 - 15; $page->setFont($font, 9)->drawText('' . $member['membername'] . '', 72, $y1); $page->setFont($font, 9)->drawText('' . $member['uid'] . '', 140, $y1); $page->setFont($font, 9)->drawText('' . $member['family_id'] . '', 200, $y1); $y1 = $y1 - 10; $page->setLineWidth(1)->drawLine(50, $y1, 550, $y1); } } $pdf->pages[] = $page; $pdfData = $pdf->render(); $pdfData = $pdf->render(); $pdf->save('/var/www/' . $projname . '/reports/grouplaw.pdf'); $path = '/var/www/' . $projname . '/reports/grouplaw.pdf'; chmod($path, 0777); // $this->_redirect('/declaration/index'); }
private function assinaturas(Zend_Pdf_Page $page, $idEncontro = 0) { if ($idEncontro > 0) { $dir = APPLICATION_PATH . "/../public/img/certificados/{$idEncontro}/"; if (!is_dir($dir)) { $dir = APPLICATION_PATH . "/../public/img/certificados/default/"; } } if (!is_dir($dir)) { throw new Exception("É necessário que o diretório {$dir} exista."); } $file = "{$dir}/assinatura-%d.png"; $maxAssinaturas = 3; for ($index = 0; $index < $maxAssinaturas; $index++) { $auxFile = sprintf($file, $index + 1); if (file_exists($auxFile)) { $image = Zend_Pdf_Image::imageWithPath($auxFile); $page->drawImage($image, Sige_Pdf_Certificado::POS_X1_INI_ASSINATURA + $index * Sige_Pdf_Certificado::DES_X, Sige_Pdf_Certificado::POS_Y1_ASSINATURA, Sige_Pdf_Certificado::POS_X2_INI_ASSINATURA + $index * Sige_Pdf_Certificado::DES_X, Sige_Pdf_Certificado::POS_Y2_ASSINATURA); } } }
protected static function DrawHeader(Zend_Pdf_Page $objPage) { $intY = STEWARDSHIP_TOP - 5 / 8 * 72; $intY -= 13.2; $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 12); $objPage->drawText(STEWARDSHIP_STATEMENT_LINE_1, 36, $intY, 'UTF-8'); $intY -= 9.199999999999999; $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 8); $objPage->drawText(STEWARDSHIP_STATEMENT_LINE_2, 36, $intY, 'UTF-8'); $intY -= 12.1; $objPage->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 11); $objPage->drawText(STEWARDSHIP_STATEMENT_LINE_3, 36, $intY, 'UTF-8'); $intY -= 12.1; $objPage->drawText(STEWARDSHIP_STATEMENT_LINE_4, 36, $intY, 'UTF-8'); if (!self::$ZendImage) { self::$ZendImage = Zend_Pdf_Image::imageWithPath(__DOCROOT__ . __IMAGE_ASSETS__ . '/alcf_logo_stewardship.png'); } $objPage->drawImage(self::$ZendImage, 424, STEWARDSHIP_TOP - 108, 576, STEWARDSHIP_TOP - 36); }
/** * Create Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats. * * @param string $imageString * @return Zend_Pdf_Page|bool */ public function createPdfPageFromImageString($imageString) { $image = imagecreatefromstring($imageString); if (!$image) { return false; } $xSize = imagesx($image); $ySize = imagesy($image); $page = new Zend_Pdf_Page($xSize, $ySize); imageinterlace($image, 0); $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_' . uniqid(mt_rand()) . time() . '.png'; imagepng($image, $tmpFileName); $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($pdfImage, 0, 0, $xSize, $ySize); unlink($tmpFileName); return $page; }
/** * inserts the logo from complete left to right * * @param Zend_Pdf_Page $page * @param mixed $store * * @todo merge _insertLogoPositioned and _insertLogoFullWidth */ protected function _insertLogoFullWidth(&$page, $store = null) { $maxwidth = 594; $maxheight = 300; $image = Mage::getStoreConfig('sales/identity/logo', $store); if ($image and file_exists(Mage::getBaseDir('media', $store) . '/sales/store/logo/' . $image)) { $image = Mage::getBaseDir('media', $store) . '/sales/store/logo/' . $image; list($width, $height) = Mage::helper('firegento_pdf')->getScaledImageSize($image, $maxwidth, $maxheight); if (is_file($image)) { $image = Zend_Pdf_Image::imageWithPath($image); $logoPosition = Mage::getStoreConfig('sales_pdf/firegento_pdf/logo_position', $store); switch ($logoPosition) { case 'center': $startLogoAt = $this->margin['left'] + ($this->margin['right'] - $this->margin['left']) / 2 - $width / 2; break; case 'right': $startLogoAt = $this->margin['right'] - $width; break; default: $startLogoAt = 0; } $position['x1'] = $startLogoAt; $position['y1'] = 663; $position['x2'] = $position['x1'] + $width; $position['y2'] = $position['y1'] + $height; $page->drawImage($image, $position['x1'], $position['y1'], $position['x2'], $position['y2']); $this->_marginTop = $height - 130; } } }
/** * Insert logo2 to pdf page * * @param Zend_Pdf_Page $page * @param null $store */ protected function insertLogo3(&$page, $store = null) { $eye_logo_image = Mage::getStoreConfig('estoreiq_options/messages/estoreiq_logo3'); $image = Mage::getBaseDir('media') . '/estoreiq-logo/' . $eye_logo_image; if ($eye_logo_image) { if (is_file($image)) { $image = Zend_Pdf_Image::imageWithPath($image); $top = 75; //top border of the page $widthLimit = 120; //half of the page width $heightLimit = 20; //assuming the image is not a "skyscraper" $width = $image->getPixelWidth(); $height = $image->getPixelHeight(); //preserving aspect ratio (proportions) $ratio = $width / $height; if ($ratio > 1 && $width > $widthLimit) { $width = $widthLimit; $height = $width / $ratio; } elseif ($ratio < 1 && $height > $heightLimit) { $height = $heightLimit; $width = $height * $ratio; } elseif ($ratio == 1 && $height > $heightLimit) { $height = $heightLimit; $width = $widthLimit; } $y1 = $top - $height; $y2 = $top; $x1 = 25; $x2 = $x1 + $width; //coordinates after transformation are rounded by Zend $page->drawImage($image, $x1, $y1, $x2, $y2); } } }
/** * Draw one label section for one item on the PDF document. * * @param int $column Horizontal index on the current page * @param int $row Vertical index on the current page * @param Item $item The item to report on */ private function _drawItemLabel(Zend_Pdf_Page $page, $column, $row, $item) { // Start at the bottom left corner and count over for columns and down // for rows. $originX = self::MARGIN_LEFT + $column * (self::LABEL_WIDTH + self::HORIZONTAL_SPACING); $originY = self::PAGE_HEIGHT - self::MARGIN_TOP - ($row + 1) * (self::LABEL_HEIGHT + self::VERTICAL_SPACING); $page->saveGS(); // Clip on label boundaries to stop text from running over. $page->clipRectangle($originX, $originY, $originX + self::LABEL_WIDTH, $originY + self::LABEL_HEIGHT); $image = $this->_getQrCode($this->_baseUrl . '/items/show/' . $item->id); $page->drawImage($image, $originX, $originY, $originX + self::LABEL_HEIGHT, $originY + self::LABEL_HEIGHT); $titles = $item->getElementTexts('Dublin Core', 'Title'); if (count($titles) > 0) { $textOriginX = $originX + self::LABEL_HEIGHT; $textOriginY = $originY + 0.8 * self::LABEL_HEIGHT; $cleanTitle = strip_tags(htmlspecialchars_decode($titles[0]->text)); $this->_drawWrappedText($page, $cleanTitle, $textOriginX, $textOriginY, self::LABEL_WIDTH - (self::LABEL_HEIGHT + 4)); } // Remove clipping rectangle $page->restoreGS(); // Release objects after use to keep memory usage down release_object($item); }
private function _setLabelToPage($label, $storeId = NULL) { $image = imagecreatefromstring(file_get_contents($label)); if (!$image) { return false; } $xSize = imagesx($image); $ySize = imagesy($image); /*if (Mage::getStoreConfig('upslabel/printing/printer') == "GIF") {*/ if (Mage::getStoreConfig('upslabel/printing/papersize') != "AC") { if (Mage::getStoreConfig('upslabel/printing/papersize') == "A4") { if ($xSize > 595) { $ySize = $ySize * (595 / $xSize); $xSize = 595; } $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); } else { $page = new Zend_Pdf_Page($xSize, $ySize); } } else { $ySize = Mage::getStoreConfig('upslabel/printing/custom_width') * ($ySize / $xSize); $xSize = Mage::getStoreConfig('upslabel/printing/custom_width'); $page = new Zend_Pdf_Page($xSize, $ySize); } imageinterlace($image, 0); $tmpFileName = sys_get_temp_dir() . DS . 'lbl' . rand(10000, 999999) . '.png'; imagepng($image, $tmpFileName); $image = Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($image, 0, 0, $xSize, $ySize); unlink($tmpFileName); /*}*/ return $page; }
/** * Generate Shipment Label Content for each Waybill * * @param Zend_Pdf_Page $page * @param null $store */ public function getContent(&$page, $store = null, $waybill, $order, $pos) { $image = Mage::getStoreConfig('sales/identity/logo', $store); if ($image) { $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image; if (is_file($image)) { $image = Zend_Pdf_Image::imageWithPath($image); $top = $pos; //top border of the page $widthLimit = 100; //half of the page width $heightLimit = 70; //assuming the image is not a "skyscraper" $width = $image->getPixelWidth(); $height = $image->getPixelHeight(); //preserving aspect ratio (proportions) $ratio = $width / $height; if ($ratio > 1 && $width > $widthLimit) { $width = $widthLimit; $height = $width / $ratio; } elseif ($ratio < 1 && $height > $heightLimit) { $height = $heightLimit; $width = $height * $ratio; } elseif ($ratio == 1 && $height > $heightLimit) { $height = $heightLimit; $width = $widthLimit; } $y1 = $top - $height; $y2 = $top; $x1 = 25; $x2 = $x1 + $width; //coordinates after transformation are rounded by Zend $page->drawImage($image, $x1, $y1, $x2, $y2); // Add Order ID, Date and COD amount $this->_setFontRegular($page, 7); $page->drawText(Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), $x1 + 190, $y1 + 25, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'medium', false), $x1 + 190, $y1 + 15, 'UTF-8'); $codamount = $order->getPayment()->getMethodInstance()->getCode() == 'cashondelivery' ? $order->getGrandTotal() : "00.00"; $page->drawText(Mage::helper('sales')->__('COD Amount ') . $codamount, $x1 + 190, $y1 + 5, 'UTF-8'); // Add Barcode and waybill# //$fontPath = '/var/www/html/magento/barcode-fonts/FRE3OF9X.TTF'; $fontPath = Mage::getBaseDir() . '/media/delhivery/font/FRE3OF9X.TTF'; $page->setFont(Zend_Pdf_Font::fontWithPath($fontPath), 30); $barcodeImage = "*" . $waybill . "*"; $page->drawText($barcodeImage, $x1 + 390, $y1 + 12); $this->_setFontRegular($page, 7); $page->drawText("*", $x1 + 385, $y1 + 15); $page->drawText("*", $x1 + 540, $y1 + 15); $page->drawText("AWB# {$waybill}", $x1 + 420, $y1 + 2); $this->_setFontBold($page, 8); $page->drawText("Ship to:", $x1 + 390, $y1 - 15); $page->drawText("From:", $x1, $y1 - 15); $this->_setFontRegular($page, 7); // Add Shipping Address $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf')); $addressy = $y1 - 25; foreach ($shippingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { $page->drawText(strip_tags(ltrim($part)), $x1 + 390, $addressy, 'UTF-8'); $addressy -= 11; } } } $addressy = $y1 - 25; // Add Store Address foreach (explode("\n", Mage::getStoreConfig('sales/identity/address', $store)) as $value) { if ($value !== '') { $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), $x1, $addressy, 'UTF-8'); $addressy -= 11; } } } $page->drawLine($x1, $pos - 160, $x1 + 550, $pos - 158); } } }
/** * Create Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats. * * @param string $imageString * @return Zend_Pdf_Page|bool */ protected function _createPdfPageFromImageString($imageString) { /** @var Magento_Filesystem $filesystem */ $filesystem = $this->_objectManager->get('Magento_Filesystem'); $image = imagecreatefromstring($imageString); if (!$image) { return false; } $xSize = imagesx($image); $ySize = imagesy($image); $page = new Zend_Pdf_Page($xSize, $ySize); imageinterlace($image, 0); $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_' . uniqid(mt_rand()) . time() . '.png'; imagepng($image, $tmpFileName); $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($pdfImage, 0, 0, $xSize, $ySize); $filesystem->delete($tmpFileName); return $page; }
function pdfgenerationAction() { $declarationform = new Declaration_Form_Account(); $this->view->form = $declarationform; $this->view->membercode = $memcode = $this->_request->getParam('membercode'); if (substr($memcode, 4, 1) == 2 or substr($memcode, 4, 1) == 3) { $this->view->groupresult = $result = $this->view->dbobj->getmembers($memcode); // if ($result) { $declarationform->populate($result[0]); $this->view->groupcode = $groupcode = $result[0]['groupcode']; $this->view->relation = $result = $this->view->dbobj->getrelations($groupcode); } } else { $this->view->result = $result = $this->view->dbobj->getmember($memcode); // if ($result) { $declarationform->populate($result[0]); $this->view->membercode1 = $familyid = $result[0]['family_id']; $this->view->relation = $result = $this->view->dbobj->getrelation($familyid); $dbobj = new Declaration_Model_Dec(); $app = $this->view->baseUrl(); $word = explode('/', $app); $projname = $word[1]; $title1 = "declaration"; $this->view->pageTitle = $title1; $pdf = new Zend_Pdf(); $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); //$page->drawImage($image, 25, 770, 570, 820); $page->drawImage($image, 30, 770, 130, 820); $page->setLineWidth(1)->drawLine(25, 25, 570, 25); //bottom horizontal $page->setLineWidth(1)->drawLine(25, 25, 25, 820); //left vertical $page->setLineWidth(1)->drawLine(570, 25, 570, 820); //right vertical $page->setLineWidth(1)->drawLine(570, 820, 25, 820); //top horizonta // define font resource $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Image $image_name = "/var/www/" . $projname . "/public/images/logo.jpg"; $image = Zend_Pdf_Image::imageWithPath($image_name); $Declaration = new Declaration_Model_Dec(); $memcode = $this->_request->getParam('membercode'); $familyid = $this->_request->getParam('membercode1'); $showgetmember = $Declaration->getmember($memcode); $showgetrelation = $Declaration->getrelation($familyid); $dateconvert = new App_Model_dateConvertor(); foreach ($this->view->result as $result) { } // write text to page $page->setFont($font, 12)->drawText('DECLARATION', 240, 720); // $page->setLineWidth(1)->drawLine(0, 800, 820, 250); $page->setFont($font, 10)->drawText('(TO BE SUBMITTED BY THE BORROWER UNDER SBI JOINT LIABILITY GROUP)', 72, 700); $page->setFont($font, 9)->drawText('I,' . $result['name'] . ' (Name of the borrower), Son of ' . $this->view->relation[0]['fathername'] . '', 72, 670); $page->setFont($font, 9)->drawText('Aged around ' . $result['age'] . ' years,presently residing at ' . $result['street'] . ' do here by', 72, 655); $page->setFont($font, 9)->drawText('Solemnly affirm and sincerely state on Oath as follows:', 72, 625); $page->setFont($font, 9)->drawText('i) I propose to avail a crop loan under SBI JLG scheme against hypothecation of the crop which the loan is to be sanctioned.', 72, 605); $page->setFont($font, 9)->drawText('ii) In this connection, I confirm that and declare that I am land less labourer / share cropper /tenant farmer /oral lessee', 72, 585); $page->setFont($font, 9)->drawText('( Stricke out which ever not applicable ).', 80, 575); $page->setFont($font, 9)->drawText('iii) I hereby declare and confirm furture that the properties mentioned in the schedule to the affidavit is the property which', 72, 555); $page->setFont($font, 9)->drawText('is the subject matter of lease (Oral /written) in my favour for year to year or for period of ' . $dateconvert->normalformat($result['created_date']) . '', 80, 545); $page->setFont($font, 9)->drawText('year as mentioned in the document and the lease is presently in force and Sri ' . $result['landowner_name'] . ' is the lesser and ', 80, 535); $page->setFont($font, 9)->drawText('the owner of the property (a copy of the lease deed is enclosed).', 80, 525); $page->setFont($font, 9)->drawText('iv)I hereby declare and confirm further that I have not committed any default in paying the lease amount to the lesser and', 72, 505); $page->setFont($font, 9)->drawText('have not committed any breach of the terms and conditions of the lease.Moreover,I declare further that there are no', 80, 495); $page->setFont($font, 9)->drawText('arrears of any lease amount.', 80, 485); $page->setFont($font, 9)->drawText('v) I have also not resorted to outside borrowing against security of the present crop which is the subject matter of the bank', 72, 465); $page->setFont($font, 9)->drawText('finance.The crop to be raised is free from the charge/encumbrances.', 80, 455); // add page to document $pdf->pages[] = $page; $pdfData = $pdf->render(); $pdfData = $pdf->render(); $pdf->save('/var/www/' . $projname . '/reports/declaration.pdf'); $path = '/var/www/' . $projname . '/reports/declaration.pdf'; chmod($path, 0777); // $this->_redirect('/declaration/index'); } } }
/** * Create \Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats. * * @param string $imageString * @return \Zend_Pdf_Page|false */ public function createPdfPageFromImageString($imageString) { /** @var \Magento\Framework\Filesystem\Directory\Write $directory */ $directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP); $directory->create(); $image = @imagecreatefromstring($imageString); if (!$image) { return false; } $xSize = imagesx($image); $ySize = imagesy($image); $page = new \Zend_Pdf_Page($xSize, $ySize); imageinterlace($image, 0); $tmpFileName = $directory->getAbsolutePath('shipping_labels_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.png'); imagepng($image, $tmpFileName); $pdfImage = \Zend_Pdf_Image::imageWithPath($tmpFileName); $page->drawImage($pdfImage, 0, 0, $xSize, $ySize); $directory->delete($directory->getRelativePath($tmpFileName)); return $page; }
/** * Insert a claim details into a PDF. * * @param int $claimRefNo * * @return void */ public function populateAndOuputClaimStatusReport($claimRefNo, $agentSchemeNumber) { $claimDataSource = new Datasource_Insurance_KeyHouse_Claim(); $claimData = $claimDataSource->getClaim($claimRefNo, $agentSchemeNumber); $pdf = new Zend_Pdf_WrapText(); // create A4 page $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4); // Add HomeLet logo $xcoord = 15; $ycoord = 780; $image = Zend_Pdf_Image::imageWithPath(APPLICATION_PATH . '/../public/assets/common/images/logo-mid.png'); $page->drawImage($image, $xcoord, $ycoord, $xcoord + $image->getPixelWidth(), $ycoord + $image->getPixelHeight()); // define a style $claimHeaderFont = new Zend_Pdf_Style(); $claimHeaderFont->setFillColor(Zend_Pdf_Color_Html::color('#FF6F1C')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $claimHeaderFont->setFont($font, 14); // define another style $claimContentTitleFont = new Zend_Pdf_Style(); $claimContentTitleFont->setFillColor(Zend_Pdf_Color_Html::color('#0C2F6B')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); $claimContentTitleFont->setFont($font, 10); // define another style $claimContentFont = new Zend_Pdf_Style(); $claimContentFont->setFillColor(Zend_Pdf_Color_Html::color('#0C2F6B')); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); $claimContentFont->setFont($font, 10); // write title text to page $page->setStyle($claimHeaderFont)->drawText('Claim Status Report', 250, 810); // write content text to page $page->setStyle($claimContentTitleFont)->drawText('Claim Number', 15, 700); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimNo'], 200, 700); $page->setStyle($claimContentTitleFont)->drawText('Claim Handler', 15, 680); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimsHandler'], 200, 680); $page->setStyle($claimContentTitleFont)->drawText('Reference Number', 15, 660); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimNo'], 200, 660); $page->setStyle($claimContentTitleFont)->drawText('Start Date', 15, 640); $page->setStyle($claimContentFont)->drawText($claimData[0]['ClaimDate'], 200, 640); $page->setStyle($claimContentTitleFont)->drawText('Date', 35, 590); $page->setStyle($claimContentTitleFont)->drawText('Action', 235, 590); $page->setStyle($claimContentTitleFont)->drawText('Status', 435, 590); // wrap text to avoid overlapping $zendWrapText = new Zend_Pdf_WrapText(); $sectionHeight = 0; $y = 570; for ($i = 0; $i < count($claimData); $i++) { $page->setStyle($claimContentFont)->drawText($claimData[$i]['ClaimDate'], 35, $y); $sectionHeight = $zendWrapText->drawWrappedText($page, 235, $y, $claimData[$i]['Activity'], 150, $claimContentFont); //$page->setStyle($claimContentFont)->drawTextBlock($claimData[$i]['Activitiy'], 235, 570, 200, 200, Zend_Pdf_Page::ALIGN_LEFT); $page->setStyle($claimContentFont)->drawText($claimData[$i]['OpenOrClosed'], 435, $y); $y -= $sectionHeight; } // add page to document $pdf->pages[] = $page; $filename = "claimstatus_" . md5($claimRefNo); // send to browser as download return $pdf->render(); }