图像未显示在pdf上 [英] Image not displayed on pdf

查看:141
本文介绍了图像未显示在pdf上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像包含到使用Apache Cocoon通过 XSL 生成的pdf中。我已经阅读了标签< fo:external-graphic> ,当图像存储在本地驱动器上或者请求物理上存在的图像时,它可以正常工作任何服务器。但我需要的是在pdf中显示一个由 jsp 生成的图像(代码栏图像),也就是说, java 生成图像,它永远不会存储在硬盘上。

I'm trying to include an image into a pdf wich is generated via XSL using Apache Cocoon. I've read about the tag <fo:external-graphic> wich works fine when a image is stored on the local drive or when you request an image wich resides physically on any server. But what i need is to show in the pdf an image (codebar image) wich is generated dinamically by a jsp, that is to say, java generates the image and it will never be stored on the hard drive.

图像是由jsp正确生成的,因为它在我的浏览器上显示。问题是图像没有显示在 pdf 中,只有大的空格而不是代码栏图像。

The image is generated correctly by the jsp since it is showed on my browser. The problem is that the image is not shown in the pdf there is only big white space instead of the codebar image.

也就是说,这样的工作正常:

That is, something like these works fine:

<fo:external-graphic src="http://website.com/codebar.jpg" content-width="3cm" content-height="3cm"></fo:external-graphic>

<fo:external-graphic src="c:\Archivos de Programa\codebar.jpg" content-width="3cm" content-height="3cm"></fo:external-graphic>

但我需要工作的是:

<fo:external-graphic src="http://website.com/codebarGenerator.jsp" content-width="3cm" content-height="3cm"></fo:external-graphic>

响应标头设置正确:

response.setContentType("image/jpg"); 

编辑

我认为问题可能是,我试图插入 html 而不是图像和这就是pdf不显示图像的原因。但是,如何才能获得 http://website.com/codebarGenerator.jsp 生成的图像而不将其存储在硬盘中?

I think the problem, may be, is that i´m trying to insert html instead of an image and that is why the pdf does not display the image. But, how can i get only the image generated by http://website.com/codebarGenerator.jsp without storing it in the hard drive?

推荐答案

我也面临着与此相关的问题这里。我通过使用 URIResolver 来解决这个问题。

I am also facing the same issue I posted about this Here. I solved this by using URIResolver.

您也可以尝试这样做:

public class PdfURIResolver implements URIResolver{
@Override
public Source resolve(String href, String base) throws TransformerException {
    Source source = null;       
    try 
    {       
        //Image to InputStream conversion code here,
       //assign that InputStream to 'source' using source = new StreamSource(InputStream );         

    } 
    catch (Exception e) 
    {
        //exception handling
    }
    finally
    {
        //resourse closing if needed.
    }
    return source;
}
}

你必须告诉FOP工厂使用这个解析器 fopFactory.setURIResolver(new PdfURIResolver());

You have to tell FOP factory to use this Resolver using fopFactory.setURIResolver(new PdfURIResolver());

这篇关于图像未显示在pdf上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆