如何在magento中创建pdf?

Wou*_*ter 4 pdf admin magento

我想在后端/ admin中的产品列表的magento中创建一个pdf.我不知道怎么做,我在互联网上找到的东西也没那么有用.希望有人可以帮助我.

GR

编辑

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);
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

ily*_*oli 11

请注意:

  • 这不是一个好方法,因为它覆盖了Magento核心文件,你必须在你的模式中覆盖这些文件.
  • 这不是一个完整的解决方案,而是一个让你理解并自己走得更远的提示.(这将只打印标题,没有数据)

我将指导您向客户添加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();
}
Run Code Online (Sandbox Code Playgroud)

编辑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);
}
Run Code Online (Sandbox Code Playgroud)

编辑app/code/core/Mage/Adminhtml/Block/Customer/Grid.php,找到

    $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
    $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
Run Code Online (Sandbox Code Playgroud)

添加PDF导出

    $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
    $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
    $this->addExportType('*/*/exportPdf', Mage::helper('customer')->__('PDF'));
Run Code Online (Sandbox Code Playgroud)

现在刷新管理员,您可以将客户导出为PDF.