Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

xml - XSL-FO external-graphic not showing

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...