The user can generate a pdf file using Apache FOP.(http://xmlgraphics.apache.org/fop/)
FOP (Formatting Objects Processor) is from the apache group.It is said to be the worlds first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter. Actually it isn’t a tool specifically meant for PDF conversion or creation.FOP can be downloaded here.
FOP converts the XSL files (*.fo) to PDF format.
Following is a sample for generating a pdf.
Create a Driver instance and set the necessary inputs.
Driver driver = new Driver();
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
MessageHandler.setScreenLogger(logger);
driver.setLogger(logger);
driver.setRenderer(Driver.RENDER_PDF);// Output type
driver.setInputSource(new InputSource(new java.io.StringReader(fo)));
// fo is the xsl-fo format string which is generated after transforming the xml with xsl.
driver.setOutputStream(new FileOutputStream(outputFile));
driver.run();
driver.reset();
Using the above snippet you can generate a PDF file.:-)
That's really cool! That FOP will help me out a lot! I was wondering, could you do a similar thing only converting docx to pdf? That would be really helpful.
ReplyDeleteHi Tom, the fop framework reads the "xsl-fo" format file which is generated after transforming xslt with the given xml.
ReplyDeleteI dont know if its possible to convert docx to pdf using fop framework. Alternatively u get other paid document generation frameworks which might help you with your task.