4

I have svg being passed from a gsp to my grails controller. I'm rendering it as a pdf and saving the file. However there is no styling attached. This makes sense as the styling is done using an external stylesheet.

My question is is it possible to add styling to the svg using a stylesheet using batik in grails?

Here is my source code :

 String svg_URI_input = params.image
    TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);
    OutputStream pdf_ostream = new FileOutputStream("report.pdf");
    TranscoderOutput output_pdf_file = new TranscoderOutput(pdf_ostream);
    Transcoder transcoder = new PDFTranscoder();
    transcoder.transcode(input_svg_image, output_pdf_file);
    pdf_ostream.flush();
    pdf_ostream.close();
    File fd = new File("report.pdf")

I'm new batik and can't find any tutorials examples that I can get my head around.

Guilherme Oderdenge
  • 4,935
  • 6
  • 61
  • 96
Travis
  • 705
  • 6
  • 30

2 Answers2

2

To use an external SVG, the following instruction must be added before your SVG content:

<?xml-stylesheet type="text/css" href="http://ww.test.com/svgstyle.css" ?>

Melanie
  • 1,198
  • 2
  • 17
  • 42
2

I know not about grails, but this is how you can do it with java (reference) :

use a 'user style-sheet':

  transcoder.addTranscodingHint(JPEGTranscoder.KEY_USER_STYLESHEET_URI, "http://localhost:2012/hermes/css/d3.css");

Or, not tested, and not sure how it works, but there is also this alternate stylesheet stuff:

transcoder.addTranscodingHint(ImageTranscoder.KEY_ALTERNATE_STYLESHEET,
                     alternateStylesheetName);
BiAiB
  • 12,932
  • 10
  • 43
  • 63