Is your virtual machine online? Maybe the handler / parser is trying to load related resources like
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
which are necessary to ensure the correctness of the xml (xhtml) you provided.
In the servlet, I do the following, which seems to work (some online resources are available in my own file system, because the server does not have an Internet connection):
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.contains("xhtml1-transitional.dtd")) { return new InputSource(new FileReader(realPath + "/WEB-INF/dtd/xhtml1-transitional.dtd")); } else if (systemId.contains("xhtml-lat1.ent")) { return new InputSource(new FileReader(realPath + "/WEB-INF/dtd/xhtml-lat1.ent")); } else if (systemId.contains("xhtml-symbol.ent")) { return new InputSource(new FileReader(realPath + "/WEB-INF/dtd/xhtml-symbol.ent")); } else if (systemId.contains("xhtml-special.ent")) { return new InputSource(new FileReader(realPath + "/WEB-INF/dtd/xhtml-special.ent")); } else { return null; } } }); final ByteArrayInputStream inputStream = new ByteArrayInputStream(html.getBytes("UTF-8")); final Document doc = builder.parse(inputStream); inputStream.close(); final ITextRenderer renderer = new ITextRenderer(26f * 4f / 3f, 26); renderer.setDocument(doc, request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()); renderer.layout();
This basically sets the DocumentBuilder and then parses my document (which is in String format and represented by the html variable)
source share