Skip to content

Instantly share code, notes, and snippets.

@Naouak
Created May 30, 2016 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naouak/98b2afc88386dbfafc4d97c09f86be49 to your computer and use it in GitHub Desktop.
Save Naouak/98b2afc88386dbfafc4d97c09f86be49 to your computer and use it in GitHub Desktop.
wkhtmltopdf
<?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