/** * Reads the child node along with the settings specified in the index the adds it to the tree. * * @param \DOMNode $node * @param WebPage $parentPage */ private function readInChildNode(\DOMNode $node, WebPage $parentPage = null) { $webPage = $parentPage; $settings = new WebPageSettings(); if (strcmp($node->nodeName, 'document') == 0) { $attributes = $node->attributes; $title = null; $src = null; $tag = array(); $order = null; $category = array(); if (isset($attributes)) { for ($i = 0; $i < $attributes->length; $i++) { $attribute = $attributes->item($i)->nodeName; switch ($attribute) { case 'title': $title = $attributes->item($i)->nodeValue; break; case 'src': $src = $attributes->item($i)->nodeValue; if ($src[0] != '/') { $src = basename($this->retriever->getFullFilePath($src)); } break; case 'category': // if category is set in XML, then overrides the web settings // TODO: should have a setting for if to use xml or web settings $category = explode(',', $attributes->item($i)->nodeValue); break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; // case 'tag': // $tag = explode( ',', $attributes->item( $i )->nodeValue ); // break; case 'order': $order = $attributes->item($i)->nodeValue; break; // /* future cases // case 'overwrite-existing': // break; // */ // /* future cases // case 'overwrite-existing': // break; // */ default: break; } } } if (!is_null($category) && is_array($category)) { foreach ($category as $index => $cat) { $cat_id = wp_create_category(trim($cat)); $settings->addCategory(intval($cat_id)); } } /* if ( !is_null( $tag ) && is_array( $tag ) ) { foreach ( $tag as $t ) { //TODO: support tags } }*/ $webPage = new WebPage($this->retriever, $title, $src, null, $settings); $webPage->setOrderPosition($order); if (is_null($parentPage)) { $this->trees[] = $webPage; } else { $parentPage->addChild($webPage); } } $children = $node->childNodes; if (isset($children)) { for ($i = 0; $i < $children->length; $i++) { $this->readInChildNode($children->item($i), $webPage); } } }
$converter = new HTML2PDF(); // Add a cover page, which is excluded from the outline, and ignore any errors $cover = new WebPageSettings(); $cover->SetLoadErrorHandling(WebPageSettings::e_ignore); $cover->SetIncludeInOutline(false); $converter->InsertFromURL($host . $page3, $cover); // Add a table of contents settings (modifying the settings is optional) $toc = new TOCSettings(); $toc->SetDottedLines(false); $converter->InsertTOC($toc); // Now add the rest of the web pages, disabling external links and // skipping any web pages that fail to load. // // Note that the order of insertion matters, so these will appear // after the cover and table of contents, in the order below. $settings = new WebPageSettings(); $settings->SetLoadErrorHandling(WebPageSettings::e_skip); $settings->SetExternalLinks(false); $converter->InsertFromURL($host . $page0, $settings); $converter->InsertFromURL($host . $page1, $settings); $converter->InsertFromURL($host . $page2, $settings); if ($converter->Convert($doc) == true) { $doc->Save($output_path . "_03.pdf", SDFDoc::e_linearized); } else { echo printf("Conversion failed. HTTP Code: %d\n%s", $converter->GetHTTPErrorCode(), $converter->GetLog()); } $doc->Close(); //-------------------------------------------------------------------------------- // Example 4) Convert HTML string to PDF. $doc = new PDFDoc(); $converter = new HTML2PDF();