2021-05-04 00:30:20 +02:00
<! doctype html >
< html lang = " fr_FR " >
< head >
<!-- Required meta tags -->
< meta charset = " utf-8 " >
< meta name = " viewport " content = " width=device-width, initial-scale=1 " >
2021-09-21 19:19:56 +02:00
2021-09-22 00:21:35 +02:00
< link href = " /vendor/bootstrap.min.css?5.1.1 " rel = " stylesheet " >
< link href = " /vendor/bootstrap-icons.css?1.5.0 " rel = " stylesheet " >
2021-05-04 00:30:20 +02:00
< title > Signature PDF </ title >
</ head >
< body >
< div class = " px-4 py-5 my-5 text-center " >
< h1 class = " display-5 fw-bold " >< i class = " bi bi-vector-pen " ></ i > Signer un PDF </ h1 >
< div class = " col-lg-3 mx-auto " >
2021-11-12 02:24:28 +01:00
< div class = " col-12 " >
< label for = " input_pdf_upload " class = " form-label " > Choisir un PDF </ label >
< input id = " input_pdf_upload " class = " form-control form-control-lg " type = " file " accept = " .pdf,application/pdf " >
2021-11-12 10:10:32 +01:00
< p class = " mt-1 opacity-50 " >< small class = " text-muted " > Le PDF ne doit pas dépasser < ? php echo round ( $maxSize / 1024 / 1024 ) ?> Mo et faire plus de <?php echo $maxPage ?> pages</small></p>
2021-11-12 02:24:28 +01:00
< a class = " btn btn-sm btn-link opacity-75 " href = " /#https://raw.githubusercontent.com/24eme/signaturepdf/master/tests/files/document.pdf " > Tester avec un PDF de démo </ a >
</ div >
2021-05-04 00:30:20 +02:00
</ div >
</ div >
2021-11-08 01:24:25 +01:00
< footer class = " text-center text-muted mb-2 fixed-bottom " >
< small > Logiciel libre sous license AGPL - 3.0 : < a href = " https://github.com/24eme/signaturepdf " > voir le code source </ a ></ small >
</ footer >
2021-09-21 19:19:56 +02:00
2021-09-22 00:21:35 +02:00
< script >
2021-11-12 01:49:23 +01:00
( async function () {
const cache = await caches . open ( 'pdf' );
var key = " <?php echo $key ?> " ;
2021-11-12 02:24:28 +01:00
var urlPdf = '/' + key + '/pdf' ;
var urlSignature = '/' + key ;
2021-11-12 01:49:23 +01:00
var pdfHistory = {};
2021-11-12 02:24:28 +01:00
var maxSize = < ? php echo $maxSize ?> ;
2021-11-12 01:49:23 +01:00
if ( localStorage . getItem ( 'pdfHistory' )) {
pdfHistory = JSON . parse ( localStorage . getItem ( 'pdfHistory' ));
2021-11-02 01:18:13 +01:00
}
2021-11-12 01:49:23 +01:00
document . getElementById ( 'input_pdf_upload' ) . addEventListener ( 'change' , async function ( event ) {
2021-11-12 02:24:28 +01:00
if ( document . getElementById ( 'input_pdf_upload' ) . files [ 0 ] . size > maxSize ) {
2021-11-08 01:25:09 +01:00
2021-11-12 09:03:35 +01:00
alert ( " Le PDF ne doit pas dépasser <?php echo round( $maxSize / 1024 / 1024) ?> Mo " );
2021-11-12 02:24:28 +01:00
document . getElementById ( 'input_pdf_upload' ) . value = " " ;
return ;
}
var response = new Response ( document . getElementById ( 'input_pdf_upload' ) . files [ 0 ], { " status " : 200 , " statusText " : " OK " });
await cache . put ( urlPdf , response );
2021-11-12 01:49:23 +01:00
pdfHistory [ key ] = { filename : document . getElementById ( 'input_pdf_upload' ) . files [ 0 ] . name }
localStorage . setItem ( 'pdfHistory' , JSON . stringify ( pdfHistory ));
2021-11-12 02:24:28 +01:00
document . location = urlSignature ;
2021-11-12 01:49:23 +01:00
});
async function uploadFromUrl ( url ) {
var response = await fetch ( url );
if ( response . status != 200 ) {
return ;
}
var pdfBlob = await response . blob ();
if ( pdfBlob . type != 'application/pdf' && pdfBlob . type != 'application/octet-stream' ) {
return ;
}
var dataTransfer = new DataTransfer ();
var filename = url . replace ( /^.* \ //, '');
dataTransfer . items . add ( new File ([ pdfBlob ], filename , {
type : 'application/pdf'
}));
document . getElementById ( 'input_pdf_upload' ) . files = dataTransfer . files ;
document . getElementById ( 'input_pdf_upload' ) . dispatchEvent ( new Event ( " change " ));
history . replaceState ({}, " Signature de PDF " , " / " );
}
if ( window . location . hash ) {
uploadFromUrl ( window . location . hash . replace ( /^ \ #/, ''));
}
window . addEventListener ( 'hashchange' , function () {
uploadFromUrl ( window . location . hash . replace ( /^ \ #/, ''));
})
})();
2021-09-21 18:22:43 +02:00
</ script >
2021-05-04 00:30:20 +02:00
</ body >
</ html >