render pdf by page, not download all file
parent
2b5a3e89d7
commit
3e3141be80
|
@ -489,7 +489,7 @@
|
||||||
<!--GuestUploadStart--><script type="text/javascript" src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script><!--GuestUploadEnd-->
|
<!--GuestUploadStart--><script type="text/javascript" src="//cdn.bootcss.com/spark-md5/3.0.0/spark-md5.min.js"></script><!--GuestUploadEnd-->
|
||||||
<!--AliyundriveUploadJsStart--><script src="https://unpkg.com/bignumber.js@9.0.2/bignumber.js"></script>
|
<!--AliyundriveUploadJsStart--><script src="https://unpkg.com/bignumber.js@9.0.2/bignumber.js"></script>
|
||||||
<script src="https://www.unpkg.com/js-sha1@0.6.0/src/sha1.js"></script><!--AliyundriveUploadJsEnd-->
|
<script src="https://www.unpkg.com/js-sha1@0.6.0/src/sha1.js"></script><!--AliyundriveUploadJsEnd-->
|
||||||
<!--IsFileStart--><!--IspdfFileStart--><script src="//cdn.bootcss.com/pdf.js/2.3.200/pdf.min.js"></script><!--IspdfFileEnd--><!--IsFileEnd-->
|
<!--IsFileStart--><!--IspdfFileStart--><script src="https://unpkg.com/pdfjs-dist@2.13.216/build/pdf.min.js"></script><!--IspdfFileEnd--><!--IsFileEnd-->
|
||||||
<!--ListEnd-->
|
<!--ListEnd-->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function changelanguage(str)
|
function changelanguage(str)
|
||||||
|
@ -655,26 +655,63 @@
|
||||||
addVideos(["<!--FileEncodeUrl-->"]);
|
addVideos(["<!--FileEncodeUrl-->"]);
|
||||||
<!--IsvideoFileEnd-->
|
<!--IsvideoFileEnd-->
|
||||||
<!--IspdfFileStart-->
|
<!--IspdfFileStart-->
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = '//cdn.bootcss.com/pdf.js/2.3.200/pdf.worker.min.js';
|
//cdn.bootcss.com/pdf.js/2.3.200/pdf.worker.min.js
|
||||||
|
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://unpkg.com/pdfjs-dist@2.13.216/build/pdf.worker.min.js';
|
||||||
var loadingTask = pdfjsLib.getDocument({
|
var loadingTask = pdfjsLib.getDocument({
|
||||||
url: "<!--FileDownUrl-->",
|
url: "<!--FileDownUrl-->",
|
||||||
cMapUrl: "//cdn.jsdelivr.net/npm/pdfjs-dist@2.2.228/cmaps/",
|
cMapUrl: "https://unpkg.com/pdfjs-dist@2.13.216/cmaps/",
|
||||||
cMapPacked: true,
|
cMapPacked: true,
|
||||||
rangeChunkSize: 65535
|
disableStream: true,
|
||||||
|
disableAutoFetch: true,
|
||||||
|
rangeChunkSize: 65535*16
|
||||||
});
|
});
|
||||||
loadingTask.promise.then(function(pdf) {
|
loadingTask.promise.then(function(pdf) {
|
||||||
var pagenum = pdf.numPages;
|
var pagenum = pdf.numPages;
|
||||||
var pdfContainer = document.getElementById('pdf-d');
|
var pdfContainer = document.getElementById('pdf-d');
|
||||||
pdfContainer.innerHTML = '';
|
pdfContainer.innerHTML = '';
|
||||||
for (var i=1;i<=pagenum;i++) {
|
if (pagenum>5) {
|
||||||
var canvasNew = document.createElement('canvas');
|
var pagepos = 0;
|
||||||
canvasNew.id = 'pdf-c'+i;
|
for (var i=1;i<=5;i++) {
|
||||||
pdfContainer.appendChild(canvasNew);
|
var canvasNew = document.createElement('canvas');
|
||||||
renderpage(pdf,i);
|
canvasNew.id = 'pdf-c'+i;
|
||||||
|
pdfContainer.appendChild(canvasNew);
|
||||||
|
renderpage(pdf,i);
|
||||||
|
}
|
||||||
|
pagepos = i;
|
||||||
|
var pdfnextpagebutton = document.createElement('button');
|
||||||
|
pdfnextpagebutton.id = 'pdfnextpagebutton';
|
||||||
|
pdfnextpagebutton.innerText = 'Load page ' + pagepos + '-' + (pagepos+4<pagenum?pagepos+4:pagenum) + ' (' + pagenum + ')';
|
||||||
|
pdfnextpagebutton.setAttribute('onclick', "this.style.display = 'none';");
|
||||||
|
pdfContainer.appendChild(pdfnextpagebutton);
|
||||||
|
var pdfWaitNextPage = setInterval(function(){
|
||||||
|
//console.log(document.documentElement.scrollTop + ", " + document.body.scrollHeight);
|
||||||
|
if (pdfnextpagebutton.style.display=='none') {
|
||||||
|
for (var i=pagepos;i<(pagepos+5<pagenum?pagepos+5:pagenum);i++) {
|
||||||
|
var canvasNew = document.createElement('canvas');
|
||||||
|
canvasNew.id = 'pdf-c'+i;
|
||||||
|
pdfContainer.appendChild(canvasNew);
|
||||||
|
renderpage(pdf,i);
|
||||||
|
}
|
||||||
|
pagepos = i;
|
||||||
|
if (pagepos<pagenum) {
|
||||||
|
pdfnextpagebutton.innerText = 'Load page ' + pagepos + '-' + (pagepos+5<pagenum?pagepos+5:pagenum) + ' (' + pagenum + ')';
|
||||||
|
pdfnextpagebutton.style.display ='';
|
||||||
|
pdfContainer.appendChild(pdfnextpagebutton);
|
||||||
|
} else {
|
||||||
|
clearInterval(pdfWaitNextPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
for (var i=1;i<=pagenum;i++) {
|
||||||
|
var canvasNew = document.createElement('canvas');
|
||||||
|
canvasNew.id = 'pdf-c'+i;
|
||||||
|
pdfContainer.appendChild(canvasNew);
|
||||||
|
renderpage(pdf,i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function renderpage(pdf,i)
|
function renderpage(pdf,i) {
|
||||||
{
|
|
||||||
pdf.getPage(i).then(function(page) {
|
pdf.getPage(i).then(function(page) {
|
||||||
var scale = 1.5;
|
var scale = 1.5;
|
||||||
var viewport = page.getViewport({ scale: scale, });
|
var viewport = page.getViewport({ scale: scale, });
|
||||||
|
|
Loading…
Reference in New Issue