使用XSLFO显示SVG [英] Displaying SVG using XSLFO

查看:114
本文介绍了使用XSLFO显示SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个问题;我目前正在修复一个图形服务,该服务使用XSLFO将我们的语法转换为FO,最后将其转换为PDF.

First question from me; I'm currently fixing a graphing service that uses XSLFO to convert our syntax to FO, and converting it to PDF in the end.

以前,我们一直在PDF导出中使用Web上的PNG图形,但这会产生非常丑陋的结果,因此我们决定改用SVG for PDF.

Previously we've been using PNG graphs from the web in the PDF exports, but this creates really ugly results, so we've decided to go with SVG for PDF instead.

但是,SVG似乎无法正确缩放到SVG画布中.

However, the SVG doesn't seem to scale into the SVG canvas properly.

这是在运行XSLFO之前的语法:

Here is the syntax before run into XSLFO:

<img src="someimage.svg">

这是我正在使用的XSLFO:

And here is the XSLFO I'm using:

   <xsl:template match="img">
      <fo:block space-after="12pt">
          <fo:instream-foreign-object width="20cm" height="15cm" content-width="scale-to-fit" content-height="scale-to-fit" scaling="uniform" background-color="#cccccc">
          <svg:svg x="0" y="0" width="100" height="100" viewBox="0 0 100 100">
                <svg:image x="0" y="0" width="100" height="100">
                    <xsl:if test="@src">
                       <xsl:attribute name="xlink:href">
                          <xsl:choose>
                             <xsl:when test="starts-with(@src, 'http://')">
                                <xsl:value-of select="@src"/>
                             </xsl:when>
                             <xsl:when test="starts-with(@src, 'https://')">
                                <xsl:value-of select="@src"/>
                             </xsl:when>
                             <xsl:otherwise>
                                <xsl:value-of select="concat($baseurl, @src)"/>
                             </xsl:otherwise>
                          </xsl:choose>
                       </xsl:attribute>
                    </xsl:if>
                   </svg:image>
            </svg:svg>
         </fo:instream-foreign-object>
      </fo:block>
   </xsl:template>

SVG确实出现在PDF中,并且似乎包含在画布中-但是出于任何原因,我都无法使其正确缩放.它真的非常非常大,结果是SVG的裁剪版本非常丰富.

The SVG does appear in the PDF, and it does seem contained within the canvas - but for whatever reason I cannot get it to scale properly. It's just really, really huge, and the result being an extremely cropped version of the SVG.

我这里的建议用光了-这里有人有经验吗?

I'm running out of suggestions here - is there anyone here that has experience with this?

PS:使用最新版本的蜡染创建图像,并正确设置宽度和高度.

PS: The image is created using the newest version of Batik, and the width and height is set properly.

推荐答案

实际上,流外对象似乎根本无法缩放SVG,即使使用正确的画布集也是如此.通过在SVG上设置正确的画布,fo:external-graphic实现了技巧;-)

Actually, instream-foreign-object didn't seem to be able to scale the SVG at all, not even with the proper canvas set. By setting the correct canvas on the SVG, fo:external-graphic did the trick ;-)

谢谢你们给我您的提示:-)这是有效的方法:

Thanks you guys for giving me your tips :-) Here is what worked:

    <fo:external-graphic content-width="25cm" content-height="16cm">
        <xsl:if test="@src">
            <xsl:attribute name="src">
                <xsl:choose>
                    <xsl:when test="starts-with(@src, 'http://')">
                        <xsl:value-of select="concat('url(',@src,')')"/>
                    </xsl:when>
                    <xsl:when test="starts-with(@src, 'https://')">
                        <xsl:value-of select="concat('url(',@src,')')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat('url(',$baseurl, @src,')') + ')'"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
        </xsl:if>
    </fo:external-graphic>

这篇关于使用XSLFO显示SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆