Skip to content

Commit b888807

Browse files
author
Raymond J. Kolbe
committed
Updated docs and fixed bug related to pdf filename behavior.
1 parent ae444fc commit b888807

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ effort on the consumer's end.
88

99
## Requirements
1010
- [Zend Framework 2](http://www.github.com/zendframework/zf2)
11-
- [DOMPDF](https://github.com/raykolbe/dompdf)
1211

1312
## Installation
1413
Installation of DOMPDFModule uses PHP Composer. For more information about
@@ -22,7 +21,7 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o
2221
```json
2322
{
2423
"require": {
25-
"dino/DOMPDFModule": "dev-master"
24+
"dino/dompdf-module": "dev-master"
2625
}
2726
}
2827
```
@@ -35,7 +34,7 @@ PHP Composer, please visit the official [PHP Composer site](http://getcomposer.o
3534
'DOMPDFModule',
3635
```
3736
#### Configuration options
38-
Copy `dino/DOMPDFModule/config/module.dompdf.local.php` to `my/project/directory/config/autoload/module.dompdf.local.php` and reference `dino/DOMPDFModule/config/module.config.php` for configration options that you can override.
37+
You can override options via the `dompdf_module` key in your local or global config files. See DOMPDFModule/config/module.config.php for config options.
3938

4039
## Usage
4140

@@ -51,17 +50,13 @@ class ReportController extends AbstractActionController
5150
{
5251
public function monthlyReportPdfAction()
5352
{
54-
return new PdfModel(
55-
array(), // Variable assignments per Zend\View\Model\ViewModel
56-
array(
57-
'fileName' => 'monthly-report', // Optional; triggers PDF download, automatically appends ".pdf"
58-
'paperSize' => 'a4',
59-
'paperOrientation' => 'landscape'
60-
)
61-
);
53+
$pdf = new PdfModel();
54+
$pdf->setOption('filename', 'monthly-report'), // Triggers PDF download, automatically appends ".pdf"
55+
$pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
56+
$pdf->setOption('paperOrientation', 'landscape'); // Defaults to "portrait"
6257
}
6358
}
6459
```
6560

6661
## To-do
67-
- Add support for DOMPDF CLI
62+
- Add command line support.

src/DOMPDFModule/View/Strategy/PdfStrategy.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ public function injectResponse(ViewEvent $e)
120120

121121
$fileName = $e->getModel()->getOption('filename');
122122
if (isset($fileName)) {
123+
if (substr($fileName, -4) != '.pdf') {
124+
$fileName .= '.pdf';
125+
}
126+
123127
$response->getHeaders()->addHeaderLine(
124128
'Content-Disposition',
125-
'attachment; filename=' . $e->getModel()->getOption('filename'));
129+
'attachment; filename=' . $fileName);
126130
}
127131
}
128132
}

tests/DOMPDFModuleTest/View/Strategy/PdfStrategyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testResponseHeadersWithFileName()
6161
{
6262
$model = new PdfModel();
6363
$model->setTemplate('basic.phtml');
64-
$model->setOption('filename', 'testPdfFileName.pdf');
64+
$model->setOption('filename', 'testPdfFileName');
6565

6666
$this->event->setModel($model);
6767
$this->event->setResponse($this->response);

0 commit comments

Comments
 (0)