【问题标题】:fo:instream-foreign-object does not show the image properlyfo:instream-foreign-object 无法正确显示图像
【发布时间】:2016-10-05 21:15:13
【问题描述】:

我使用以下代码以 PDF 格式显示 PNG 图像。我使用<fo:instream-foreign-object> 因为<fo:external-graphic> 不能满足我显示图像的要求。参考问题external graphic

<fo:instream-foreign-object width="50%" content-width="scale-to-fit">
   <svg> 
       <image height="439px" width="1037px" xlink:href="test.png"/>
   </svg>
</fo:instream-foreign-object>

通过上述使用,我无法获取文档中的图片。图像未正确放置在页面中,并且下一段中的文本覆盖在其顶部。 请提出如何实现它。

【问题讨论】:

  • 缺少 svg 的命名空间 (xmlns="http://www.w3.org/2000/svg")。
  • @potame 我在模板的开头添加了 svg 的命名空间。
  • 您可以添加当前输出的屏幕截图吗?
  • @TonyGraham。不,由于安全问题,我不能这样做:(。下一段中的文字在图像上方

标签: xsl-fo apache-fop


【解决方案1】:

根据您显示的内容,AH Formatter 将使用包含图像的fo:block 的整个页面并将下一段放在下一页上。

widthheightviewbox 属性添加到svg 元素至少可以让AH Formatter 正确调整图像大小:

<fo:instream-foreign-object width="50%" content-width="scale-to-fit">
    <svg xmlns="http://www.w3.org/2000/svg" width="1037" height="439"
        viewBox="0 0 1037 439">
        <image height="439px" width="1037px" xlink:href="test.png"
            xmlns:xlink="http://www.w3.org/1999/xlink" />
    </svg>
</fo:instream-foreign-object>

让 FOP 使用正确的图像高度可能就足够了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-27
    • 2021-09-26
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    相关资源
    最近更新 更多