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

Merge branch 'metadata' of github.com:24eme/signaturepdf into metadata

This commit is contained in:
Gabriel Poma 2023-04-20 15:55:58 +02:00
commit c30c89ad60
6 changed files with 48 additions and 21 deletions

View File

@ -355,8 +355,6 @@ $f3->route('POST /organize',
$f3->route('GET /metadata', $f3->route('GET /metadata',
function($f3) { function($f3) {
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
echo View::instance()->render('metadata.html.php'); echo View::instance()->render('metadata.html.php');
} }
); );

View File

@ -9,3 +9,6 @@ PDF_STORAGE_PATH=/path/to/folder
; Manage demo link pdf : true (by default, show), false (hide), or custom link ; Manage demo link pdf : true (by default, show), false (hide), or custom link
;PDF_DEMO_LINK=true ;PDF_DEMO_LINK=true
; Metadata default fields
;METADATA_DEFAULT_FIELDS[metadata_key].type = "text"

View File

@ -35,18 +35,23 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
await loadingTask.promise.then(function(pdf) { await loadingTask.promise.then(function(pdf) {
pdf.getMetadata().then(function(metadata) { pdf.getMetadata().then(function(metadata) {
console.log(metadata); console.log(metadata);
for(fieldKey in defaultFields) {
addMetadata(fieldKey, null, defaultFields[fieldKey]['type'], false);
}
for(metaKey in metadata.info) { for(metaKey in metadata.info) {
if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") { if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") {
continue; continue;
} }
addMetadata(metaKey, metadata.info[metaKey]); addMetadata(metaKey, metadata.info[metaKey], "text", false);
} }
for(metaKey in metadata.info.Custom) { for(metaKey in metadata.info.Custom) {
if(metaKey == "sha256") { if(metaKey == "sha256") {
continue; continue;
} }
addMetadata(metaKey, metadata.info.Custom[metaKey]); addMetadata(metaKey, metadata.info.Custom[metaKey], "text", false);
} }
for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
@ -56,6 +61,11 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
pageRender(pageIndex); pageRender(pageIndex);
}); });
} }
if(document.querySelector('.input-metadata input')) {
document.querySelector('.input-metadata input').focus();
} else {
document.getElementById('input_metadata_key').focus();
}
}); });
}, function (reason) { }, function (reason) {
console.error(reason); console.error(reason);
@ -91,12 +101,26 @@ var pageRender = async function(pageIndex) {
}); });
} }
var addMetadata = function(key, value) { var addMetadata = function(key, value, type, focus) {
let input = document.querySelector('.input-metadata input[name="'+key+'"]');
if(input && input.value === null) {
input.value = value;
}
if(input && focus) {
input.focus();
}
if(input) {
return;
}
let div = document.createElement('div'); let div = document.createElement('div');
div.classList.add('form-floating', 'mt-3', 'input-metadata'); div.classList.add('form-floating', 'mt-3', 'input-metadata');
let input = document.createElement('input'); input = document.createElement('input');
input.value = value; input.value = value;
input.type = type;
input.name = key;
input.classList.add('form-control'); input.classList.add('form-control');
let label = document.createElement('label'); let label = document.createElement('label');
@ -111,7 +135,9 @@ var addMetadata = function(key, value) {
div.appendChild(deleteButton); div.appendChild(deleteButton);
document.getElementById('form-metadata-container').appendChild(div); document.getElementById('form-metadata-container').appendChild(div);
input.focus(); if(focus) {
input.focus();
}
} }
const deleteMetadata = function(el) { const deleteMetadata = function(el) {
@ -158,7 +184,7 @@ const save = async function () {
var createEventsListener = function() { var createEventsListener = function() {
document.getElementById('form_metadata_add').addEventListener('submit', function(e) { document.getElementById('form_metadata_add').addEventListener('submit', function(e) {
let formData = new FormData(this); let formData = new FormData(this);
addMetadata(formData.get('metadata_key'), ""); addMetadata(formData.get('metadata_key'), "", "text", true);
this.classList.add('invisible'); this.classList.add('invisible');
setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400); setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400);
this.reset(); this.reset();
@ -221,12 +247,6 @@ var pageUpload = async function() {
document.getElementById('input_pdf_upload').focus(); document.getElementById('input_pdf_upload').focus();
const cache = await caches.open('pdf'); const cache = await caches.open('pdf');
document.getElementById('input_pdf_upload').addEventListener('change', async function(event) { document.getElementById('input_pdf_upload').addEventListener('change', async function(event) {
if(document.getElementById('input_pdf_upload').files[0].size > maxSize) {
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
document.getElementById('input_pdf_upload').value = "";
return;
}
let filename = document.getElementById('input_pdf_upload').files[0].name; let filename = document.getElementById('input_pdf_upload').files[0].name;
let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" }); let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" });
let urlPdf = '/pdf/'+filename; let urlPdf = '/pdf/'+filename;

View File

@ -10,7 +10,7 @@
<link href="/css/app.css?202210080134" rel="stylesheet"> <link href="/css/app.css?202210080134" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="/favicon-organization.ico"> <link rel="icon" type="image/x-icon" href="/favicon-organization.ico">
<title>Métadonnées d'un PDF</title> <title>Édition des métadonnées d'un PDF</title>
</head> </head>
<body> <body>
<noscript> <noscript>
@ -31,13 +31,13 @@
</li> </li>
</ul> </ul>
<div class="px-4 py-4 text-center"> <div class="px-4 py-4 text-center">
<h1 class="display-5 fw-bold mb-0 mt-3"><i class="bi bi-tags"></i> Metadonnées d'un PDF</h1> <h1 class="display-5 fw-bold mb-0 mt-3"><i class="bi bi-tags"></i> Éditer les métadonnées</h1>
<p class="fw-light mb-3 subtitle text-dark text-nowrap" style="overflow: hidden; text-overflow: ellipsis;"></p> <p class="fw-light mb-3 subtitle text-dark text-nowrap" style="overflow: hidden; text-overflow: ellipsis;">Ajouter, modifier ou supprimer les métadonnées d'un PDF</p>
<div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto"> <div class="col-md-6 col-lg-5 col-xl-4 col-xxl-3 mx-auto">
<div class="col-12"> <div class="col-12">
<label class="form-label mt-3" for="input_pdf_upload">Choisir un PDF <small class="opacity-75" style="cursor: help" title="Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo"><i class="bi bi-info-circle"></i></small></label> <label class="form-label mt-3" for="input_pdf_upload">Choisir un PDF <small class="opacity-75" style="cursor: help" title="Le PDF ne doit pas dépasser <?php echo round($maxSize / 1024 / 1024) ?> Mo"><i class="bi bi-info-circle"></i></small></label>
<input id="input_pdf_upload" placeholder="Choisir un PDF" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" /> <input id="input_pdf_upload" placeholder="Choisir un PDF" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
<p class="mt-2 small fw-light text-dark">Le PDF sera traité par le serveur sans être conservé ni stocké</p> <p class="mt-2 small fw-light text-dark">&nbsp;</p>
<?php if($PDF_DEMO_LINK): ?> <?php if($PDF_DEMO_LINK): ?>
<a class="btn btn-sm btn-link opacity-75" href="#<?php echo $PDF_DEMO_LINK ?>">Tester avec un PDF de démo</a> <a class="btn btn-sm btn-link opacity-75" href="#<?php echo $PDF_DEMO_LINK ?>">Tester avec un PDF de démo</a>
<?php endif; ?> <?php endif; ?>
@ -73,7 +73,7 @@
<div style="width: 40%;" class="offcanvas offcanvas-end show d-none d-md-block shadow-sm" data-bs-backdrop="false" data-bs-scroll="true" data-bs-keyboard="false" tabindex="-1" id="sidebarTools" aria-labelledby="sidebarToolsLabel"> <div style="width: 40%;" class="offcanvas offcanvas-end show d-none d-md-block shadow-sm" data-bs-backdrop="false" data-bs-scroll="true" data-bs-keyboard="false" tabindex="-1" id="sidebarTools" aria-labelledby="sidebarToolsLabel">
<a class="btn btn-close btn-sm position-absolute opacity-25 d-none d-sm-none d-md-block" title="Fermer ce PDF et retourner à l'accueil" style="position: absolute; top: 2px; right: 2px; font-size: 10px;" href="/metadata"></a> <a class="btn btn-close btn-sm position-absolute opacity-25 d-none d-sm-none d-md-block" title="Fermer ce PDF et retourner à l'accueil" style="position: absolute; top: 2px; right: 2px; font-size: 10px;" href="/metadata"></a>
<div class="offcanvas-header d-block mb-0 pb-0 border-bottom"> <div class="offcanvas-header d-block mb-0 pb-0 border-bottom">
<h5 class="mb-1 d-block w-100" id="sidebarToolsLabel">Édition de métadonnées<span class="float-end me-2" title="Ce PDF est stocké sur votre ordinateur pour être signé par vous uniquement"><i class="bi bi-tags"></i></span></h5> <h5 class="mb-1 d-block w-100" id="sidebarToolsLabel">Édition des métadonnées<span class="float-end me-2" title="Ce PDF est stocké sur votre ordinateur pour être signé par vous uniquement"><i class="bi bi-tags"></i></span></h5>
<button type="button" class="btn-close text-reset d-md-none" data-bs-dismiss="offcanvas" aria-label="Close"></button> <button type="button" class="btn-close text-reset d-md-none" data-bs-dismiss="offcanvas" aria-label="Close"></button>
<p id="text_document_name" class="text-muted mb-2" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;" title=""><i class="bi bi-files"></i> <span></span></p> <p id="text_document_name" class="text-muted mb-2" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden;" title=""><i class="bi bi-files"></i> <span></span></p>
</div> </div>
@ -100,7 +100,7 @@
<script src="/vendor/pdf.js?legacy"></script> <script src="/vendor/pdf.js?legacy"></script>
<script src="/vendor/pdf-lib.min.js?1.17.1"></script> <script src="/vendor/pdf-lib.min.js?1.17.1"></script>
<script> <script>
var maxSize = <?php echo $maxSize ?>; var defaultFields = <?php echo json_encode(isset($METADATA_DEFAULT_FIELDS) ? $METADATA_DEFAULT_FIELDS : array()); ?>;
</script> </script>
<script src="/js/metadata.js?202212070154"></script> <script src="/js/metadata.js?202212070154"></script>
</body> </body>

View File

@ -26,6 +26,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a> <a class="nav-link active" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="/metadata"><i class="bi bi-tags"></i> Metadonnées</a>
</li>
</ul> </ul>
<div class="px-4 py-4 text-center"> <div class="px-4 py-4 text-center">
<h1 class="display-5 fw-bold mb-0 mt-3"><i class="bi bi-ui-checks-grid"></i> Organiser des PDF</h1> <h1 class="display-5 fw-bold mb-0 mt-3"><i class="bi bi-ui-checks-grid"></i> Organiser des PDF</h1>
@ -156,4 +159,4 @@
</script> </script>
<script src="/js/organization.js?202212070154"></script> <script src="/js/organization.js?202212070154"></script>
</body> </body>
</html> </html>

View File

@ -25,6 +25,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a> <a class="nav-link" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="/metadata"><i class="bi bi-tags"></i> Metadonnées</a>
</li>
</ul> </ul>
<?php endif; ?> <?php endif; ?>
<div class="px-4 py-4 text-center"> <div class="px-4 py-4 text-center">