我必须以 Magento
中的订单的pdf格式导出数据但我收到了这个错误:
致命错误:在1683行的app / code / core / Mage / Adminhtml / Block / Widget / Grid.php中调用未定义的方法Mage_Reports_Model_Resource_Report_Collection :: getSelect()
我的getpdf操作代码
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();
}
我的控制器操作代码是
public function exportPdfAction(){
$fileName = 'daily_orders.pdf';
$content = $this->getLayout()->createBlock('reportneworders/adminhtml_reportneworders_grid')->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
网格在管理中正常工作。
csv和excel数据导出成功,但pdf不能。请帮助我。
答案 0 :(得分:2)
您只打印网格标题的foreach ($this->_columns as $column)
语句。
您还必须遍历项目集合。在$pdf->pages[] = $page;
行之前,添加以下内容:
$j = 40;
foreach ($collection as $item) {
// add code here, which is printing $item information
// Example:
$y = $page->getHeight()-$j;
$page->drawText($item->getincrement_id(), 20, $y);
$page->drawText($item->getcreated_at(), 50, $y);
// etc.
$j += 20;
}
另外,在我自己的代码中,为了使PDF导出响应网格过滤器,我必须将function exportPdfAction()
代码更改为以下内容(否则忽略过滤器):
public function exportPdfAction(){
$fileName = 'daily_orders.pdf';
$grid = $this->getLayout()->createBlock('reportneworders/adminhtml_reportneworders_grid');
$this->_initReportAction($grid);
$content = $grid->getPdfFile();
$this->_prepareDownloadResponse($fileName, $content);
}
如您所见,我添加了$this->_initReportAction($grid);