seyfer/kohana-mpdf

此软件包的最新版本(dev-3.3/master)没有提供许可证信息。

Kohana模块,用于快速轻松地管理PDF

维护者

详细信息

github.com/seyfer/kohana-mpdf

源代码

安装: 58

依赖者: 0

建议者: 0

安全: 0

星星: 8

观察者: 4

分支: 15

类型:kohana-module

dev-3.3/master 2015-05-11 05:45 UTC

This package is auto-updated.

Last update: 2024-09-26 17:46:55 UTC


README

为Kohana扩展了一个PDF而非HTML。使用MPDF将正常HTML视图渲染为PDF文件。

分支以修复使用Kohana Smarty模块渲染视图的问题。现在增加了新功能,如从字符串读取、合并PDF等。

mPDF版本 5.7.1a !

安装

使用Composer!

要从Packagist安装,请点击链接

"seyfer/kohana-mpdf": "dev-master"

要从Git安装

{
    "type": "package",
    "package": {
        "name": "kohana/modules/mpdf",
        "version": "3.3",
        "source": {
            "type": "git",
            "url": "https://github.com/seyfer/kohana-mpdf.git",
            "reference": "3.3/master"
        }
    }
}

安装后,转到模块文件夹并执行

composer install

这将把mPDF加载到vendor目录。之后,在应用index.php的开头添加

require vendor/autoload.php

配置

编辑application/bootstrap.php并添加模块

Kohana::modules(array(
    ...
    'mpdf' => 'modules/mpdf',
    ...
));

用法

放置在控制器动作中

// Load a view using the PDF extension
$mpdf = Kohana_MPDF::factory('pdf/example');
//Or use it with some data and with Smarty
$mpdf = Kohana_MPDF::factory("pdf/example.tpl", array("data" => $data));

//Set data for wiew later
$mpdf->setData($data);
//Or directly to PDF
$mpdf->setDataToPdf($data);

// Use CSS
$mpdf->setCss('media/css/style.css');
// And again. This is array.
$mpdf->setCss('media/css/style2.css');
//Or set array of CSS path directly to PDF
$mpdf->setCssToPdf($array);

//Render pdf with your html template and css
$mpdf->render();

//Check output with different output mode (see MPDF documentation).
$mpdf->output('mpdf.pdf', 'S');

扩展用法

//You can set some options
$mpdf->setCharset($charset);
$mpdf->setSourceFile($filePath);
$mpdf->setImportUse();
$mpdf->setFormat('A4');

//Save to tmp path
$mpdf->saveTpmPdfFile($data, $name);
//You can load PDF file in one command from tmp path
$mpdf->loadPdfFile($fileName);

//And finally! Parse PDF from string, not file
$mpdf->parsePdfString($pdfBinData);

//Merge different PDF to one
$mpdf = new Kohana_MPDF();
$mpdf->mergePdf(1.pdf);
$mpdf->mergePdf(2.pdf);
$mpdf->output();

你可以调用任何mPDF方法。

有关所有mPDF方法的说明,请参阅http://www.mpdf1.com/文档。