我正在尝试将一个图像包含到一个pdf中,它是通过XSL使用Apache生成的。我读过关于标记<fo:external-graphic>的文章,当图像存储在本地驱动器上或请求物理驻留在任何服务器上的图像时,它工作得很好。但是我需要的是在pdf中显示一个图像(codebar映像),它是由jsp动态生成的,也就是说,java生成映像,它永远不会存储在硬盘上。
图像是由jsp正确生成的,因为它显示在我的浏览器上。问题是,图像没有显示在pdf中,只有大的空白,而不是codebar图像。
也就是说,像这样的东西工作得很好:
<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而不是image,这就是为什么pdf不显示图像。但是,如何才能只获得http://website.com/codebarGenerator.jsp生成的映像而不将其存储在硬盘中呢?
发布于 2014-07-16 10:28:32
我也面临着同样的问题,我张贴了关于这个Here。我使用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());来使用这个转换器。
https://stackoverflow.com/questions/24768480
复制相似问题