Skip to content

Commit

Permalink
Merge pull request #25 from radekdostal/fix-parsing-styles
Browse files Browse the repository at this point in the history
Fixed removing styles from HTML template.
  • Loading branch information
jkuchar authored Aug 28, 2019
2 parents 71d3809 + 6f35329 commit 369ca35
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/PdfResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class PdfResponse implements \Nette\Application\IResponse {
*/
private $source;

/** @var array */
public $domOptions = [];


/**
* Callback - create mPDF object
Expand Down Expand Up @@ -347,7 +350,7 @@ public function send(IRequest $httpRequest, IResponse $httpResponse): void {

// deletes all <style> tags

$parsedHtml = new Dom();
$parsedHtml = $this->createDom();
$parsedHtml->loadStr($html);
foreach($parsedHtml->find('style') AS $el) {
$el->outertext = '';
Expand All @@ -359,9 +362,8 @@ public function send(IRequest $httpRequest, IResponse $httpResponse): void {
$mode = 0; // Parse all: HTML + CSS
}


// Support for base64 encoded images - workaround
$parsedHtml = new Dom();
$parsedHtml = $this->createDom();
$parsedHtml->loadStr($html);
$i = 1000;
foreach($parsedHtml->find('img') AS $element) {
Expand Down Expand Up @@ -455,4 +457,25 @@ public function createMPDF() {

return new Mpdf($config);
}


/**
* Creates and returns Dom object
* @return Dom
*/
private function createDom() {
$options = $this->domOptions;

if (empty($options))
{
$options = [
'removeStyles' => FALSE
];
}

$dom = new Dom();
$dom->setOptions($options);

return $dom;
}
}

0 comments on commit 369ca35

Please sign in to comment.