fo:instream-foreign-object does not show the image

2019-06-14 05:24发布

问题:

I use the below code to show a PNG image in PDF. I use <fo:instream-foreign-object> because <fo:external-graphic> does not fulfil my requirement to show a image. Refer to issue 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>

With the above use, I am not able to get the picture in the document. The image is not properly placed in the page and the text in the next paragraph is overlay on top of it. Please suggest how to achieve it.

回答1:

With what you show, AH Formatter will use the whole page for the fo:block containing the image and put the next paragraph on the next page.

Adding width, height, and viewbox attributes to the svg element lets AH Formatter, at least, size the image properly:

<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>

It may be enough to let FOP use the correct height for the image.