Put this code in your Controllers file.
How to make custom PDF in magento admin panel
$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
$page->setFont($font, 11);
//add pages to main document
$pdf->pages[] = $page;
$top = $this->y;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
$page->drawRectangle(25, $top, 570, $top - 55);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
//Header order
$titre = "Packingslip # 100000039";
$page->drawText($titre, 40, $page->getHeight()-115, "UTF-8");
$titre = "Order # 100000031";
$page->drawText($titre, 40, $page->getHeight()-130, "UTF-8");
$titre = "Order Date: Aug 20, 2015";
$page->drawText($titre, 40, $page->getHeight()-145, "UTF-8");
//Create rectangle
$top -= 55;
$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, $top, 275, ($top - 25));
$page->drawRectangle(275, $top, 570, ($top - 25));
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(Mage::helper('sales')->__('Sold to:'), 35, ($top - 15), 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Ship to:'), 285, ($top - 15), 'UTF-8');
//Create rectangle
$addressesHeight = 110;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->drawRectangle(25, ($top - 25), 570, $top - 33 - $addressesHeight);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->setFont($font, 10);
$this->y = $top - 40;
$addressesStartY = $this->y;
//Billing Address
$page->drawText(strip_tags(ltrim('Jaydip Kanasagra')), 35, $this->y, 'UTF-8');
$page->drawText(strip_tags(ltrim('Metizsoft')), 35, $this->y-15, 'UTF-8');
$page->drawText(strip_tags(ltrim('35 Brownsboro,')), 35, $this->y-30, 'UTF-8');
$page->drawText(strip_tags(ltrim('Madison,')), 35, $this->y-45, 'UTF-8');
$page->drawText(strip_tags(ltrim('Alabama, 33324')), 35, $this->y-60, 'UTF-8');
$page->drawText(strip_tags(ltrim('United States')), 35, $this->y-75, 'UTF-8');
$page->drawText(strip_tags(ltrim('T: (256) 683 - 0237')), 35, $this->y-90, 'UTF-8');
//Shipping Address
$page->drawText(strip_tags(ltrim('Jaydip Kanasagra')), 285, $this->y, 'UTF-8');
$page->drawText(strip_tags(ltrim('Metizsoft')), 285, $this->y-15, 'UTF-8');
$page->drawText(strip_tags(ltrim('35 Brownsboro,')), 285, $this->y-30, 'UTF-8');
$page->drawText(strip_tags(ltrim('Madison,')), 285, $this->y-45, 'UTF-8');
$page->drawText(strip_tags(ltrim('Alabama, 33324')), 285, $this->y-60, 'UTF-8');
$page->drawText(strip_tags(ltrim('United States')), 285, $this->y-75, 'UTF-8');
$page->drawText(strip_tags(ltrim('T: (256) 683 - 0237')), 285, $this->y-90, 'UTF-8');
$this->y -= 110;
$addressesEndY = $this->y;
$addressesEndY = min($addressesEndY, $this->y);
$this->y = $addressesEndY;
//Create rectangle
$page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 275, $this->y-25);
$page->drawRectangle(275, $this->y, 570, $this->y-25);
//Payment and Shipping Method
$this->y -= 15;
$page->setFont($font, 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y , 'UTF-8');
$this->y -=10;
$page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
$page->setFont($font, 10);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$paymentLeft = 35;
$yPayments = $this->y - 15;
foreach (Mage::helper('core/string')->str_split('Cash On Pickup', 45, true, true) as $_value) {
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
$yPayments -= 15;
}
$yPayments = min($addressesEndY, $yPayments)-60;
$page->drawLine(25, ($top - 150), 25, $yPayments);
$page->drawLine(570, ($top - 150), 570, $yPayments);
$page->drawLine(25, $yPayments, 570, $yPayments);
foreach (Mage::helper('core/string')->str_split('Delivery - Delivery
(Only available for local area)', 45, true, true) as $_value) {
$page->drawText(strip_tags(trim($_value)), 285, $this->y-15, 'UTF-8');
$this->y -= 15;
}
$topMargin = 20;
$methodStartY = $this->y;
$yShipments = $this->y;
$totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " $0.00)";
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$currentY = min($yPayments, $yShipments);
// replacement of Shipments-Payments rectangle block
$page->drawLine(25, $methodStartY, 25, $currentY); //left
$page->drawLine(25, $currentY, 570, $currentY); //bottom
$page->drawLine(570, $currentY, 570, $methodStartY); //right
$this->y = $currentY;
$this->y -= 15;
//Items
$page->setFont($font, 10);
$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, 0, 0));
$page->drawText(Mage::helper('sales')->__('Qty'), 35, $this->y, 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Products'), 125, $this->y , 'UTF-8');
$page->drawText(Mage::helper('sales')->__('Sku'), 550, $this->y , 'UTF-8');
$test = array(0=>'test',1=>'test1',2=>'test2');
$this->y = $this->y-15;
foreach ($test as $_value) {
$this->y -= 15;
$page->drawText(strip_tags(trim('10')), 35, $this->y, 'UTF-8');
$page->drawText(strip_tags(trim('SWISHER SWEET CGRL WGRP 2F.99')), 125, $this->y, 'UTF-8');
$page->drawText(strip_tags(trim('025900227289')), 500, $this->y, 'UTF-8');
}
//generate pdf
$content = $pdf->render();
$fileName = 'details.pdf';
$this->_prepareDownloadResponse($fileName, $content);
No comments:
Post a Comment