Skip to content

Commit

Permalink
Tweaked pdf export iframe replacement to fix compatibility
Browse files Browse the repository at this point in the history
Was using a method that wasn't a proper available part of the
DomElement API.
  • Loading branch information
ssddanbrown committed Nov 28, 2021
1 parent 2c21850 commit 42703dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/Entities/Tools/ExportFormatter.php
Expand Up @@ -144,6 +144,7 @@ protected function htmlToPdf(string $html): string
{
$html = $this->containHtml($html);
$html = $this->replaceIframesWithLinks($html);

return $this->pdfGenerator->fromHtml($html);
}

Expand All @@ -159,7 +160,6 @@ protected function replaceIframesWithLinks(string $html): string
$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$xPath = new DOMXPath($doc);


$iframes = $xPath->query('//iframe');
/** @var DOMElement $iframe */
foreach ($iframes as $iframe) {
Expand All @@ -172,7 +172,7 @@ protected function replaceIframesWithLinks(string $html): string
$anchor->setAttribute('href', $link);
$paragraph = $doc->createElement('p');
$paragraph->appendChild($anchor);
$iframe->replaceWith($paragraph);
$iframe->parentNode->replaceChild($paragraph, $iframe);
}

return $doc->saveHTML();
Expand Down
6 changes: 2 additions & 4 deletions app/Entities/Tools/PdfGenerator.php
Expand Up @@ -2,12 +2,11 @@

namespace BookStack\Entities\Tools;

use Barryvdh\Snappy\Facades\SnappyPdf;
use Barryvdh\DomPDF\Facade as DomPDF;
use Barryvdh\Snappy\Facades\SnappyPdf;

class PdfGenerator
{

/**
* Generate PDF content from the given HTML content.
*/
Expand All @@ -24,5 +23,4 @@ public function fromHtml(string $html): string

return $pdf->output();
}

}
}

0 comments on commit 42703dd

Please sign in to comment.