我想在后端/管理员的产品列表的magento中创建一个pdf。 我不知道怎么做,我在互联网上找到的东西也没那么有用。 希望有人可以帮助我。
克
修改的
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);
}
这是我的控制器
答案 0 :(得分:10)
请注意:
我将指导您向客户添加PDF导出功能(默认情况下有CSV和Excel)
编辑 app / code / core / Mage / Adminhtml / Block / Widget / Grid.php ,添加以下功能
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();
}
编辑 app / code / core / Mage / Adminhtml / controllers / CustomerController.php ,添加以下功能
public function exportPdfAction(){
$fileName = 'customers.pdf';
$content = $this->getLayout()->createBlock('adminhtml/customer_grid')->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
修改 app / code / core / Mage / Adminhtml / Block / Customer / Grid.php ,找到
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
添加PDF导出
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
$this->addExportType('*/*/exportPdf', Mage::helper('customer')->__('PDF'));
现在刷新管理员,您可以将客户导出为PDF。