从嵌入式SVG设置XSL FO背景图像

阿列克谢·德特(Alexej Detert)

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

<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设置为背景图像...

凯文·布朗

这是一种方法。要在页面上制作背景图像,您可以将after-region的范围设置为页面的高度,然后使用该区域的静态内容放置图像。我对您的图像没有做任何特别的事情,但是通过这种方式,您可以使SVG大小与页面大小相同,然后进行居中对齐等出色的工作。

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

    <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的结果:

在此处输入图片说明

当然,您可以调整位置,大小,旋转度等。如果您愿意,我可以使用一些不同的Watermark SVG,在这里为您提供:

        <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。

样本:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章