-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mPDF dependency is handled by composer & packagist
- Loading branch information
castamir
committed
Feb 9, 2013
1 parent
a36c452
commit 9fe56e7
Showing
2 changed files
with
20 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 ]]]]]]) | ||
|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} |