Skip to content

Commit

Permalink
Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ywarnier committed Apr 18, 2024
2 parents 5245228 + e4e88c2 commit b4241a8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main/inc/lib/pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mpdf\Mpdf;
use Mpdf\MpdfException;
use Mpdf\Utils\UtfString;
use Symfony\Component\DomCrawler\Crawler;

/**
* Class PDF.
Expand Down Expand Up @@ -334,9 +335,24 @@ public function html_to_pdf(
$filename = basename($filename, '.htm');
}

$webPath = api_get_path(WEB_PATH);

$document_html = @file_get_contents($file);
$document_html = preg_replace($clean_search, '', $document_html);

$crawler = new Crawler($document_html);
$crawler
->filter('link[rel="stylesheet"]')
->each(function (Crawler $node) use ($webPath) {
$linkUrl = $node->link()->getUri();

if (!str_starts_with($linkUrl, $webPath)) {
$node->getNode(0)->parentNode->removeChild($node->getNode(0));
}
})
;
$document_html = $crawler->outerHtml();

//absolute path for frames.css //TODO: necessary?
$absolute_css_path = api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css';
$document_html = str_replace('href="./css/frames.css"', $absolute_css_path, $document_html);
Expand Down

0 comments on commit b4241a8

Please sign in to comment.