2010-07-19 90 views
1

我有與Zend PDF一個奇怪的問題,我只是不能獲取PDF,以顯示我的行動 我有了這個代碼:無法獲得Zend的pdf顯示在瀏覽器

$this->_helper->layout->disableLayout(); 
$this->_helper->viewRenderer->setNoRender(); 

$pdf = new Zend_Pdf('path/to/file.pdf'); 

$this->getResponse()->setHeader('Content-type', 'application/x-pdf', true); 
$this->getResponse()->setHeader('Content-disposition', 'inline; filename=filetrace.pdf', true); 
$this->getResponse()->setBody($pdf->render()); 

Zend公司創建該堆棧跟蹤:

#0 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Pdf.php(303): Zend_Pdf_Parser->__construct('http://example...', Object(Zend_Pdf_ElementFactory_Proxy), false) 
#1 E:\wwwroot\test\htdocs\application\modules\dashboard\controllers\FileController.php(171): Zend_Pdf->__construct('http://example...') 
#2 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Action.php(513): Dashboard_FileController->showAction() 
#3 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('showAction') 
#4 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#5 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#6 E:\SRVApps\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#7 E:\wwwroot\test\htdocs\public\index.php(26): Zend_Application->run() 
#8 {main} 

當創建一個新的PDF也沒有問題

沒有任何人有一個想法?

感謝

+0

什麼顯示,而不是PDF? – 2010-07-19 19:26:43

+0

應用程序錯誤/內部服務器錯誤 – Peter 2010-07-19 19:42:29

回答

1

方法1:獲取Zend_Pdf外的二進制字符串

$file = file_get_contents('path/to/file.pdf') 
$pdf = new Zend_Pdf($file); 

方法2:設置$load參數true

$pdf = new Zend_Pdf('path/to/file.pdf', null, true); 

方法3:使用靜態load - 方法

$pdf = Zend_Pdf::load('path/to/file.pdf'); 
1

我意識到這是一個老問題,但我通過反覆試驗找到了答案。這就是我的行動看起來只是讓pdf在瀏覽器中顯示。這適用於Chrome。我沒有在任何其他瀏覽器中測試過它。

$this->_helper->viewRenderer->setNoRender(); 
    $this->_helper->layout()->disableLayout(); 
    $this->getResponse() 
     ->setHeader('Content-Disposition', 'inline; filename=foo.pdf') 
     ->setHeader('Content-type', 'application/pdf'); 
    $pdf = Zend_Pdf::load('/path/to/my.pdf'); 
    echo $pdf->render(); 
相關問題