public static void createSVG(Document pdfDocument, int pageNumber, Writer out) {
        try {

            if (pdfDocument != null &&
                    (pageNumber >= 0 && pageNumber < pdfDocument.getNumberOfPages())) {
                // Get a DOMImplementation
                DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
                // Create an instance of org.w3c.dom.Document
                org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
                        null);
                // Create an instance of the SVG Generator
                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
                // Ask the test to render into the SVG Graphics2D implementation

                float userRotation = 0;
                float userZoom = 1;
                PDimension pdfDimension = pdfDocument.getPageDimension(pageNumber, userRotation, userZoom);
                svgGenerator.setSVGCanvasSize(pdfDimension.toDimension());

                pdfDocument.paintPage(pageNumber, svgGenerator,
                        GraphicsRenderingHints.PRINT,
                        Page.BOUNDARY_CROPBOX,
                        userRotation, userZoom);

                // Finally, stream out SVG to the standard output using UTF-8
                // character to byte encoding
                boolean useCSS = true;              // we want to use CSS style attribute
                //            File f=new File("a.svg");
                //            Writer out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
                svgGenerator.stream(out, useCSS);
            }
        } catch (org.apache.batik.svggen.SVGGraphics2DIOException e) {
            logger.log(Level.SEVERE, "Error creating svg document.", e);
        }
    }