Skip to content

Commit

Permalink
Updates to release v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Apr 14, 2020
1 parent 0426925 commit 7ea3a5f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
4 changes: 3 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Change Log: `yii2-mpdf`

## Version 1.0.6

**Date:** _under development_
**Date:** 14-Apr-2020

- (enh #106): Fix getCss function.
- (enh #92, #104, #105): Enhancements for MPDF v8.0.
- Update README.
- (enh #89): Fix README.md & throw InvalidConfigException for invalid CSS config.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2018, Kartik Visweswaran
Copyright (c) 2014 - 2020, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
67 changes: 27 additions & 40 deletions src/Pdf.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2020
* @package yii2-mpdf
* @version 1.0.6
*/
Expand Down Expand Up @@ -198,32 +198,6 @@ class Pdf extends Component
*/
protected $_pdfAttachments;

/**
* Defines a Mpdf temporary path if not set.
*
* @param string $prop the Mpdf constant to define
* @param string $dir the directory to create
*
* @throws InvalidConfigException
*/
protected static function definePath($prop, $dir)
{
if (defined($prop)) {
$propDir = constant($prop);
if (is_writable($propDir)) {
return;
}
}
$status = true;
if (!is_dir($dir)) {
$status = mkdir($dir, 0777, true);
}
if (!$status) {
throw new InvalidConfigException("Could not create the folder '{$dir}' in '\$tempPath' set.");
}
define($prop, $dir);
}

/**
* @inheritdoc
*/
Expand All @@ -236,25 +210,26 @@ public function init()

/**
* Initialize folder paths to allow [[Mpdf]] to write temporary data.
*
* @throws InvalidConfigException
*/
public function initTempPaths()
{
if (empty($this->tempPath)) {
$this->tempPath = Yii::getAlias('@runtime/mpdf');
}
$s = DIRECTORY_SEPARATOR;
$prefix = $this->tempPath . $s;
static::definePath('_MPDF_TEMP_PATH', "{$prefix}tmp{$s}");
static::definePath('_MPDF_TTFONTDATAPATH', "{$prefix}ttfontdata{$s}");
if (!file_exists($this->tempPath)) {
mkdir($this->tempPath);
}
}

/**
* Renders and returns the PDF output. Uses the class level property settings.
*
* @return mixed
* @throws InvalidConfigException
* @throws \Mpdf\MpdfException
* @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
* @throws \setasign\Fpdi\PdfParser\PdfParserException
* @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
*/
public function render()
{
Expand Down Expand Up @@ -300,26 +275,26 @@ public function setApi()
* Fetches the content of the CSS file if supplied
*
* @return string
* @throws InvalidConfigException
*/
public function getCss()
{
if (!empty($this->_css)) {
return $this->_css;
}
$this->_css = '';
$this->_css = '';
if (!empty($this->cssFile)) {
$cssFiles = is_array($this->cssFile) ? $this->cssFile : [$this->cssFile];
foreach ($cssFiles as $cssFile) {
$cssFile = Yii::getAlias($cssFile);
if (!empty($cssFile) && file_exists($cssFile)) {
$this->_css .= file_get_contents($cssFile);
}
else {
} else {
throw new InvalidConfigException("CSS File not found: '{$cssFile}'.");
}
}
}
$this->_css .= $this->cssInline;
$this->_css .= $this->cssInline;
return $this->_css;
}

Expand Down Expand Up @@ -374,6 +349,10 @@ public function execute($method, $params = [])
*
* @return mixed
* @throws InvalidConfigException
* @throws \Mpdf\MpdfException
* @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
* @throws \setasign\Fpdi\PdfParser\PdfParserException
* @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
*/
public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
{
Expand All @@ -392,7 +371,6 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
$api->WriteHTML($content);
}
if ($pdfAttachments) {
$api->SetImportUse();
$api->SetHeader(null);
$api->SetFooter(null);
foreach ($pdfAttachments as $attachment) {
Expand Down Expand Up @@ -430,7 +408,7 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
/**
* Parse the format automatically based on the orientation
*/
protected function parseFormat()
public function parseFormat()
{
$landscape = self::ORIENT_LANDSCAPE;
$tag = '-' . $landscape;
Expand All @@ -444,9 +422,18 @@ protected function parseFormat()
*
* @param Mpdf $api the Mpdf API instance
* @param string $attachment the attachment name
* @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
* @throws \setasign\Fpdi\PdfParser\PdfParserException
* @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
*/
private function writePdfAttachment($api, $attachment)
public function writePdfAttachment($api = null, $attachment = null)
{
if ($attachment === null) {
return;
}
if ($api === null) {
$api = $this->getApi();
}
$pageCount = $api->SetSourceFile($attachment);
for ($i = 1; $i <= $pageCount; $i++) {
$api->AddPage();
Expand Down

0 comments on commit 7ea3a5f

Please sign in to comment.