簡體   English   中英

為什么我的圖像不顯示在 XSL-FO 中?

[英]Why isn't my image displayed in XSL-FO?

在我的一個項目中,我必須使用 xslt 和 xml 在 pdf 中添加圖像。 但是,我的圖像根本不顯示。

這是我的 xslt 片段

<fo:block text-align="left">
<fo:external-graphic src="url({$var})" content-height="6pt" content-width="6pt"/>
</fo:block>

(我已經嘗試過使用和不使用 url 部分,但由於它已經存在,我決定在我的問題中顯示它)

變量 var 在包含的另一個文件中聲明。

<xsl:variable name="imgPath"></xsl:variable>
<xsl:variable name="var">
<xsl:value-of select="$imgPath"/>image.svg</xsl:variable>

我遇到的問題是,即使我在調試時可以看到圖像的正確路徑,圖像也不會顯示在最終結果中。

我不認為這是圖像位置的問題,因為 xsl 和圖像都在同一級別(因此 image.svg 是訪問圖像的正確路徑)

所以,我的問題的答案是我的文件名中有一個重音,這使我的 FOP 無法找到我的文件。 有時,最簡單的問題最難找到。

通過 XSL-FO 的 SVG 嵌入式圖形

Apache FOP 嵌入式 SVG 示例

<?xml version="1.0" encoding="utf-8"?>
<!-- external-graphic-SVG-Diagram.fo
 - Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4in" page-width="3in">
   <fo:region-body region-name="body" background-color="#eeffff"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body">
   <fo:block border-width="1px" border-style="solid">
    <fo:block-container width="1in" border-width="1px"
     border-style="solid">
     <fo:block>1 inch</fo:block>
    </fo:block-container>
    <fo:block-container width="72px" border-width="1px" 
     border-style="solid">
     <fo:block>72 px</fo:block>
    </fo:block-container>
    <fo:block-container width="120px" border-width="1px" 
     border-style="solid">
     <fo:block>120 px</fo:block>
    </fo:block-container>
    <fo:block border-width="1px" border-style="solid">
     SVG diagram of 288x288 px at a fixed resolution 144dpi:
    <fo:external-graphic src="sample.svg" width="2in" height="2in"
     content-width="scale-to-fit" content-height="scale-to-fit"/>
    </fo:block>
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

RenderX 嵌入式 SVG 示例

SVG 直接嵌入 XSL-FO:

<fo:block>
  Here is the image of a typical roadsign:
  <fo:instream-foreign-object content-height="1em">1 
    <svg:svg xmlns:svg="http://www.w3.org/2000/svg"2
             height="100" width="100" viewBox="-50 -50 100 100">
      <svg:circle r="50" style="fill:red; stroke:none"/>
      <svg:rect x="-40" y="-10" width="80" height="20"
                style="fill:white; stroke:none"/>             
    </svg:svg> 
  </fo:instream-foreign-object>
</fo:block>

根據XEP 用戶指南fo:instream-foreign-object可以托管 SVG 圖形。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM