gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:57:18 25 4
gpt4 key购买 nike

我正在以这种方式 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设置为背景图像...

最佳答案

这是一种方法。要在页面上制作背景图像,您可以将 region-after 的范围设置为页面的高度,然后使用该区域的静态内容来放置图像。我对您的图像没有做任何特别的处理,但是这样做,您可以使 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 的结果:

enter image description here

当然,你可以调整你的定位、大小、旋转等。我使用了一些不同的 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 测试了第二个 Watermark。它不适用于 FOP,因为某些内容不受支持。

示例:

enter image description here

关于xsl-fo - 从嵌入式 SVG 设置 XSL FO 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38012480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com