I want to create a pdf in magento of the product list in the backend/admin. i don't know how to do it and the things i find on the internet are not that helpfull. Hope somebody can help me.
gr
edit
class Wouterkamphuisdotcom_Web_Adminhtml_WebController extends Mage_Adminhtml_Controller_action {
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('web/items')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
return $this;
}
public function exportPdfAction(){
$fileName = 'customers.pdf';
$content = $this->getLayout()->createBlock('Web/Web_Grid')->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
this is my controller
Please note:
I will guide you adding PDF Export feature to customers (by default there is CSV and Excel)
Edit app/code/core/Mage/Adminhtml/Block/Widget/Grid.php, add the following function
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);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
$page->setFont($font, 12);
$width = $page->getWidth();
$i=0;
foreach ($this->_columns as $column) {
if (!$column->getIsSystem()) {
$i+=10;
$header = $column->getExportHeader();
$page->drawText($header, $i, $page->getHeight()-20);
$width = $font->widthForGlyph($font->glyphNumberForCharacter($header));
$i+=($width/$font->getUnitsPerEm()*12)*strlen($header)+10;
}
}
$pdf->pages[] = $page;
return $pdf->render();
}
Edit app/code/core/Mage/Adminhtml/controllers/CustomerController.php, add the following function
public function exportPdfAction(){
$fileName = 'customers.pdf';
$content = $this->getLayout()->createBlock('adminhtml/customer_grid')->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
Edit app/code/core/Mage/Adminhtml/Block/Customer/Grid.php, locate
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
Add the PDF Export
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
$this->addExportType('*/*/exportPdf', Mage::helper('customer')->__('PDF'));
Now refresh the admin, you can export customers as PDF.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With