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"/>
<title>Tiff 图片预览</title>
<link rel="stylesheet" href="css/viewer.min.css">
<script src="js/tiff.min.js"></script>
<script src="js/UTIF.js"></script>
<#include "*/commonHeader.ftl">
<style>
body {
background-color: #404040;
<#if currentUrl?contains("http://") || currentUrl?contains("https://") || currentUrl?contains("file://")|| currentUrl?contains("ftp://")>
<#assign finalUrl="${currentUrl}">
<#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];
}
#tiff {
position: fixed;
top:50%;
left:50%;
transform: translate(-50%,-50%);
ctx.putImageData(imageData, 0, 0);
const imgObj = document.createElement('img');
imgObj.src = canvas.toDataURL('image/png');
if (++p < pages.length) {
imgObj.onload = loadOne;
}
var myp = document.getElementById('tiff');
myp.appendChild(imgObj);
}
/*#dowebok li img { width: 200%;}*/
</style>
</head>
<body>
<input hidden id="currentUrl" value="${currentUrl}"/>
<div id="tiff">
</div>
function imgLoaded(e) {
resp = e.target.response;
pages = UTIF.decode(resp);
p = 0;
loadOne();
}
<script>
var xhr = new XMLHttpRequest();
function doPrint() {
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.open('GET', $("#currentUrl").val());
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.onload = imgLoaded;
xhr.send();
/*初始化水印*/
@ -46,5 +96,4 @@
}
</script>
</body>
</html>

Loading…
Cancel
Save