You need to use Entity Resolver
myBuilder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
if (systemId.contains("pdf2xml.dtd")) {
return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
} else
return null;
}
});
when the parser reaches the condition - "pdf2xml.dtd", the entity resolver is called, which returns an empty XML doc.