Commit 4211c6e0 authored by chase's avatar chase

merge 档案管理

parent 0b7018c3
......@@ -36,6 +36,7 @@ import pwc.taxtech.atms.vat.entity.FileUpload;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
......@@ -122,44 +123,76 @@ public class TaxDocumentController {
*/
@PostMapping("/previewPDF")
@ResponseBody
public void previewPDF(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
// return taxDocumentService.previewPDF2(response,taxDocumentDto.getPath());
taxDocumentService.previewPDF(response,taxDocumentDto.getPath());
/*InputStream is = null;
ByteArrayOutputStream os = null;
public String previewPDF(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
return taxDocumentService.previewPDF2(response,taxDocumentDto.getPath());
}
// /**
// * 读取PDF 转换为图片
// *
// */
// @PostMapping("/previewPDF3")
// @ResponseBody
// public void previewPDF3(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
// OutputStream outputStream = null;
// InputStream in = null;
// try {
// in = taxDocumentService.getInputStreamByUrl(taxDocumentDto.getPath());
// response.setHeader("Content-Disposition", "attachment;fileName=test.pdf");
// response.setContentType("multipart/form-data");
// outputStream = response.getOutputStream();
// IOUtils.write(IOUtils.toByteArray(in), outputStream);
// } catch (IOException e) {
// e.printStackTrace();
// throw new RuntimeException("PDF转换失败");
// } finally {
// try {
// in.close();
// } catch (IOException e) {
// throw new RuntimeException("PDF转换失败");
// }
// try {
// outputStream.close();
// } catch (IOException e) {
// throw new RuntimeException("PDF转换失败");
// }
// }
// }
/**
* 读取PDF 转换为图片
*
*/
@PostMapping("/previewPDF2")
@ResponseBody
public void previewPDF2(HttpServletResponse response ,@RequestBody TaxDocumentDto taxDocumentDto) {
OutputStream outputStream = null;
InputStream is = null;
try {
//根据url地址 获取文件输入流
is = getInputStreamByUrl(taxDocumentDto.getPath());
os = new ByteArrayOutputStream();
outputStream = response.getOutputStream();
byte[] buff = new byte[1024];
int len = 0;
String dUrlData="";
int len;
is = taxDocumentService.getInputStreamByUrl(taxDocumentDto.getPath());
while ((len = is.read(buff)) != -1) {
os.write(buff, 0, len);
outputStream.write(buff, 0, len);
}
//刷新此输出流并强制写出所有缓冲的输出字节,必须这行代码,否则有可能有问题
os.flush();
os.toByteArray();
dUrlData= Base64.encode(os.toByteArray());
return dUrlData;
} catch (Exception e) {
e.printStackTrace();
return null;
}finally {
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException("PDF转换失败");
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF转换失败");
}
try {
os.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF转换失败");
}
}*/
}
}
}
@RequestMapping("exportExcel")
@ResponseBody
public void exportExcelFile(HttpServletResponse response, @RequestBody TaxDocumentDto taxDocumentDto) {
......
......@@ -1231,10 +1231,9 @@ public class TaxDocumentServiceImpl {
while ((len = is.read(buff)) != -1) {
os.write(buff, 0, len);
}
os.flush();
os.toByteArray();
dUrlData = Base64.getEncoder().encodeToString(os.toByteArray());
os.flush();
} catch (IOException e) {
log.error(e.getMessage());
throw new RuntimeException("pdf转换错误");
......
......@@ -25547,6 +25547,8 @@
}
function createBuiltInCMap(name, builtInCMapParams) {
builtInCMapParams={ url: 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/',
packed: true};
if (name === 'Identity-H') {
return new IdentityCMap(false, 2);
} else if (name === 'Identity-V') {
......@@ -1593,13 +1593,13 @@ taxDocumentManageModule.directive('pdfPreview', function () {
restrict: 'EA',
controller: ['$scope','taxDocumentListService', function ($scope,taxDocumentListService) {
window.PDFJS.workerSrc = './bundles/pdf.worker.js';
// var canvas = document.getElementById('the-canvas');
// var context = canvas.getContext('2d');
// var pdfCurPageIndex = 1;
// var pdfSumPages = 1;
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
var pdfCurPageIndex = 1;
var pdfSumPages = 1;
var container = document.getElementById("pdfLayoutDialog");
// var pdfPromise = null;
// var cacheUrl = null;
var pdfPromise = null;
var cacheUrl = null;
$scope.openPdfPreviewPop_bak = function (url) {
container.style.display = "block";
if (cacheUrl !== url) {
......@@ -1610,32 +1610,37 @@ taxDocumentManageModule.directive('pdfPreview', function () {
renderPdf(pdf)
})
};
$scope.openPdfPreviewPop = function (url)
{
var params={path:url};
taxDocumentListService.readPDF(params).then(function (data, status, headers) {
if(status===204){
SweetAlert.warning("没有数据可以下载");
return;
$scope.openPdfPreviewPop = function (url) {
container.style.display = "block";
function start() {
return new Promise(function (resolve, reject){
resolve('start');
});
}
start().then(function(data) {
console.log('result of start: ', data);
return taxDocumentListService.readPDF({path:url});
}).then(function(dataURL) {
var pdfData=null;
if(typeof dataURL =="string"){
pdfData = convertDataURIToBinary(dataURL);
}
container.style.display = "block";
var blob=data;
var img = document.createElement('img');
var myBlob = new window.Blob([blob], {type: 'image/png'});
console.log(myBlob);
var qrUrl = window.URL.createObjectURL(myBlob);
img.src = qrUrl;
img.onload = function () {
window.URL.revokeObjectURL(qrUrl);
$("div.busy-indicator-container").removeClass("busy-indicator-container");
$(".TDL-content-container")[0].style.display="none";
$(".TDL-header")[0].style.display="none";
$(".navbar-custom-top")[0].style.display="none";
container.append(img);
console.log(pdfData);
return window.PDFJS.getDocument({data:pdfData});
}).then(function(data) {
pdfSumPages = data.numPages;
return data.getPage(pdfCurPageIndex);
}).then(function(page){
var scale = 1.5;
var viewport = page.getViewport(scale);
canvas.height = viewport.height;
canvas.width = viewport.width;
var renderContext = {
canvasContext: context,
viewport: viewport
};
},function () {
SweetAlert.error($translate.instant('PleaseContactAdministrator'));
})
page.render(renderContext);
});
};
function convertDataURIToBinary(dataURI) { //将encodeBase64解码
var raw = window.atob(dataURI);
......
......@@ -306,8 +306,6 @@
}
.TDL-pdf-layout-dialog {
text-align: center;
float: top;
display: none;
}
......@@ -1483,10 +1481,14 @@
</div>
</div>
<div class="TDL-pdf-layout-dialog" id="pdfLayoutDialog" pdf-preview>
<div id="pdfContainer" style="width:0px;height:0px;overflow: hidden;">
<div class="TDL-pdf-layout-dialog" id="pdfLayoutDialog" pdf-preview>
<div class="wrapper TDL-pdf-preview-pop" id="pdfContainer">
<canvas id="the-canvas"></canvas>
</div>
<button class="TDL-pdf-preview-pop-close-btn" ng-click="closePdfPop()">×</button>
<button class="TDL-pdf-paging-btn TDL-pdf-paging-btn-prev" ng-click="prevPaging()" title="上一页">&lt;</button>
<button class="TDL-pdf-paging-btn TDL-pdf-paging-btn-next" ng-click="nextPaging()" title="下一页">&gt;</button>
</div>
<div class="modal fade" id="imgLayoutDialog" img-preview tabindex="-1" role="dialog" aria-labelledby="myModal"
......
......@@ -134,21 +134,7 @@ taxDocumentManageModule.factory('taxDocumentListService',
return jqFetch.post(apiInterceptor.webApiHostUrl + '/taxDoc/previewExcelToJson', params);
},
readPDF:function(params){
$('#busy-indicator-container').show();
var defer = $q.defer();
var xhr = new XMLHttpRequest();
xhr.onload = function(result) {
if (this.status == 200) {
var blob = this.response;
defer.resolve(blob,xhr.status,xhr.getAllResponseHeaders());
}
};
xhr.open("post", apiInterceptor.webApiHostUrl + "/taxDoc/previewPDF", true);
xhr.setRequestHeader("Authorization", apiInterceptor.tokenType + ' ' + apiInterceptor.apiToken());
xhr.setRequestHeader("Content-Type", 'application/json;charset=UTF-8');
xhr.responseType="blob";
xhr.send(JSON.stringify(params));
return defer.promise;
return jqFetch.post(apiInterceptor.webApiHostUrl + '/taxDoc/previewPDF', params);
},
getBinaryData:function(url){
var defer = $q.defer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment