Symfony2 PDF Generator Bundle

时间:2013-10-11 12:36:01

标签: symfony pdf

我正在寻找一个易于使用且不需要wkhtmltopdf的PDF生成器捆绑包,因为我的共享托管服务器不支持此功能。

我已经尝试了https://github.com/psliwa/PdfBundle,但如果我按照文档操作,我只是在屏幕上得到回复(没有生成PDF)。虽然有in this question的解决方案,但这个解决方案似乎过于复杂。

我还查看了ioalessio/IoTcpdfBundle,它似乎很容易使用,但没有安装作曲家,我的网络服务器也不支持供应商安装。

我也尝试了stedekay/SpraedPDFGeneratorBundle,但这只是一些错误,抱怨没有找到Java。

虽然whiteoctober/WhiteOctoberTCPDFBundle可能能够工作,但这只会创建一个TCPDF对象,必须进一步处理该文档并且文档不是很有用。

非常感谢任何建议(或关于如何使任何提到的捆绑包工作的建议)。

6 个答案:

答案 0 :(得分:4)

我使用SpraedPDFGeneratorBundle并使用Composer从https://github.com/stedekay/SpraedPDFGeneratorBundle安装它以激活它。我在AppKernel new Spraed\PDFGeneratorBundle\SpraedPDFGeneratorBundle()

中激活了

最后我执行了命令php composer.phar update,并在我的控制器中输入了这段代码:

 $html = $this->renderView('MyappJournalBundle:Default:index1.html.twig');
    $pdfGenerator = $this->get('spraed.pdf.generator');

    return new Response($pdfGenerator->generatePDF($html),
                    200,
                    array(
                        'Content-Type' => 'application/pdf',
                        'Content-Disposition' => 'inline; filename="out.pdf"'
                    )
    );

它对我有用!

答案 1 :(得分:3)

我绝对可以推荐使用twig模板KnpSnappyBundle

我已经多次在生产中使用过库/包,并且没有遇到太多麻烦。

(当时遗留应用程序中与tcpdf& dompdf相比)。

示例用法:

$this->get('knp_snappy.pdf')->generateFromHtml(
    $this->renderView(
        'MyBundle:Foo:bar.html.twig',
        array(
            'some'  => $vars
        )
    ),
    '/path/to/the/file.pdf'
);

答案 2 :(得分:1)

我是SpraedPDFGeneratorBundle的开发人员。我的捆绑包使用Java库,因此您需要在服务器上运行JRE(6或更高版本)。

答案 3 :(得分:1)

如果您想在Symfony3上安装SpraedPDFGeneratorBundle,请确保该服务为:

$('#id_of_an_element').find('*').removeAttr('title');

这在文档中很深入,但很难找到。

你可以意识到的另一件事是发电机使用" The Flying Sauser"使用一种特殊的CSS。所以通过阅读这个,在http://flyingsaucerproject.github.io/flyingsaucer/r8/guide/users-guide-R8.html#xil_36,我发现我必须使用: @page {margin:0 0.5cm;尺寸:21cm 26.5cm; } 证明文件中的边距是合理的。

答案 4 :(得分:0)

您可以使用EnseparHtml2pdfBundle。 看here了解更多详情

答案 5 :(得分:0)

您可以尝试此捆绑包。 MpdfPortBundle。 https://github.com/tasmanianfox/MpdfPortBundle