0

我正在开发一个应用程序,我需要创建 pdf 文件。使用 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;
        }

该函数正确生成 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

如果打开女巫文本编辑器存档生成:

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>

谢谢。

4

2 回答 2

0

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

于 2012-11-06T13:44:28.637 回答
0

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

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

于 2012-11-06T13:06:27.497 回答