Skip to content

Instantly share code, notes, and snippets.

@ogavrisevs
Created May 29, 2012 13:41
Show Gist options
  • Save ogavrisevs/2828437 to your computer and use it in GitHub Desktop.
Save ogavrisevs/2828437 to your computer and use it in GitHub Desktop.
Create pdf using iText 2.08 + ITextRenderer (R8 or R8pre) from html with styles
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(false);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.parse(stream);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
renderer.createPDF(outputStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment