Guest User

Untitled

a guest
Mar 22nd, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. File pdfRootDirectory = new File(configRootDirectory.getAbsolutePath()+System.getProperty("file.separator")+"pdf");
  2.  
  3. DOMImplementation domImpl= GenericDOMImplementation.getDOMImplementation();
  4. // Create an instance of org.w3c.dom.Document
  5. Document document = domImpl.createDocument(null, "svg", null);
  6. // Create an instance of the SVG Generator
  7. SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
  8. // set the precision to avoid a null pointer exception in Batik 1.5
  9. svgGenerator.getGeneratorContext().setPrecision(6);
  10. // Ask the chart to render into the SVG Graphics2D implementation
  11. chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);
  12. // Finally, stream out SVG to a file using UTF-8 character to
  13. // byte encoding
  14. boolean useCSS = true;
  15. Writer w = new OutputStreamWriter(
  16. new FileOutputStream(new File("test.svg")), "UTF-8");
  17. svgGenerator.stream(w, useCSS);
  18.  
  19. // <editor-fold defaultstate="collapsed" desc="Export chart as PNG file">
  20. ChartUtilities.saveChartAsPNG(new File(pdfRootDirectory.getAbsolutePath()+ System.getProperty("file.separator") +"tmp.png"), chart, width, height);
  21. // </editor-fold>
  22.  
  23. File xslt = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "xslt"+System.getProperty("file.separator")+"stylesheet.xsl");
  24. File xml = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "xml" + System.getProperty("file.separator") + "data.xml");
  25. File fo = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "fo" + System.getProperty("file.separator") + "temp.fo");
  26.  
  27. convertXML2FO(xml, xslt, fo);
  28.  
  29. FopFactory fopFactory = FopFactory.newInstance();
  30.  
  31. OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
  32. try {
  33. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
  34.  
  35. TransformerFactory factory = TransformerFactory.newInstance();
  36. Transformer transformer = factory.newTransformer();
  37.  
  38. Source src = new StreamSource(fo);
  39.  
  40. Result res = new SAXResult(fop.getDefaultHandler());
  41.  
  42. transformer.transform(src, res);
  43. } finally {
  44. out.close();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment