Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File pdfRootDirectory = new File(configRootDirectory.getAbsolutePath()+System.getProperty("file.separator")+"pdf");
- DOMImplementation domImpl= GenericDOMImplementation.getDOMImplementation();
- // Create an instance of org.w3c.dom.Document
- Document document = domImpl.createDocument(null, "svg", null);
- // Create an instance of the SVG Generator
- SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
- // set the precision to avoid a null pointer exception in Batik 1.5
- svgGenerator.getGeneratorContext().setPrecision(6);
- // Ask the chart to render into the SVG Graphics2D implementation
- chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);
- // Finally, stream out SVG to a file using UTF-8 character to
- // byte encoding
- boolean useCSS = true;
- Writer w = new OutputStreamWriter(
- new FileOutputStream(new File("test.svg")), "UTF-8");
- svgGenerator.stream(w, useCSS);
- // <editor-fold defaultstate="collapsed" desc="Export chart as PNG file">
- ChartUtilities.saveChartAsPNG(new File(pdfRootDirectory.getAbsolutePath()+ System.getProperty("file.separator") +"tmp.png"), chart, width, height);
- // </editor-fold>
- File xslt = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "xslt"+System.getProperty("file.separator")+"stylesheet.xsl");
- File xml = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "xml" + System.getProperty("file.separator") + "data.xml");
- File fo = new File(pdfRootDirectory.getAbsolutePath() + System.getProperty("file.separator") + "fo" + System.getProperty("file.separator") + "temp.fo");
- convertXML2FO(xml, xslt, fo);
- FopFactory fopFactory = FopFactory.newInstance();
- OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
- try {
- Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer();
- Source src = new StreamSource(fo);
- Result res = new SAXResult(fop.getDefaultHandler());
- transformer.transform(src, res);
- } finally {
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment