import java.io.FileInputStream; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class for Servlet: renderxsample * */ public class renderxsample extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#HttpServlet() */ public renderxsample() { super(); } /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { renderpdf(); } public void renderpdf(){ try{ System.out.println("===============inside renderpdf()=========="); java.util.Properties options = new java.util.Properties(); // Find the configuration file. If there exists a system property // named com.renderx.xep.CONFIG, do nothing; otherwise, set an // explicit CONFIG property in the constructor. // Adjust the path to match your installation. if (System.getProperty("com.renderx.xep.CONFIG") == null) { options.setProperty("CONFIG", "C:\\RenderX\\XEP\\xep.xml"); } // Create an instance of XEP formatter com.renderx.xep.FormatterImpl xep = null; try { xep = new com.renderx.xep.FormatterImpl(options); } catch (Exception e) { System.out.println("Could not create XEP formatter: " + e.toString()); System.exit(1); } try { // Create a JAXP SAXSource for the source javax.xml.transform.sax.SAXSource source = null; try { java.io.File in = new java.io.File("C:\\o2kreportsnew\\originalXMLDocumentISO.xml"); // java.io.File.toURL() is Java 1.2+, not supported by MS JVM //org.xml.sax.InputSource saxsrc = new org.xml.sax.InputSource(in.toURL().toString()); org.xml.sax.InputSource saxsrc = new org.xml.sax.InputSource(new FileInputStream(in)); source = new javax.xml.transform.sax.SAXSource(saxsrc); } catch (Exception e) { System.out.println("Source creation failed: " + e.toString()); System.exit(1); } // Create a transformer object com.renderx.xep.FOTransformer transformer = null; try { java.io.File in = new java.io.File("C:\\o2kreportsnew\\stylesheet_original.xsl"); javax.xml.transform.stream.StreamSource stylesheet = new javax.xml.transform.stream.StreamSource(in); transformer = new com.renderx.xep.FOTransformer(stylesheet, xep); } catch (Exception e) { System.out.println("Transformer creation failed: " + e.toString()); System.exit(1); } // Open the output file java.io.OutputStream outstr = null; try { outstr = new java.io.BufferedOutputStream(new java.io.FileOutputStream("C:\\o2kreportsnew\\RenderXgeneratedPDF.pdf")); } catch (Exception e) { System.out.println("Could not open output file: " + e.toString()); System.exit(1); } // Perform the transformation try { try { transformer.transform(source, new com.renderx.xep.FOTarget(outstr, "PDF")); } finally { outstr.close(); } } catch (Exception e) { System.out.println("Transformation error: " + e.toString()); System.exit(1); } } finally { xep.cleanup(); } // Everything is OK //System.exit(0); }catch(Exception ex){ ex.printStackTrace(); } } public static void main(String[] str){ renderxsample sample = new renderxsample(); sample.renderpdf(); } }