2017-03-10 33 views
0

我想有一个动态生成的PDF显示成一个iframe,我可以成功调用的iframe内的servlet,如下所示:如何注入一个动态生成的PDF成GWT IFRAME

Frame frame = new Frame(); 
frame.setUrl(downloadUrl); 

其中“downloadUrl”是一个包含servlet地址和参数的字符串。问题是,在过程结束时,我被问到是否要下载pdf文件,并且iframe保持空白。

这是servlet

//the pdf file 
byte[] outArray = null; 

[...] 

response.setContentType("application/pdf"); 
response.setHeader("Content-Disposition", "attachment;filename=Customer_Print.pdf"); 

[...] 

outArray = functionToGeneratePdfFile(); 

if (outArray != null) { 
OutputStream outStream = response.getOutputStream(); 
outStream.write(outArray); 
outStream.flush(); 
} 

任何暗示相关的部分? 在此先感谢

SOLUTION:

好吧,我能够通过改变下列方式标题中获得iframe中预览:

response.setHeader("Content-Disposition: inline", "filename=Customer_Print.pdf"); 
+1

你检查出http://stackoverflow.com/questions/12974115/how-to-open-a-pdf-file-in-an-iframe?可能你需要使用一些pdf渲染器 – Tobika

回答

1

我认为主要的问题是由您添加“附件”引起的到标题,只需删除它。