pdf.js展示流檔案
阿新 • • 發佈:2018-12-30
- 把viewer.js中的var DEFAULT_URL刪除
- viewer.html 中新增 DEFAULT_URL 把地址改成流的地址,切記viewer.js在最後
<!-- This snippet is used in production (included from viewer.html) -->
<link rel="resource" type="application/l10n" href="locale/locale.properties">
<script src="l10n.js"></script>
<script src ="../build/pdf.js"></script>
<script src="debugger.js"></script>
<script src="jquery-1.7.1.js"></script>
<script type="text/javascript" language="javascript">
//原來viewer.js裡面的引數現在,放.do
var DEFAULT_URL = 'pdf/pdfio';
//獲取url裡面的引數
function GetRequest() {
var url = location.search; //獲取url中"?"符後的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var req = GetRequest();
var from = req['from'];
alert(from);
</script>
<script src="viewer.js"></script>
4.後臺程式碼
OutputStream os=null;
//本地檔案地址
File fff = new File("D:/111.pdf");
FileInputStream fileInputStream = new FileInputStream(fff);
String fileName = URLEncoder.encode("111.pdf", "UTF-8");
response.setHeader("Content-Disposition", "filename=" + fileName);
//response.setHeader("Content-disposition","filename=" + new String("證明檔案.pdf".getBytes("GB2312"), "ISO-8859-1"));// 設定輸出檔案頭
response.setContentType("application/pdf;charset=UTF-8");// 定義輸出型別
OutputStream out = response.getOutputStream();
//寫檔案
int b;
while((b=fileInputStream.read())!= -1)
{
out.write(b);
}
fileInputStream.close();
out.close();