Is it possible to style svg with an external stylesheet using batik in the grail?

I am passing svg from gsp to the grails controller. I present it as a PDF and save the file. However, there is no styling. This makes sense because the style is performed using an external style sheet.

My question is: is it possible to add style to svg using a stylesheet using batik in grail?

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 am a new batik and cannot find examples of textbooks on which I can plunge.

+4
source share
2 answers

To use external SVG, the following statement must be added before its SVG content:

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

+2
source

I don't know about grails, but here is how you can do it with java (link) :

use custom style:

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

Or, I have not tested it and I'm not sure how it works, but there is this alternative style sheet:

 transcoder.addTranscodingHint(ImageTranscoder.KEY_ALTERNATE_STYLESHEET, alternateStylesheetName); 
+2
source

Source: https://habr.com/ru/post/1488519/


All Articles