chrisandchris/mpdf-port-bundle

此包已被废弃,不再维护。作者建议使用tfox/mpdf-port-bundle包。

增强响应处理的tfox/mpdf-port-bundle版本

安装: 65

依赖: 0

建议者: 0

安全性: 0

星星: 0

关注者: 1

分支: 23

类型:symfony-bundle

1.2.6 2015-04-13 08:01 UTC

This package is auto-updated.

Last update: 2019-09-19 09:37:14 UTC


README

使用Composer(Symfony 2.1+)

  • 在您的composer.json文件中添加新行
"require": {
		...
        
        "tfox/mpdf-port-bundle": "1.2.*"
}
  • 运行命令
php composer.phar update
  • app/AppKernel.php中添加新行
$bundles = array(
  ...
  new ChrisAndChris\MpdfPortBundle\TFoxMpdfPortBundle(),
)

使用deps-file(Symfony 2.0.x)

  • 在您的deps文件中添加新条目
[TFoxMpdfPortBundle]
    git=https://github.com/tasmanianfox/MpdfPortBundle.git
    target=/bundles/TFox/MpdfPortBundle 
  • app/AppKernel.php中添加新行
new ChrisAndChris\MpdfPortBundle\TFoxMpdfPortBundle(),
  • app/autoload.php中添加新行
'TFox' => __DIR__.'/../vendor/bundles',
  • 运行命令
php bin/vendors install

快速入门指南

如何创建Response对象

以下示例创建一个A4格式的纵向PDF文档

$mpdfService = $this->get('tfox.mpdfport');
$html = "Hello World!";
$response = $mpdfService->generatePdfResponse($html);

生成包含PDF内容的变量

有时需要获取一个内容为PDF文档的变量。显然,可以从上一个示例生成响应,然后调用一个方法

$response->getContent()

但有一个更简短的方法来获取原始内容

$mpdfService = $this->get('tfox.mpdfport');
$html = "Hello World!";
$content = $mpdfService->generatePdf($html);

如何获取\mPDF类的实例

如果您想直接与mPDF类交互,可以使用getMpdf方法

$mpdfService = $this->get('tfox.mpdfport');
$mPDF = $mpdfService->getMpdf();

警告

  • 默认情况下,此包将'utf-8'和'A4'两个属性添加到mPDF类构造函数中。要关闭这些选项,请使用setAddDefaultConstructorArgs方法
$mpdfService->setAddDefaultConstructorArgs(false);
  • 由于包默认将前两个参数插入到mPDF构造函数中,因此额外的构造函数参数应从第三个参数(默认字体大小)开始。

  • 如果调用了setAddDefaultConstructorArgs(false)方法,构造函数的额外参数应从第一个参数(模式)开始。

额外参数

由于包使用mPDF类的方法,可以添加一些额外的参数到这些方法中。包中使用了3个mPDF方法

要传递额外的参数,应创建一个包含参数的数组

$arguments = array(
	'constructorArgs' => array(), //Constructor arguments. Numeric array. Don't forget about points 2 and 3 in Warning section!
	'writeHtmlMode' => null, //$mode argument for WriteHTML method
	'writeHtmlInitialise' => null, //$mode argument for WriteHTML method
	'writeHtmlClose' => null, //$close argument for WriteHTML method
	'outputFilename' => null, //$filename argument for Output method
	'outputDest' => null //$dest argument for Output method
);

不需要在数组中包含所有键。此数组可以作为第二个参数传递给generatePdfgeneratePdfResponse方法

$mpdfService->generatePdf($html, $arguments);
$mpdfService->generatePdfResponse($html, $arguments);