tfox/mpdf-port-bundle

mPDF 类的包装器,允许在 Symfony2 项目中使用 mPDF

安装次数: 491,441

依赖项: 0

建议者: 0

安全: 0

类型:symfony-bundle

2.1.0 2020-12-10 08:27 UTC

README

使用 Composer (Symfony 2.x, Symfony 3.0.x)

  • 运行命令

    composer require tfox/mpdf-port-bundle
    
  • app/AppKernel.php 中添加新行

    $bundles = array(
    ...
    new TFox\MpdfPortBundle\TFoxMpdfPortBundle(),
    )
    

使用 deps 文件 (Symfony 2.0.x)

  • 在您的 deps 文件中添加新条目

    [TFoxMpdfPortBundle]
      git=https://bitbucket.org/tasmanianfox/mpdfportbundle.git
      target=/bundles/TFox/MpdfPortBundle 
    
  • app/AppKernel.php 中添加新行

    new TFox\MpdfPortBundle\TFoxMpdfPortBundle(), 
    
  • app/autoload.php 中添加新行

    'TFox' => DIR.'/../vendor/bundles',
    
  • 运行命令

    php bin/vendors install
    

快速入门指南

如何创建响应对象

此示例创建一个 A4 格式、纵向排列的 PDF 文档

public function indexAction()
{
   return new \TFox\MpdfPortBundle\Response\PDFResponse($this->getMpdfService()->generatePdf('Hello World'));
}

/**

  • @return \TFox\MpdfPortBundle\Service\PDFService */ private function getMpdfService() { return $this->get('t_fox_mpdf_port.pdf'); }

生成包含 PDF 内容的变量

有时需要获取一个内容为 PDF 文档的变量。

$myVar = $this->getMpdfService()->generatePdf('Hello World');

如何获取 \mPDF 类的实例

如果您想使用 mPDF 类本身,可以使用 getMpdf 方法

$mpdf = new \Mpdf\Mpdf();

附加选项

可以通过第二个参数传递附加选项

public function indexAction()
{
    return new \TFox\MpdfPortBundle\Response\PDFResponse($this->getMpdfService()->generatePdf('Hello World', array(
            'format' => 'A4-L' // A4 page, landscape orientation
    )));
}

详细描述可在官方手册页面查看: https://mpdf.github.io/