从嵌入式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?问题是,导入外部图片作为水印效果很好,但是我找不到任何方法将此嵌入式 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,因为不支持某些功能.
示例:
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>
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...
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>
Result using Apache FOP:
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>
However, I have only tested that second Watermark with RenderX XEP. It does not work with FOP as something is not supported.
Sample:
这篇关于从嵌入式SVG设置XSL FO背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!