I create my pdf document out of a html File.
I want to save it to my Filesystem after creating it.
But i dont know how to save it… can you please help me saving this document? So that it is saved as a pdf then?
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setValidating(false);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
builder.setEntityResolver(FSEntityResolver.instance());
org.w3c.dom.document = builder.parse(new ByteArrayInputStream(result.getBytes("UTF-8")), "UTF-8");
baos = new ByteArrayOutputStream();
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(document, null);
renderer.layout();
renderer.createPDF(baos);
out.println(baos.toString());
baos.close();
If the code you’ve got is correct as far as you’re aware, but is simply writing to the wrong place (memory instead of a file) you just need to use a
FileOutputStream: