简体   繁体   English

保存生成PDF服务器

[英]save generate pdf to server

I am developing an application and I need to create pdf files. 我正在开发应用程序,我需要创建pdf文件。 using pdfbundle 使用pdfbundle

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

The function generates the txt file correctly but when I try to do the same with the pdf I displayed a lot of other odd characters. 该函数正确生成txt文件,但是当我尝试对pdf进行相同操作时,我显示了很多其他奇数字符。

%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

if open witch text editor the archive generate : 如果打开女巫文本编辑器,则存档生成:

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>

thanks. 谢谢。

尝试输出标题,以使浏览器知道您正在输出PDF文件:

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

解决了github psliwa中的女巫部分的问题,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM