【问题标题】:Is it possible to style svg with an external style sheet using batik in grails?是否可以在 grails 中使用 batik 使用外部样式表设置 svg 样式?
【发布时间】:2013-06-27 15:13:21
【问题描述】:

我已将 svg 从 gsp 传递到我的 grails 控制器。我将其渲染为 pdf 并保存文件。但是没有附加样式。这是有道理的,因为样式是使用外部样式表完成的。

我的问题是是否可以使用 grails 中的 batik 样式表向 svg 添加样式?

这是我的源代码:

 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")

我是新蜡染,找不到任何我可以理解的教程示例。

【问题讨论】:

    标签: java grails svg batik


    【解决方案1】:

    要使用外部 SVG,必须在 SVG 内容之前添加以下指令:

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

    【讨论】:

      【解决方案2】:

      我不知道 grails,但这是你可以用 java (reference) 做到的:

      使用“用户样式表”:

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

      或者,没有测试,也不确定它是如何工作的,但也有这个替代样式表的东西:

      transcoder.addTranscodingHint(ImageTranscoder.KEY_ALTERNATE_STYLESHEET,
                           alternateStylesheetName);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-16
        相关资源
        最近更新 更多