samokspv/cakephp-pdf-generator

为任务PDF生成添加页面按钮(从当前URL获取数据,格式为json)

1.0.18 2014-12-12 09:24 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:01:27 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

如果您想在页面上添加按钮以生成PDF,请使用它(从当前URL获取数据,格式为json)

安装

cd my_cake_app/app
git clone git://github.com/samokspv/cakephp-pdf-generator.git Plugin/PdfGenerator

或者如果您使用git将其作为子模块添加

cd my_cake_app
git submodule add "git://github.com/samokspv/cakephp-pdf-generator.git" "app/Plugin/PdfGenerator"

然后在Config/bootstrap.php中添加插件加载

CakePlugin::load('PdfGenerator', array('bootstrap' => true, 'routes' => true));

用法

For example:

You url:
	http://your_domain/documents/view/14210

	http://your_domain/documents/view/14210.json - must return array data in json:
	[
		{
			"field1": "text1",
			"field2": 'text2',
			...
			"fieldN": [
				"text1",
				"text2",
				...
				"textN"
			]
		},
		...
	]

In any place of your view where you need button:
echo $this->element('PdfGenerator.pdf/generate-link');

app/Config/core.php:
Configure::write('PdfGenerator', array(
	'pdf' => array(
		'cacheDir' => WWW_ROOT . 'cache/pdf', // link to pdf file
		'css' => WWW_ROOT . 'css/pdf/pdf.css' // link to css for pdf file
		'log' => LOGS . 'error.log', // link to log file
		'pages' => array(
			array(
				'element' => 'pdf/cover' // first page
			),
			array(
				'element' => 'pdf/documents' // data from http://your_domain/documents/view/14210.json
			)
		) // elements will be included in the pdf file
	)
));
Configure::write('Task', array(
	'timeout' => 60 * 60 * 24 * 5,
	'dateDiffFormat' => "%h hours, %i min, %s sec",
	'processEvents' => array(
		array(
			'model' => 'PdfGenerator.PdfGenerator',
			'key' => 'Task.taskStarted',
			'options' => array()
		),
		array(
			'model' => 'PdfGenerator.PdfGenerator',
			'key' => 'Task.taskUpdated',
			'options' => array()
		),
		array(
			'model' => 'PdfGenerator.PdfGenerator',
			'key' => 'Task.taskStopped',
			'options' => array()
		)
	)
));
Configure::write('App.fullBaseUrl', 'http://your_domain');