Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created August 2, 2012 05:18
Show Gist options
  • Save sreeprasad/3233907 to your computer and use it in GitHub Desktop.
Save sreeprasad/3233907 to your computer and use it in GitHub Desktop.
Convert html to pdf using iText and Flying Saucer.
String inputFile = "~/github/iText/myhtml.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "~/github/iText/generated.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment