【问题标题】:Creating pdf in symfony 2.3.*在 symfony 2.3.* 中创建 pdf
【发布时间】:2014-02-28 12:29:59
【问题描述】:

我搜索过在 symfony 2.3 中创建 pdf 文件但没有成功。我有 2 束

  1. Knp snapy bundle 另一个是
  2. psliwa / PHPPdf

我的任务只是点击下载 pdf 文件。为此,我在 html.twig 中给出了链接,例如

<a href="{{path('route name')}}">Download file</a>

在 pdf 操作中,我正在生成 PDF 文件

在我正在做的 knp snapy bundle 中:

$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
    'some'  => $vars
));

return new Response(
    $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )
);

出现错误

退出状态代码“1”表示出了点问题:stderr:“The 系统找不到指定的路径。

如果是,wkpdftohtml 是否需要安装,那么我如何在基于共享的主机上安装。

在 psliwa / PHPdf 我已经阅读了以下示例:

得到了

找不到树枝文件

如果我将 $format = $this-&gt;get('request')-&gt;get('_format'); 更改为 $format='pdf';,那么它会显示简单的 html 文件。
无法理解我应该怎么做才能完成任务...

【问题讨论】:

    标签: php symfony pdf wkhtmltopdf symfony-2.3


    【解决方案1】:

    是的。对于 Knp Snappy Bundle,wkhtmltopdf 是必需的,您需要在 config.yml 中正确配置它

    knp_snappy:
    pdf:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltopdf #path to wkhtmltopdf binary
        options:    []
    

    【讨论】:

    • wkhtmltopdf.org 下载二进制文件到一个文件夹或 bin 文件夹,并在配置文件中给出路径。对于某些功能,您可能需要 xvfb。
    【解决方案2】:

    这是使用 psliwa/PHPPdf 的实时共享主机环境中控制器的摘录:

        $facade = $this->get('ps_pdf.facade');
        $response = new Response();
        $this->render('ManaClientBundle:Contact:roster.html.twig', array(
            'date' => $found['latestDate'],
            'center' => $location,
            'roster' => $found['contactSet'],
                ), $response);
        $date = new \DateTime($found['latestDate']);
        $filename = str_replace(' ', '', $location) . date_format($date, '_Ymd') . '.pdf';
        $xml = $response->getContent();
        $stylesheet = $this->renderView('ManaClientBundle:Contact:contact.xml.twig', array());
        $content = $facade->render($xml, $stylesheet);
        return new Response($content, 200, array
            ('content-type' => 'application/pdf',
            'Content-Disposition' => 'attachment; filename=' . $filename
        ));
    

    【讨论】:

      猜你喜欢
      • 2017-04-29
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 2014-05-13
      • 1970-01-01
      • 2017-04-08
      • 1970-01-01
      相关资源
      最近更新 更多