Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG to Image Using SVGSalamander not rendering SVG correctly #46

Open
thilinadinith opened this issue Oct 15, 2019 · 1 comment
Open

Comments

@thilinadinith
Copy link

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

@weisJ
Copy link
Contributor

weisJ commented Aug 25, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants