I design reports using freemarker, I have a problem when I need processed PDF output.
What I want to do is to pass the HTML + CSS fremarker template to the freemarker mechanism and output the processed HTML as a PDF. The current issue is how to convert processed freemarker to pdf
try { Configuration cfg = new Configuration(); Template tpl = cfg.getTemplate("example.ftl"); OutputStreamWriter output = new OutputStreamWriter(System.out); Map testHashMap = new HashMap(); testHashMap.put("test", "testValue"); tpl.process(testHashMap, output); } catch (Exception e) { e.printStackTrace(); }
While searching the Internet, I could not find any information on this topic, but I found out about the iText infrastructure
try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new StringBufferInputStream(buf.toString())); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(doc, null); renderer.layout(); OutputStream os = response.getOutputStream(); renderer.createPDF(os); os.close(); } catch (Exception ex) { ex.printStackTrace(); }
Now the problem is how to combine these two code snippets to create pdf?
All help is really appreciated
Regards, MilindaD
source share