Package com.pd4ml.dom
Class Document
- java.lang.Object
-
- com.pd4ml.dom.Node
-
- com.pd4ml.dom.Document
-
public class Document extends Node
An HTML document parsed by the v42 layout engine, asPD4ML.getDocument()returns it afterreadHTML(). Changes made to it before the document is written (writePDF(), writeRTF(), renderAsImages() etc.) are laid out as if the HTML had been written that way: elements, attributes, inline styles and<style>/<link>style sheets, images. No external libraries are involved.PD4ML pd4ml = new PD4ML(); pd4ml.useHtmlRenderer(Constants.LayoutEngine.v42); pd4ml.readHTML(url); Document doc = pd4ml.getDocument(); for (Element e : doc.querySelectorAll("table.prices td.amount")) { e.addClass("right"); } doc.getBody().appendChild(doc.createElement("p")).setTextContent("Printed " + new Date()); pd4ml.writePDF(out);- Since:
- v4.2.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CommentcreateComment(java.lang.String data)A new comment of this document, not yet in the tree.ElementcreateElement(java.lang.String tagName)A new element of this document, not yet in the tree.TextcreateTextNode(java.lang.String data)A new text node of this document, not yet in the tree.java.lang.StringgetBaseURI()The base URI relative links and images are resolved against.ElementgetBody()The<body>(or<frameset>) element, or null.DocumentTypegetDoctype()The doctype, or null if the document has none (it is laid out in quirks mode then).ElementgetDocumentElement()The root element (<html>).ElementgetElementById(java.lang.String id)The first element with the id, or null.java.util.List<Element>getElementsByClassName(java.lang.String names)The elements that have all the (space separated) class names, in document order.java.util.List<Element>getElementsByTagName(java.lang.String name)The elements with the tag name, in document order (*: all).ElementgetHead()The<head>element, or null.java.lang.StringgetTitle()The text of the<title>element, or an empty string.booleanisQuirksMode()True if the document is laid out in quirks mode (no or a legacy doctype).static Documentof(java.lang.Object parsedDocument)The document object for the parsed v42 document.ElementquerySelector(java.lang.String selectors)The first element that matches the CSS selector (list), or null.java.util.List<Element>querySelectorAll(java.lang.String selectors)The elements that match the CSS selector (list), in document order.voidsetTextContent(java.lang.String text)Comments and text cannot be direct children of a document here: only the doctype and the root.-
Methods inherited from class com.pd4ml.dom.Node
appendChild, cloneNode, contains, equals, getChildNodes, getFirstChild, getLastChild, getNextSibling, getNodeName, getOwnerDocument, getParentElement, getParentNode, getPreviousSibling, getTextContent, hasChildNodes, hashCode, insertBefore, remove, removeChild, replaceChild, toHtml, toString
-
-
-
-
Method Detail
-
getDocumentElement
public Element getDocumentElement()
The root element (<html>).
-
getHead
public Element getHead()
The<head>element, or null.
-
getBody
public Element getBody()
The<body>(or<frameset>) element, or null.
-
getDoctype
public DocumentType getDoctype()
The doctype, or null if the document has none (it is laid out in quirks mode then).
-
isQuirksMode
public boolean isQuirksMode()
True if the document is laid out in quirks mode (no or a legacy doctype).
-
getBaseURI
public java.lang.String getBaseURI()
The base URI relative links and images are resolved against.
-
getTitle
public java.lang.String getTitle()
The text of the<title>element, or an empty string.
-
getElementById
public Element getElementById(java.lang.String id)
The first element with the id, or null.
-
getElementsByTagName
public java.util.List<Element> getElementsByTagName(java.lang.String name)
The elements with the tag name, in document order (*: all).
-
getElementsByClassName
public java.util.List<Element> getElementsByClassName(java.lang.String names)
The elements that have all the (space separated) class names, in document order.
-
querySelector
public Element querySelector(java.lang.String selectors)
The first element that matches the CSS selector (list), or null.- Throws:
java.lang.IllegalArgumentException- if the selector is not valid
-
querySelectorAll
public java.util.List<Element> querySelectorAll(java.lang.String selectors)
The elements that match the CSS selector (list), in document order.- Throws:
java.lang.IllegalArgumentException- if the selector is not valid
-
createElement
public Element createElement(java.lang.String tagName)
A new element of this document, not yet in the tree.- Parameters:
tagName- the tag name (made lower case)
-
createTextNode
public Text createTextNode(java.lang.String data)
A new text node of this document, not yet in the tree.
-
createComment
public Comment createComment(java.lang.String data)
A new comment of this document, not yet in the tree.
-
setTextContent
public void setTextContent(java.lang.String text)
Comments and text cannot be direct children of a document here: only the doctype and the root.- Overrides:
setTextContentin classNode
-
of
public static Document of(java.lang.Object parsedDocument)
The document object for the parsed v42 document. Internal: usePD4ML.getDocument().
-
-