如何在magento中创建PDF? [英] How to create a pdf in magento?

查看:76
本文介绍了如何在magento中创建PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后端/管理员的产品列表的magento中创建pdf. 我不知道该怎么做,而且我在互联网上找到的东西也没有帮助. 希望有人能帮助我.

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

编辑

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);
}

这是我的控制器

推荐答案

请注意:

  • 这不是好的方法,因为它会覆盖Magento核心文件,因此您必须在自己的模板中覆盖这些文件.
  • 这不是完整的解决方案,而是使您理解并进一步发展的提示. (这将仅打印标题,不打印数据)
  • This is not the good way to do it, because it overrides Magento core files, you have to override those files within your modeule.
  • This is not a complete solution but a tip to make you understand and go further yourself. (this will print only headers, no data)

我将指导您为客户添加PDF导出功能(默认情况下为CSV和Excel)

I will guide you adding PDF Export feature to customers (by default there is CSV and 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.

Now refresh the admin, you can export customers as PDF.

这篇关于如何在magento中创建PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆