2010-07-19 21 views
1

J'ai un problème étrange avec zend pdf, je ne peux pas obtenir le pdf pour montrer dans mon action, j'ai ce code:ne peut pas obtenir show Zend dans le navigateur

$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 crée cette stacktrace:

#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} 

Lorsque vous créez un nouveau pdf il n'y a pas de problème

est-ce que quelqu'un a une idée?

Merci

+0

Qu'est-ce qui se passe à la place du format PDF? –

+0

Erreur d'application/Erreur interne du serveur – Peter

Répondre

1

Méthode 1: obtenir le train binaire à l'extérieur de Zend_Pdf

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

Méthode 2: définir le paramètre $loadtrue

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

Méthode 3: Utiliser la load statique -method

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

Je me rends compte que c'est une vieille question mais j'ai trouvé la réponse à ceci par l'essai et l'erreur. C'est ce que mon action ressemble à obtenir juste le pdf pour montrer dans le navigateur. Cela fonctionne dans Chrome. Je ne l'ai pas testé dans un autre navigateur.

$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();