从嵌入式 SVG 设置 XSL FO 背景图像
Setting XSL FO background image from embedded SVG
我正在 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?问题是导入 external 图像作为水印效果很好,但我找不到任何方法将此 embedded SVG 设置为背景图像。 .
这是一种方法。要在页面上做一个background-image,您可以将region-after 的范围设置为页面的高度,然后使用该区域的static-content 来放置图像。我对你的图片没有做任何特别的处理,但这样做,你可以使 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 测试了第二个 Watermark。它不适用于 FOP,因为某些内容不受支持。
样本:
我正在 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?问题是导入 external 图像作为水印效果很好,但我找不到任何方法将此 embedded SVG 设置为背景图像。 .
这是一种方法。要在页面上做一个background-image,您可以将region-after 的范围设置为页面的高度,然后使用该区域的static-content 来放置图像。我对你的图片没有做任何特别的处理,但这样做,你可以使 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 测试了第二个 Watermark。它不适用于 FOP,因为某些内容不受支持。
样本: