Skip to content

Commit

Permalink
Merge branch 'Stopka-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
castamir committed Jan 3, 2018
2 parents 9c036b6 + d4589d2 commit 0f6870c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .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
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -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"
Expand Down
55 changes: 34 additions & 21 deletions src/Joseki/Application/Responses/PdfResponse.php
Expand Up @@ -2,7 +2,7 @@

namespace Joseki\Application\Responses;

use mPDF;
use Mpdf\Mpdf;
use Nette;
use Nette\Bridges\ApplicationLatte\Template;
use Nette\FileNotFoundException;
Expand All @@ -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
Expand All @@ -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";

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -605,3 +617,4 @@ public function __toString()
}

}

Binary file modified tests/PdfResponse/expected/full.pdf
Binary file not shown.
Binary file modified tests/PdfResponse/expected/page.format.pdf
Binary file not shown.
Binary file modified tests/PdfResponse/expected/symfony.crawler.pdf
Binary file not shown.

0 comments on commit 0f6870c

Please sign in to comment.