svgSalamander icon indicating copy to clipboard operation
svgSalamander copied to clipboard

SVG to Image Using SVGSalamander not rendering SVG correctly

Open thilinadinith opened this issue 4 years ago • 1 comments

I have worked for SVG image rendering for iText PDF document. to do this i used SVGSalamander for convert SVG to image format. it works fine but it has a strange behavior that some of the SVG images are not rendering correctly while some are doing. those wrongly rendered svg are not aligned with the real image. I tried but i couldn't figure out why its happening only for some images.

Really appreciate if someone help me to resolve this.

Java Code:


private static Image createSVGImage(PdfWriter pdfWriter, String imageEntry) throws BadElementException {
        Image image = null;

        Graphics2D g2dgraphics =null;
        PdfTemplate template = null;
        try{
            SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram( new java.io.File( imageEntry ).toURI() );
            template = pdfWriter.getDirectContent().createTemplate( diagram.getWidth(), diagram.getHeight());
            diagram.setIgnoringClipHeuristic(true);
             g2dgraphics= new PdfGraphics2D(template, diagram.getWidth(), diagram.getHeight());
        diagram.render(g2dgraphics);
    }catch( Exception e ){
        e.printStackTrace();
    } finally {
        if( g2dgraphics != null ){
            g2dgraphics.dispose();
          image = Image.getInstance(template);

        }
        g2dgraphics.dispose();
    }

    return image;
}

SVG xml code that its not align

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <path d="M19,16a46,46 0,1,0 62,0l-8,8a34,34 0,1,1-46,0z" fill="#069"/>
  <path d="M46,43v35a28,28 0,0,1-14-49zM54,43v35a28,28 0,0,0 14-49z" fill="#396"/>
  <circle r="15" cx="50" cy="18" fill="#900"/>
</svg>

more details are available in question in stackoverflow ( images ) https://stackoverflow.com/questions/58373840/svg-to-image-using-svgsalamander-not-rendering-svg-correctly

thilinadinith avatar Oct 15 '19 01:10 thilinadinith

This doesn't seem to be relevant anymore. The provided svg renders correctly for me.

weisJ avatar Aug 25 '21 19:08 weisJ