web js pdf

bei_fang_du_lang發表於2017-10-16
InputStream is = new FileInputStream(temp); // 在InputRepresentation中會關閉流
			Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
			// disposition.setFilename(URLEncoder.encode(bean.getName()));
			MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
			if(isOpenFile){
				FileType fileType = FileType.parse(bean.getType());
				if(fileType.isPDFFile()){
					mediaType = MediaType.APPLICATION_PDF;
				} else if(fileType.isOfficeFile()){
					if(bean.getType().contains("do")){
						mediaType = MediaType.APPLICATION_WORD;
					} else if(bean.getType().contains("xls")){
						mediaType = MediaType.APPLICATION_EXCEL;
					}else if(bean.getType().contains("ppt")){
						mediaType = MediaType.APPLICATION_POWERPOINT;
					}
				} else if(fileType.isTextFile()){
					mediaType = MediaType.APPLICATION_TEX;
				}
			}
			Representation rep = new InputRepresentation(is, mediaType, temp.length()) {
				@Override
				public void release() {
					super.release();
					if (temp.delete()) {
						logger.debug("臨時檔案" + temp.getName() + "已經被刪除");
					} else {
						logger.debug("臨時檔案" + temp.getName() + "未被刪除");
					}
				}
			};
			if(mediaType == MediaType.APPLICATION_OCTET_STREAM){
				rep.setDisposition(disposition);
			}
			rep.setModificationDate(new Date(bean.getModifyTime()));
			rep.setTag(new Tag(bean.getMd5Code()));
			return rep;

<embed type="application/pdf" src="/bi/api/files/root/調查報告/2012function.pdf?openFile=1" id="pdfblock" style="width: 1900px; height: 591px;" width="1900" height="591">

相關文章