2017-03-10 32 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

我認爲主要的問題是由您添加「附件」引起的到標題,只需刪除它。