jasir/pdf-response

schmutzka/pdf-response 的个人分支 - 已启用 packagist

dev-master 2013-02-05 18:07 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:23:32 UTC


README

  • 发送模板作为 PDF 输出
  • mPDF 需要 - http://www.mpdf1.com/mpdf/download(已测试版本 5.6)
  • 与 Nette 2.0.8 兼容(发布于 2013-01-01)
  • 不支持 JavaScript
  • 良好的 API

默认文件位置

libs/mPDF/
libs/netterobots.txt (prevents from caching all mPDF classes)
libs/PdfResponse.php (anywhere)

使用方法

<?php

use PdfResponse;

class MyPresenter extends Nette\Application\UI\Presenter
{

	public function actionPdf()
	{
		$template = $this->createTemplate()->setFile(APP_DIR . "/templates/myPdf.latte");
		$template->someValue = 123;
		// Tip: In template to make a new page use <pagebreak>

		$pdf = new \PdfResponse($template, $this->presenter);
		$pdf->documentTitle = "costum file name 123";

		// optional
		$pdf->documentTitle = date("Y-m-d") . " My super title"; // creates filename 2012-06-30-my-super-title.pdf
		$pdf->pageFormat = "A4-L"; // wide format
		$pdf->getMPDF()->setFooter("|© www.mysite.com|"); // footer

		// now you have 3 posibilites:

		// 1. render template in browser and terminate, e.g. testing
		$pdf->test();

		// 2. save file to server
		$pdf->save(WWW_DIR . "/generated/"); // as a filename $this->documentTitle will be used
		$pdf->save(WWW_DIR . "/generated/", "another file 123); // OR use a custom name

		// OR in case of mail attachment, returns path to file on server
		$savedFile = $pdf->save(WWW_DIR . "/contracts/"); 
		$mail = new Nette\Mail\Message;
		$mail->addTo("john@doe.com");
		$mail->addAttachment($savedFile);
		$mail->send();

		// 3. send pdf file to output (save/open by user) and terminate
		$pdf->output();
	}

}

?>

更多信息