2012-11-06 49 views
0

我正在开发一个应用程序,我需要创建PDF文件。使用pdfbundle保存生成PDF到服务器

public function helloAction($id) 
     { 
    $format = $this->get('request')->get('_format'); 
    $venta = $this->getDoctrine()->getRepository('miomioBundle:Venta')->find($id); 
    $lineas = $venta->getLineas(); 
    $cliente = $venta->getCliente(); 
    $empleado = $venta->getEmpleado(); 
    //return new Response ($cliente->getNombre()); 
    $pdf = $this->render(sprintf('miomioBundle:Venta:helloAction.%s.twig', $format), array('cliente' => $cliente,'empleado' => $empleado, 
     'venta' => $venta, 
     'lineas' => $lineas 
     )); 

    $hi = "hiii"; 
    //file_put_contents('holajiji.pdf', $pdf); 
    file_put_contents('hi.txt', $hi); 
    return $pdf; 
     } 

功能正确生成txt文件,但是当我尝试做与PDF相同的I显示了很多其他奇怪的字符。

%PDF-1.4 %���� 1 0 obj <> endobj 2 0 obj <> endobj 3 0 obj <> endobj 4 0 obj [] endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> /XObject <> >> /MediaBox [0 0 595 842 ] /Contents [8 0 R ] /Parent 2 0 R >> endobj 8 0 obj <> stream /F1 9 Tf 0 g 0 G q 0.69 0.878 0.9020000000000000 RG 0.69 0.878 0.9020000000000000 rg 39 586 m 93.25 586 l 93.25 570 l 39 570 l 39 586 l h f Q q 1 0.753 0.796 RG 1 0.753 0.796 rg 447.5 586 m 501.75 586 l 501.75 570 l 447.5 570 l 447.5 586 l h f Q q 0.69 0.878 0.9020000000000000 RG 0.69 0.878 0.9020000000000000 rg 501.75 586 m 556 586 l 556 570 l 501.75 570 l 501.75 586 l h f Q q 0.9020000000000000 0.9020000000000000 0.98 RG 0.9020000000000000 0.9020000000000000 0.98 rg 39 432 m 142.4 432 l 142.4 416 l 39 416 l 39 432 l h f Q q 0.9020000000000000 0.9020000000000000 0.98 RG 

如果开放女巫文本编辑器存档产生:

HTTP/1.0 200 OK 
Cache-Control: no-cache 
Content-Type: text/html; charset=UTF-8 
Date:   Tue, 06 Nov 2012 12:59:43 GMT 

<pdf> 
    <page document-template="holita.pdf"> 
     <img src="/var/www/Symfony/src/mio/mioBundle/Resources/public/images/optinet.png" float="left" height="100px" width="300px" /> 
     <h1 float="right" text-decoration="underline">Factura Número: 4</h1> 
     <p><h1 float="right">Fecha: 06/11/2012 </h1></p> 
     <table text-align="left" margin-bottom="30%"> 
      <tr> 

感谢。

+0

请考虑取消注释掉的代码,因为它什么都不做并可能模糊整体观点。 –

回答

0

尝试的输出头,让浏览器知道你是输出PDF文件:

Header('Content-Type: application/pdf');

+0

不工作:(( – Bicu

0

解决了这个问题巫婆节github上psliwa感谢

+0

请在这里发布解决方案,以避免链接腐烂。 –

相关问题