XSL-FO external-graphic not showing

余生颓废 提交于 2019-11-28 09:27:45

问题


I'm having some issues getting the external-graphic to show in my PDF. I've tried using all sorts of paths using the url() but nothing seems to work. Is it something else I'm missing?

<fo:table-cell>
    <fo:block>
        <fo:external-graphic src="url(ss/naam.png)"></fo:external-graphic>
    </fo:block>
</fo:table-cell>

回答1:


I am using Apache FOP 1.1 Ver.

first you should tell apache FOP that where is base path in follwing way. You should copy code as it is.

    fopFactory = FopFactory.newInstance();
    // for image base URL : images from Resource path of project
    String serverPath = request.getSession().getServletContext().getRealPath("/");
    fopFactory.setBaseURL(serverPath);
    // for fonts base URL :  .ttf from Resource path of project
    fopFactory.getFontManager().setFontBaseURL(serverPath);

In your XSL template file

<fo:table-cell>
    <fo:block>
        <fo:external-graphic src="url(resources/naam.png)"></fo:external-graphic>
    </fo:block>
</fo:table-cell>

Here naam.png will be in resources/ directory

I added all images and required font font files in resource director of my project. It is working fine for me. Thank you




回答2:


To add a <fo:external-graphic> for an absolute path the only way it worked for me is to write the url as url(file:/C:/myPath/image.jpg). Source.

<fo:external-graphic src="url(file:/C:/myPath/image.jpg)"/>



回答3:


Example, it runs in my xls-fo template for Apache FOP.

<fo:external-graphic src='url("src/main/resources/ima/logo.depo.gif")' />



回答4:


<fo:external-graphic src="ss/naam.png"/>

Works for me this way.



来源:https://stackoverflow.com/questions/13267951/xsl-fo-external-graphic-not-showing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!