从嵌入的 SVG 设置 XSL FO 背景图像 [英] Setting XSL FO background image from embedded SVG

查看:25
本文介绍了从嵌入的 SVG 设置 XSL FO 背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以这种方式在 XSL FO 文档创建背景文本:

I am creating a background text within a XSL FO document this way:

<svg:svg width="285" height="70">
      <svg:g transform="rotate(-5)">
            <svg:text x="10" y="60" style="font-family:Courier;font-size:40;font-weight:normal;stroke-width:0.5;fill:none;stroke:lightgray;stroke-opacity:0.75;">
                  Background Watermark Text 
            </svg:text>
      </svg:g>
</svg:svg>

有没有办法在页面背景中显示这个 SVG?问题是导入外部图像作为水印效果很好,但我找不到任何方法将此嵌入式 SVG设置为背景图像...

Is there any way to display this SVG in background of the page? The problem is that importing an external image as watermark works fine, but I do not find any way to set this embedded SVG as background image...

推荐答案

这是一种方法.要在页面上做背景图像,您可以将区域后的范围设置为页面的高度,然后使用该区域的静态内容来放置图像.我对你的图片没有做任何特别的事情,但是这样做,你可以让 SVG 成为页面的大小,然后很好地居中等等.

Here's one way. To do a background-image on a page, you can set the extent of the region-after to the height of the page and then use the static-content of that region to place the image. I did nothing special with your image, but doing it this way, you could make the SVG the size of the page and then do a nice job centering and such.

(我更改了颜色以使其更易于查看):

(I changed the color to make it easier to see):

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:rx="http://www.renderx.com/XSL/Extensions">
        <fo:layout-master-set>
            <fo:simple-page-master page-width="8in" page-height="11in" master-name="first">
                <fo:region-body margin-top="1in" margin-left="1in" margin-bottom="1in"
                    margin-right="1in"/>
                <fo:region-before extent="0pt"/>
                <fo:region-after extent="11in"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="first">
            <fo:static-content flow-name="xsl-region-before">
                <fo:block line-height="0">
                    <fo:instream-foreign-object>
                        <svg:svg width="285" height="70" xmlns:svg="http://www.w3.org/2000/svg">
                            <svg:g transform="rotate(-5)">
                                <svg:text x="10" y="60" style="font-family:Courier;font-size:40;font-weight:normal;stroke-width:0.5;fill:cyan;stroke:lightgray;stroke-opacity:0.75;">
                                    Background Watermark Text 
                                </svg:text>
                            </svg:g>
                        </svg:svg>
                    </fo:instream-foreign-object>
                </fo:block>
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body">
                <fo:block>
                    I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. 
                </fo:block>
                <fo:block>
                    I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. 
                </fo:block>
                <fo:block>
                    I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. I am a happy little block in the page. 
                </fo:block>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>

使用 Apache FOP 的结果:

Result using Apache FOP:

当然,你可以调整你的定位、大小、旋转等.我使用了一些不同的水印 SVG,如果您愿意,可以在这里为您提供:

Of course, you can adjust your positioning, size, rotation, etc. I use a bit different Watermark SVG, here for you if you wish:

        <svg width="612pt" height="792pt" xmlns="http://www.w3.org/2000/svg" version="1.1">
            <text transform="translate(306pt, 396pt) rotate(47)" text-anchor="middle" fill="rgb(255,0,0)" font-family="Helvetica" font-size="92pt" stroke="rgb(255,0,0)" fill-opacity="0.07">WATERMARK</text>
        </svg>

但是,我只用 RenderX XEP 测试了第二个水印.它不适用于 FOP,因为某些内容不受支持.

However, I have only tested that second Watermark with RenderX XEP. It does not work with FOP as something is not supported.

示例:

这篇关于从嵌入的 SVG 设置 XSL FO 背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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