I want to write a java code which converts .html to pdf.I used adobe's itext api for html to pdf conversion.However this conversion fails when i give bad html file as input.(Html tags are not properly ended)Hence i used Htmlcleaner parser which cleans the bad html but not able to get the code which can rebuild the new html .Does anyone know about how to build new html from the parsed html tagnodes?
Asked
Active
Viewed 44 times
1 Answers
0
HtmlCleaner comes with a set of serializers that you can use for instance like this:
final HtmlCleaner cleaner = new HtmlCleaner();
final CleanerProperties properties = cleaner.getProperties();
final Serializer serializer = new SimpleHtmlSerializer(properties);
TagNode node = cleaner.clean("hello world");
StringWriter writer = new StringWriter();
serializer.write(node, writer, "UTF-8");
System.out.println(writer.toString());

Oscar Scholten
- 570
- 5
- 13