Created
May 30, 2016 12:34
-
-
Save Naouak/98b2afc88386dbfafc4d97c09f86be49 to your computer and use it in GitHub Desktop.
wkhtmltopdf
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
<?php | |
class PdfRenderer extends \mikehaertl\wkhtmlto\Pdf{ | |
/** | |
* Add a page object to the output | |
* | |
* @param string $input either a URL, a HTML string or a PDF/HTML filename | |
* @param array $options optional options for this page | |
* @return static the Pdf instance for method chaining | |
*/ | |
public function addPage($input,$options=array(),$type = null) | |
{ | |
$options = $this->processOptions($options); | |
$options['inputArg'] = $this->processInput($input,$type); | |
$this->_objects[] = $options; | |
return $this; | |
} | |
/** | |
* @param string $input | |
* @return \mikehaertl\tmp\File|string a File object if the input is a html string. The unchanged input otherwhise. | |
*/ | |
protected function processInput($input, $type = null) | |
{ | |
if (preg_match(self::REGEX_HTML, $input) || $type === "html") { | |
return $this->_tmpFiles[] = new \mikehaertl\tmp\File($input, '.html', self::TMP_PREFIX, $this->tmpDir); | |
} elseif (preg_match(self::REGEX_XML, $input) || $type === "xml") { | |
return $this->_tmpFiles[] = new \mikehaertl\tmp\File($input, '.xml', self::TMP_PREFIX, $this->tmpDir); | |
} else { | |
return $input; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment