diff --git a/.travis.yml b/.travis.yml index bcc19e2..41b9c3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - + - 7.2 matrix: allow_failures: - php: hhvm diff --git a/composer.json b/composer.json index 84a3c04..94fa329 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ } ], "require": { - "php": ">=5.4 || ~7.0.0 || ~7.1.0", - "mpdf/mpdf": "~6.1.3" + "php": ">=5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0", + "mpdf/mpdf": "~7.0.0" }, "require-dev": { "nette/application": "~2.2", - "nette/tester": "~1.0", + "nette/tester": "~2.0", "symfony/dom-crawler": "~2.5", "symfony/css-selector": "~2.5", "latte/latte": "~2.2" diff --git a/src/Joseki/Application/Responses/PdfResponse.php b/src/Joseki/Application/Responses/PdfResponse.php index a27cf20..0c1bb3c 100644 --- a/src/Joseki/Application/Responses/PdfResponse.php +++ b/src/Joseki/Application/Responses/PdfResponse.php @@ -2,7 +2,7 @@ namespace Joseki\Application\Responses; -use mPDF; +use Mpdf\Mpdf; use Nette; use Nette\Bridges\ApplicationLatte\Template; use Nette\FileNotFoundException; @@ -20,6 +20,7 @@ * @author Jan Kuchař * @author Tomáš Votruba * @author Miroslav Paulík + * @author Štěpán Škorpil * @copyright Copyright (c) 2010 Jan Kuchař (http://mujserver.net) * @license LGPL * @link http://addons.nette.org/cs/pdfresponse2 @@ -37,8 +38,10 @@ * @property bool $ignoreStylesInHTMLDocument * @method onBeforeComplete($mpdf) @internal */ -class PdfResponse extends Nette\Object implements Nette\Application\IResponse +class PdfResponse implements Nette\Application\IResponse { + use Nette\SmartObject; + /** possible save modes */ const INLINE = "I"; @@ -106,7 +109,7 @@ class PdfResponse extends Nette\Object implements Nette\Application\IResponse /** @var string margins: top, right, bottom, left, header, footer */ private $pageMargins = "16,15,16,15,9,9"; - /** @var mPDF */ + /** @var Mpdf */ private $mPDF = null; /** @var mPDF */ @@ -412,28 +415,37 @@ public function setBackgroundTemplate($pathToBackgroundTemplate) + /** + * @return array + */ + protected function getMPDFConfig() + { + $margins = $this->getMargins(); + return [ + 'mode' => 'utf-8', + 'format' => $this->pageFormat, + 'margin_left' => $margins["left"], + 'margin_right' => $margins["right"], + 'margin_top' => $margins["top"], + 'margin_bottom' => $margins["bottom"], + 'margin_header' => $margins["header"], + 'margin_footer' => $margins["footer"], + 'orientation' => $this->pageOrientation + ]; + } + + + /** * @throws InvalidStateException - * @return mPDF + * @return Mpdf */ public function getMPDF() { - if (!$this->mPDF instanceof mPDF) { - $margins = $this->getMargins(); - - $mpdf = new mPDF( - 'utf-8', // string $codepage - $this->pageFormat, // mixed $format - '', // float $default_font_size - '', // string $default_font - $margins["left"], // float $margin_left - $margins["right"], // float $margin_right - $margins["top"], // float $margin_top - $margins["bottom"], // float $margin_bottom - $margins["header"], // float $margin_header - $margins["footer"], // float $margin_footer - $this->pageOrientation - ); + if (!$this->mPDF instanceof Mpdf) { + + $mpdf = new Mpdf($this->getMPDFConfig()); + $mpdf->showImageErrors = true; $this->mPDF = $mpdf; @@ -580,7 +592,7 @@ public function save($dir, $filename = null) $filename = Strings::lower($filename ?: $this->documentTitle); if (Strings::endsWith($filename, ".pdf")) { - $filename = substr($filename, 0,-4); + $filename = substr($filename, 0, -4); } $filename = Strings::webalize($filename, "_") . ".pdf"; @@ -605,3 +617,4 @@ public function __toString() } } + diff --git a/tests/PdfResponse/expected/full.pdf b/tests/PdfResponse/expected/full.pdf index ea115ff..c3ede8d 100644 Binary files a/tests/PdfResponse/expected/full.pdf and b/tests/PdfResponse/expected/full.pdf differ diff --git a/tests/PdfResponse/expected/page.format.pdf b/tests/PdfResponse/expected/page.format.pdf index 785683e..22283b3 100644 Binary files a/tests/PdfResponse/expected/page.format.pdf and b/tests/PdfResponse/expected/page.format.pdf differ diff --git a/tests/PdfResponse/expected/symfony.crawler.pdf b/tests/PdfResponse/expected/symfony.crawler.pdf index 1a1d5e9..a724abb 100644 Binary files a/tests/PdfResponse/expected/symfony.crawler.pdf and b/tests/PdfResponse/expected/symfony.crawler.pdf differ