Browse Source

更新tiff预览

pull/54/MERGE
陈精华 2 years ago
parent
commit
e7930a2442
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D
  1. 1621
      server/src/main/resources/static/js/UTIF.js
  2. 3189
      server/src/main/resources/static/js/tiff.min.js
  3. 107
      server/src/main/resources/web/tiff.ftl

1621
server/src/main/resources/static/js/UTIF.js

File diff suppressed because it is too large Load Diff

3189
server/src/main/resources/static/js/tiff.min.js vendored

File diff suppressed because it is too large Load Diff

107
server/src/main/resources/web/tiff.ftl

@ -4,40 +4,90 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>Tiff 图片预览</title> <title>Tiff 图片预览</title>
<link rel="stylesheet" href="css/viewer.min.css"> <link rel="stylesheet" href="css/viewer.min.css">
<script src="js/tiff.min.js"></script> <script src="js/UTIF.js"></script>
<#include "*/commonHeader.ftl"> <#include "*/commonHeader.ftl">
<style> <#if currentUrl?contains("http://") || currentUrl?contains("https://") || currentUrl?contains("file://")|| currentUrl?contains("ftp://")>
body { <#assign finalUrl="${currentUrl}">
background-color: #404040; <#else>
<#assign finalUrl="${baseUrl}${currentUrl}">
</#if>
</head>
<style type="text/css">
body{ text-align:center}
img{max-width: 100%;
margin:0 auto;
border: 2px solid #ddd;
}
</style>
<body>
<#if "false" == pdfDownloadDisable>
<!--endprint-->
<button type="button" onclick="doPrint()">打印</button>
<!--startprint-->
</#if>
<div id="tiff"></div>
<script>
let pages;
let p;
let resp;
function loadOne(e) {
UTIF.decodeImage(resp, pages[p]);
const rgba = UTIF.toRGBA8(pages[p]);
const canvas = document.createElement('canvas');
canvas.width = pages[p].width;
canvas.height = pages[p].height;
const ctx = canvas.getContext('2d');
const imageData = ctx.createImageData(canvas.width, canvas.height);
for (let i = 0; i < rgba.length; i++) {
imageData.data[i] = rgba[i];
} }
ctx.putImageData(imageData, 0, 0);
#tiff { const imgObj = document.createElement('img');
position: fixed; imgObj.src = canvas.toDataURL('image/png');
top:50%; if (++p < pages.length) {
left:50%; imgObj.onload = loadOne;
transform: translate(-50%,-50%);
} }
var myp = document.getElementById('tiff');
myp.appendChild(imgObj);
}
/*#dowebok li img { width: 200%;}*/ function imgLoaded(e) {
</style> resp = e.target.response;
</head> pages = UTIF.decode(resp);
<body> p = 0;
<input hidden id="currentUrl" value="${currentUrl}"/> loadOne();
<div id="tiff"> }
</div>
<script> function doPrint() {
var xhr = new XMLHttpRequest(); bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
initWaterMark();
window.print();
}
String.prototype.startsWithh = function(str) {
var reg = new RegExp("^" + str);
return reg.test(this);
}
String.prototype.endsWithh = function(str) {
var reg = new RegExp(str + "$");
return reg.test(this);
}
var url = '${finalUrl}';
var baseUrl = '${baseUrl}'.endsWithh('/') ? '${baseUrl}' : '${baseUrl}' + '/';
if (!url.startsWithh(baseUrl)) {
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(url);
}
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.open('GET', $("#currentUrl").val()); xhr.onload = imgLoaded;
var config = {};
config.TOTAL_MEMORY = ${initializeMemorySize};
Tiff.initialize(config)
xhr.onload = function (e) {
var tiff = new Tiff({buffer: xhr.response});
var canvas = tiff.toCanvas();
$("#tiff").append(canvas)
};
xhr.send(); xhr.send();
/*初始化水印*/ /*初始化水印*/
@ -46,5 +96,4 @@
} }
</script> </script>
</body> </body>
</html> </html>

Loading…
Cancel
Save