Java 图像未显示在pdf上

Java 图像未显示在pdf上,java,image,jsp,pdf-generation,xsl-fo,Java,Image,Jsp,Pdf Generation,Xsl Fo,我试图将一个图像包含到pdf中,该pdf是使用ApacheCook通过XSL生成的。我读过有关标签的内容,当图像存储在本地驱动器上或当您请求物理上驻留在任何服务器上的图像时,该标签可以正常工作。但我需要的是在pdf中显示一个由jsp动态生成的图像代码条图像,也就是说,java生成图像,并且它永远不会存储在硬盘上 该图像由jsp正确生成,因为它显示在我的浏览器上。问题是图像没有显示在pdf中,只有大的空白而不是代码条图像 也就是说,类似这样的方法很好: <fo:external-graphi

我试图将一个图像包含到pdf中,该pdf是使用ApacheCook通过XSL生成的。我读过有关标签的内容,当图像存储在本地驱动器上或当您请求物理上驻留在任何服务器上的图像时,该标签可以正常工作。但我需要的是在pdf中显示一个由jsp动态生成的图像代码条图像,也就是说,java生成图像,并且它永远不会存储在硬盘上

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

也就是说,类似这样的方法很好:

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


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

我也面临着与我发布的相同的问题。我用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.setURIResolvernew PdfURIResolver使用此解析器

您确定您拥有JSP上的所有参数吗?如。。。该JSP是否只是返回一些罐装或随机条形码,或者您是否缺少实际生成特定条形码的参数?如果你没有发送所有的信息,它当然不会返回任何信息,你也不会得到任何信息。是的,实际上jsp生成了一个特定的条形码,只是为了测试,所以它不需要任何参数。如上所述,在浏览器上正确显示条形码图像。
response.setContentType("image/jpg"); 
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;
}
}