wucdbm/pdf-generator-bundle

基于WKHTMLTOPDF的PDF生成器

安装: 331

依赖关系: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v0.2.0 2018-01-11 10:32 UTC

This package is auto-updated.

Last update: 2024-09-16 08:33:44 UTC


README

基于 wkhtmltopdf 的PDF生成器Bundle

要求

  • 需要在您的服务器上安装 xvfb(在 Debian/Ubuntu 上使用 apt-get install xvfb

默认情况下,此Bundle使用 h4cc/wkhtmltopdf-i386 包的二进制文件。要使用您的系统二进制文件,请在您的 parameters.yml.dist 文件中添加以下内容,并执行 composer install

    wucdbm_pdf_generator.binary: wkhtmltopdf

在您的 AppKernel 中注册此Bundle

<?php
public function registerBundles() {
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        // Add WucdbmPdfGeneratorBundle to your AppKernel
        new \Wucdbm\Bundle\PdfGeneratorBundle\WucdbmPdfGeneratorBundle(),
    ];
}

基本用法

<?php 
/** @var \Wucdbm\Bundle\PdfGeneratorBundle\Generator\PdfGenerator $generator */
$generator = $container->get('wucdbm_pdf_generator.generator');
$filename = 'someFile.pdf';
// Get a PdfResult. The wkPrint and bootstrap methods both return a PdfResult
/** @var \Wucdbm\Bundle\PdfGeneratorBundle\Generator\PdfResult $result */
$result = $generator->wkPrint($html);
// The PdfResult is the result of the PDF generation. It has access to the temporary PDF file
$tempPdfPath = $result->realPath();
// return a Symfony Response
return $generator->bootstrap($html)->response($filename);
// return a Symfony Response and copy the file some place else
// The Generator does NOT save the files; it will unlink them as soon as the request is finished
// The copy() method returns PrintResult
return $generator->bootstrap($html)->copy('/some/location/someFile.pdf')->response($filename);
// And last, you can also get the PDF file contents as string
$contents = $generator->bootstrap($html)->contents();

待办事项