如何在使用XSLT FOP渲染我的PDF时插入和调整重叠的图像。

huangapple go评论71阅读模式
英文:

How to Insert and adjust over lapping images While Rendering My PDF Using XSLT FOP

问题

我想在我的PDF中显示两张图片,它们将位于相同的位置,重叠在一起;或者说一张图片将成为另一张图片/标志的背景,所以我尝试了下面的代码:

<fo:table table-layout="fixed" width="100%">
  <fo:table-column column-width="proportional-column-width(4.5)"/>
  <fo:table-column column-width="proportional-column-width(1)"/>
   <fo:table-body>
    <fo:table-row>
      <fo:table-cell column-number="2">
        <fo:block-container background-image="file:///{$Logo}/Image2.png">
        <fo:block>
         <fo:external-graphic  src="file:///{$Logo}/Image1.png" content-height="16mm" content-width="45mm" scaling="non-uniform"/>
        </fo:block>
       </fo:block-container>
      </fo:table-cell>
     </fo:table-row>
    </fo:table-body>
 </fo:table>

现在,Image2作为Image1的背景显示出来了,但我需要调整Image2的大小或位置;我可以使用哪些属性?

例如,假设:

  1. Image2应该显示在中间,即Image1的中心。
  2. 想要减小Image2的高度和长度。

我该如何做到这些?

我使用的方法是否正确,还是应该使用其他方法?

英文:

I want to display two images at the same position in my pdf where they will be overlapping to each other; or likely one image will be back ground of another image/logo so I tried below code:

&lt;fo:table table-layout=&quot;fixed&quot; width=&quot;100%&quot;&gt;
  &lt;fo:table-column column-width=&quot;proportional-column-width(4.5)&quot;/&gt;
  &lt;fo:table-column column-width=&quot;proportional-column-width(1)&quot;/&gt;
   &lt;fo:table-body&gt;
    &lt;fo:table-row&gt;
      &lt;fo:table-cell column-number=&quot;2&quot;&gt;
        &lt;fo:block-container background-image=&quot;file:///{$Logo}/Image2.png&quot;&gt;
        &lt;fo:block&gt;
         &lt;fo:external-graphic  src=&quot;file:///{$Logo}/Image1.png&quot; content-height=&quot;16mm&quot; content-width=&quot;45mm&quot; scaling=&quot;non-uniform&quot;/&gt;
        &lt;/fo:block&gt;
       &lt;/fo:block-container&gt;
      &lt;/fo:table-cell&gt;
     &lt;/fo:table-row&gt;
    &lt;/fo:table-body&gt;
 &lt;/fo:table&gt;

Now that Image2 is coming as back ground for Image1 but I need to resize or fix the position for Image2 ; what all property I can use?

For example lets say

  1. Image2 should came in the middle/in the center as the Image1 back ground.
  2. Want to decrease the height and length of Image2.
    How i can do all these things?

Is this the correct approach I am using or should I used any other approach ?

答案1

得分: 1

你可以使用 background-position 来定位背景图像(参见 https://www.w3.org/TR/xsl11/#background-position)。

XSL-FO示例集中有一个关于 background-position 的示例(https://www.antennahouse.com/xsl-fo-sample),可在 https://www.antennahouse.com/hubfs/xsl-fo-sample/structure/background-position-1.pdf 获取,但请注意,XSL 1.1 仅允许在另一个长度上使用长度,百分比上使用百分比,以及关键字上使用关键字。

XSL 1.1 没有用于调整背景图像大小的属性。FOP 提供了用于背景图像宽度和高度的扩展属性(参见 https://xmlgraphics.apache.org/fop/2.8/extensions.html#backgroundimages),但我从未尝试过它们。

英文:

You can position the background image using background-position (see https://www.w3.org/TR/xsl11/#background-position).

There's a background-position sample from the XSL-FO Samples Collection (https://www.antennahouse.com/xsl-fo-sample) available at https://www.antennahouse.com/hubfs/xsl-fo-sample/structure/background-position-1.pdf, but be aware that XSL 1.1 only allows a length to be used with another length, a percentage to be used with a percentage, and a keyword to be used with a keyword.

XSL 1.1 doesn't have a property for sizing the background image. FOP has extension properties for background image width and height (see https://xmlgraphics.apache.org/fop/2.8/extensions.html#backgroundimages), but I've never tried them.

huangapple
  • 本文由 发表于 2023年6月5日 20:22:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定