/** * Renders the HTML to PDF */ function render() { $this->save_locale(); if (DOMPDF_LOG_OUTPUT_FILE) { if (!file_exists(DOMPDF_LOG_OUTPUT_FILE) && is_writable(dirname(DOMPDF_LOG_OUTPUT_FILE))) { touch(DOMPDF_LOG_OUTPUT_FILE); } $this->_start_time = microtime(true); ob_start(); } //enable_mem_profile(); $this->_process_html(); $this->_css->apply_styles($this->_tree); $root = null; foreach ($this->_tree->get_frames() as $frame) { // Set up the root frame if (is_null($root)) { $root = Frame_Factory::decorate_root($this->_tree->get_root(), $this); continue; } // Create the appropriate decorators, reflowers & positioners. $deco = Frame_Factory::decorate_frame($frame, $this); $deco->set_root($root); // FIXME: handle generated content if ($frame->get_style()->display === "list-item") { // Insert a list-bullet frame $node = $this->_xml->createElement("bullet"); // arbitrary choice $b_f = new Frame($node); $parent_node = $frame->get_parent()->get_node(); if (!$parent_node->hasAttribute("dompdf-children-count")) { $count = 0; foreach ($parent_node->childNodes as $_node) { if ($_node instanceof DOMElement) { $count++; } } $parent_node->setAttribute("dompdf-children-count", $count); } $index = 0; if (!$parent_node->hasAttribute("dompdf-counter")) { $index = 1; $parent_node->setAttribute("dompdf-counter", 1); } else { $index = $parent_node->getAttribute("dompdf-counter"); $index++; $parent_node->setAttribute("dompdf-counter", $index); } $node->setAttribute("dompdf-counter", $index); $style = $this->_css->create_style(); $style->display = "-dompdf-list-bullet"; $style->inherit($frame->get_style()); $b_f->set_style($style); $deco->prepend_child(Frame_Factory::decorate_frame($b_f, $this)); } } $page_style = $this->_css->get_page_style(); if ($page_style && is_array($page_style->size)) { $this->set_paper(array(0, 0, $page_style->size[0], $page_style->size[1])); } $this->_pdf = Canvas_Factory::get_instance($this->_paper_size, $this->_paper_orientation); // Add meta information $title = $this->_xml->getElementsByTagName("title"); if ($title->length) { $this->_pdf->add_info("Title", trim($title->item(0)->nodeValue)); } $metas = $this->_xml->getElementsByTagName("meta"); $labels = array("author" => "Author", "keywords" => "Keywords", "description" => "Subject"); foreach ($metas as $meta) { $name = mb_strtolower($meta->getAttribute("name")); if (isset($labels[$name])) { $this->_pdf->add_info($labels[$name], trim($meta->getAttribute("content"))); } } $root->set_containing_block(0, 0, $this->_pdf->get_width(), $this->_pdf->get_height()); $root->set_renderer(new Renderer($this)); // This is where the magic happens: $root->reflow(); // Clean up cached images Image_Cache::clear(); global $_dompdf_warnings, $_dompdf_show_warnings; if ($_dompdf_show_warnings) { echo '<b>DOMPDF Warnings</b><br><pre>'; foreach ($_dompdf_warnings as $msg) { echo $msg . "\n"; } echo $this->get_canvas()->get_cpdf()->messages; echo '</pre>'; flush(); } $this->restore_locale(); }