Skip to content

Instantly share code, notes, and snippets.

@ogavrisevs
Created May 29, 2012 13:38
Show Gist options
  • Save ogavrisevs/2828423 to your computer and use it in GitHub Desktop.
Save ogavrisevs/2828423 to your computer and use it in GitHub Desktop.
Create pdf using iText from html
com.lowagie.text.Document document = new com.lowagie.text.Document();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfWriter.getInstance(document, outputStream);
HtmlWriter.getInstance(document, System.out);
document.open();
List<Element> objects = HTMLWorker.parseToList(reader, null, null);
for (Element element : objects) {
document.add(element);
}
document.close();
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
document.close();
htmlWorker.parse(reader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment