1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

Automatically reload the pdf if there is a new signature

This commit is contained in:
Vincent LAURENT 2022-04-15 00:47:36 +02:00
parent 39380bd641
commit ebf7e0e889
2 changed files with 26 additions and 4 deletions

View File

@ -16,9 +16,10 @@ var menu = null;
var menuOffcanvas = null;
var currentCursor = null;
var signaturePad = null;
var nblayers = null;
var loadPDF = async function(pdfBlob, filename) {
let pdfjsLib = window['pdfjs-dist/build/pdf'];
const pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.js?legacy';
let url = await URL.createObjectURL(pdfBlob);
@ -37,7 +38,7 @@ var loadPDF = async function(pdfBlob, filename) {
if(document.getElementById('input_pdf_share')) {
document.getElementById('input_pdf_share').files = dataTransfer.files;
}
var loadingTask = pdfjsLib.getDocument(url);
let loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {
if(pdf.numPages > maxPage) {
@ -156,6 +157,23 @@ var loadPDF = async function(pdfBlob, filename) {
});
};
var reloadPDF = async function(url) {
const pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.js?legacy';
pdfjsLib.getDocument(url).promise.then(function(pdf) {
for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
pdf.getPage(pageNumber).then(function(page) {
page.render({
canvasContext: document.getElementById('canvas-pdf-' + (page.pageNumber - 1)).getContext('2d'),
viewport: page.getViewport({scale: currentScale}),
enhanceTextSelection: true
});
});
}
});
}
var is_mobile = function() {
return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none");
};
@ -994,7 +1012,11 @@ var updateNbLayers = function() {
xhr.open('GET', '/signature/'+hash+'/nblayers', true);
xhr.onload = function() {
if (xhr.status == 200) {
let nblayers = xhr.response;
let newNblayers = xhr.response;
if(nblayers !== null && nblayers != newNblayers) {
reloadPDF('/signature/'+hash+'/pdf');
}
nblayers = newNblayers;
document.querySelectorAll('.nblayers').forEach(function(item) {
item.innerHTML = nblayers;
});

View File

@ -247,6 +247,6 @@
hash = "<?php echo $hash ?>";
<?php endif; ?>
</script>
<script src="/js/signature.js?202204141030"></script>
<script src="/js/signature.js?202204150047"></script>
</body>
</html>