_url($baseHref);
}
// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
// Get all the stylesheets so that they are processed in document order
$xpath = new DOMXPath($this->dom);
$stylesheets = $xpath->query("//*[name() = 'link' or name() = 'style']");
/** @var \DOMElement $tag */
foreach ($stylesheets as $tag) {
switch (strtolower($tag->nodeName)) {
// load tags
case "link":
if (mb_strtolower(stripos($tag->getAttribute("rel"), "stylesheet") !== false) || // may be "appendix stylesheet"
mb_strtolower($tag->getAttribute("type")) === "text/css"
) {
//Check if the css file is for an accepted media type
//media not given then always valid
$formedialist = preg_split("/[\s\n,]/", $tag->getAttribute("media"), -1, PREG_SPLIT_NO_EMPTY);
if (count($formedialist) > 0) {
$accept = false;
foreach ($formedialist as $type) {
if (in_array(mb_strtolower(trim($type)), $acceptedmedia)) {
$accept = true;
break;
}
}
if (!$accept) {
//found at least one mediatype, but none of the accepted ones
//Skip this css file.
break;
}
}
$url = $tag->getAttribute("href");
$url = Helpers::build_url($this->protocol, $this->baseHost, $this->basePath, $url);
if ($url !== null) {
$this->css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
}
}
break;
// load
$child = $child->nextSibling;
}
} else {
$css = $tag->nodeValue;
}
// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
$this->css->load_css($css, Stylesheet::ORIG_AUTHOR);
break;
}
// Set the base path of the Stylesheet to that of the file being processed
$this->css->set_protocol($this->protocol);
$this->css->set_host($this->baseHost);
$this->css->set_base_path($this->basePath);
}
}
/**
* @param string $cacheId
* @deprecated
*/
public function enable_caching($cacheId)
{
$this->enableCaching($cacheId);
}
/**
* Enable experimental caching capability
*
* @param string $cacheId
*/
public function enableCaching($cacheId)
{
$this->cacheId = $cacheId;
}
/**
* @param string $value
* @return bool
* @deprecated
*/
public function parse_default_view($value)
{
return $this->parseDefaultView($value);
}
/**
* @param string $value
* @return bool
*/
public function parseDefaultView($value)
{
$valid = ["XYZ", "Fit", "FitH", "FitV", "FitR", "FitB", "FitBH", "FitBV"];
$options = preg_split("/\s*,\s*/", trim($value));
$defaultView = array_shift($options);
if (!in_array($defaultView, $valid)) {
return false;
}
$this->setDefaultView($defaultView, $options);
return true;
}
/**
* Renders the HTML to PDF
*/
public function render()
{
$this->setPhpConfig();
$logOutputFile = $this->options->getLogOutputFile();
if ($logOutputFile) {
if (!file_exists($logOutputFile) && is_writable(dirname($logOutputFile))) {
touch($logOutputFile);
}
$startTime = microtime(true);
if (is_writable($logOutputFile)) {
ob_start();
}
}
$this->processHtml();
$this->css->apply_styles($this->tree);
// @page style rules : size, margins
$pageStyles = $this->css->get_page_styles();
$basePageStyle = $pageStyles["base"];
unset($pageStyles["base"]);
foreach ($pageStyles as $pageStyle) {
$pageStyle->inherit($basePageStyle);
}
// Set paper size if defined via CSS
if (is_array($basePageStyle->size)) {
[$width, $height] = $basePageStyle->size;
$this->setPaper([0, 0, $width, $height]);
}
// Create a new canvas instance if the current one does not match the
// desired paper size
$canvasWidth = $this->canvas->get_width();
$canvasHeight = $this->canvas->get_height();
$size = $this->getPaperSize();
if ($canvasWidth !== $size[2] || $canvasHeight !== $size[3]) {
$this->canvas = CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation);
$this->fontMetrics->setCanvas($this->canvas);
}
$canvas = $this->canvas;
$root_frame = $this->tree->get_root();
$root = Factory::decorate_root($root_frame, $this);
foreach ($this->tree as $frame) {
if ($frame === $root_frame) {
continue;
}
Factory::decorate_frame($frame, $this, $root);
}
// Add meta information
$title = $this->dom->getElementsByTagName("title");
if ($title->length) {
$canvas->add_info("Title", trim($title->item(0)->nodeValue));
}
$metas = $this->dom->getElementsByTagName("meta");
$labels = [
"author" => "Author",
"keywords" => "Keywords",
"description" => "Subject",
];
/** @var \DOMElement $meta */
foreach ($metas as $meta) {
$name = mb_strtolower($meta->getAttribute("name"));
$value = trim($meta->getAttribute("content"));
if (isset($labels[$name])) {
$canvas->add_info($labels[$name], $value);
continue;
}
if ($name === "dompdf.view" && $this->parseDefaultView($value)) {
$canvas->set_default_view($this->defaultView, $this->defaultViewOptions);
}
}
$root->set_containing_block(0, 0, $canvas->get_width(), $canvas->get_height());
$root->set_renderer(new Renderer($this));
// This is where the magic happens:
$root->reflow();
if (isset($this->callbacks["end_document"])) {
$fs = $this->callbacks["end_document"];
foreach ($fs as $f) {
$canvas->page_script($f);
}
}
// Clean up cached images
if (!$this->options->getDebugKeepTemp()) {
Cache::clear($this->options->getDebugPng());
}
global $_dompdf_warnings, $_dompdf_show_warnings;
if ($_dompdf_show_warnings && isset($_dompdf_warnings)) {
echo 'Dompdf Warnings