A Java-based HTML to text conversion library with support for nested tables and a subset of CSS. Please take a look at the Rendering document for a demonstration of Inscriptis conversion quality.
This is a Java port of inscriptis for Python.
Here is a quick teaser of an application using inscriptis for Java:
package example;
import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.w3c.dom.Document;
import ch.x28.inscriptis.Inscriptis;
public class Example {
public static void main(String[] args) {
String htmlContent = "<p style=\"margin-top:0px\">Hello World!</p>";
// use jsoup to parse HTML and convert it to W3C Document (https://jsoup.org)
Document document = W3CDom.convert(Jsoup.parse(htmlContent));
Inscriptis inscriptis = new Inscriptis(document);
String text = inscriptis.getText();
System.out.println(text); // Hello World!
}
}
Add the Maven dependency:
<dependency>
<groupId>ch.x28.inscriptis</groupId>
<artifactId>inscriptis</artifactId>
<version>1.0</version>
</dependency>
inscriptis requires a W3C document, so it's up to you which parser you choose. Here is a list of parsers that support a W3C document result.
https://mvnrepository.com/artifact/nu.validator/htmlparser
inscriptis for Java is an Open Source software released under the Apache License, Version 2.0