Skip to content

Commit

Permalink
mPDF dependency is handled by composer & packagist
Browse files Browse the repository at this point in the history
  • Loading branch information
castamir committed Feb 9, 2013
1 parent a36c452 commit 9fe56e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
43 changes: 0 additions & 43 deletions PdfResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
* @property-read mPDFExtended $mPDF
*/
class PdfResponse extends Nette\Object implements Nette\Application\IResponse {
/**
* path to mPDF.php
* @var string
*/
public static $mPDFPath = "/mPDF/mpdf.php";


/**
* Source data
* @var mixed
Expand Down Expand Up @@ -361,10 +354,6 @@ public function getMPDF() {
* @return mPDFExtended
*/
public function createMPDF() {
$mpdfPath = LIBS_DIR . self::$mPDFPath;
define('_MPDF_PATH', dirname($mpdfPath) . "/");
require($mpdfPath);

$margins = $this->getMargins();

// [ float $margin_header , float $margin_footer [, string $orientation ]]]]]])
Expand Down Expand Up @@ -403,35 +392,3 @@ public function save($location, $name = NULL) {
}

}

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);

// 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 2 posibilites:

// 1. 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("[email protected]");
$mail->addAttachment($savedFile);
$mail->send();

// 2. send pdf file to output (save/open by user) and terminate
$this->sendResponse($pdf);
}
}
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "castamir/pdf-response",
"description": "Personal fork of schmutzka/pdf-response - packagist enabled",
"require": {
"mpdf/mpdf": "v5.6.1"
},
"authors": [
{
"name": "Jan Kuchař"
},
{
"name": "Tomáš Votruba",
"email": "[email protected]"
}
],
"license": "LGPL-3.0",
"autoload": {
"classmap": ["PdfResponse.php"]
}
}

0 comments on commit 9fe56e7

Please sign in to comment.