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:
commit
c30c89ad60
2
app.php
2
app.php
@ -355,8 +355,6 @@ $f3->route('POST /organize',
|
||||
|
||||
$f3->route('GET /metadata',
|
||||
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');
|
||||
}
|
||||
);
|
||||
|
@ -9,3 +9,6 @@ PDF_STORAGE_PATH=/path/to/folder
|
||||
|
||||
; Manage demo link pdf : true (by default, show), false (hide), or custom link
|
||||
;PDF_DEMO_LINK=true
|
||||
|
||||
; Metadata default fields
|
||||
;METADATA_DEFAULT_FIELDS[metadata_key].type = "text"
|
||||
|
@ -35,18 +35,23 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
|
||||
await loadingTask.promise.then(function(pdf) {
|
||||
pdf.getMetadata().then(function(metadata) {
|
||||
console.log(metadata);
|
||||
for(fieldKey in defaultFields) {
|
||||
addMetadata(fieldKey, null, defaultFields[fieldKey]['type'], false);
|
||||
}
|
||||
|
||||
for(metaKey in metadata.info) {
|
||||
if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") {
|
||||
continue;
|
||||
}
|
||||
addMetadata(metaKey, metadata.info[metaKey]);
|
||||
addMetadata(metaKey, metadata.info[metaKey], "text", false);
|
||||
}
|
||||
|
||||
for(metaKey in metadata.info.Custom) {
|
||||
if(metaKey == "sha256") {
|
||||
continue;
|
||||
}
|
||||
|
||||
addMetadata(metaKey, metadata.info.Custom[metaKey]);
|
||||
addMetadata(metaKey, metadata.info.Custom[metaKey], "text", false);
|
||||
}
|
||||
|
||||
for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
|
||||
@ -56,6 +61,11 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) {
|
||||
pageRender(pageIndex);
|
||||
});
|
||||
}
|
||||
if(document.querySelector('.input-metadata input')) {
|
||||
document.querySelector('.input-metadata input').focus();
|
||||
} else {
|
||||
document.getElementById('input_metadata_key').focus();
|
||||
}
|
||||
});
|
||||
}, function (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');
|
||||
div.classList.add('form-floating', 'mt-3', 'input-metadata');
|
||||
|
||||
let input = document.createElement('input');
|
||||
input = document.createElement('input');
|
||||
input.value = value;
|
||||
input.type = type;
|
||||
input.name = key;
|
||||
input.classList.add('form-control');
|
||||
|
||||
let label = document.createElement('label');
|
||||
@ -111,7 +135,9 @@ var addMetadata = function(key, value) {
|
||||
div.appendChild(deleteButton);
|
||||
document.getElementById('form-metadata-container').appendChild(div);
|
||||
|
||||
input.focus();
|
||||
if(focus) {
|
||||
input.focus();
|
||||
}
|
||||
}
|
||||
|
||||
const deleteMetadata = function(el) {
|
||||
@ -158,7 +184,7 @@ const save = async function () {
|
||||
var createEventsListener = function() {
|
||||
document.getElementById('form_metadata_add').addEventListener('submit', function(e) {
|
||||
let formData = new FormData(this);
|
||||
addMetadata(formData.get('metadata_key'), "");
|
||||
addMetadata(formData.get('metadata_key'), "", "text", true);
|
||||
this.classList.add('invisible');
|
||||
setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400);
|
||||
this.reset();
|
||||
@ -221,12 +247,6 @@ var pageUpload = async function() {
|
||||
document.getElementById('input_pdf_upload').focus();
|
||||
const cache = await caches.open('pdf');
|
||||
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 response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" });
|
||||
let urlPdf = '/pdf/'+filename;
|
||||
|
@ -10,7 +10,7 @@
|
||||
<link href="/css/app.css?202210080134" rel="stylesheet">
|
||||
<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>
|
||||
<body>
|
||||
<noscript>
|
||||
@ -31,13 +31,13 @@
|
||||
</li>
|
||||
</ul>
|
||||
<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>
|
||||
<p class="fw-light mb-3 subtitle text-dark text-nowrap" style="overflow: hidden; text-overflow: ellipsis;"></p>
|
||||
<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;">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-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>
|
||||
<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"> </p>
|
||||
<?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>
|
||||
<?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">
|
||||
<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">
|
||||
<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>
|
||||
<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>
|
||||
@ -100,7 +100,7 @@
|
||||
<script src="/vendor/pdf.js?legacy"></script>
|
||||
<script src="/vendor/pdf-lib.min.js?1.17.1"></script>
|
||||
<script>
|
||||
var maxSize = <?php echo $maxSize ?>;
|
||||
var defaultFields = <?php echo json_encode(isset($METADATA_DEFAULT_FIELDS) ? $METADATA_DEFAULT_FIELDS : array()); ?>;
|
||||
</script>
|
||||
<script src="/js/metadata.js?202212070154"></script>
|
||||
</body>
|
||||
|
@ -26,6 +26,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/metadata"><i class="bi bi-tags"></i> Metadonnées</a>
|
||||
</li>
|
||||
</ul>
|
||||
<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>
|
||||
@ -156,4 +159,4 @@
|
||||
</script>
|
||||
<script src="/js/organization.js?202212070154"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -25,6 +25,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/organization"><i class="bi bi-ui-checks-grid"></i> Organiser</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/metadata"><i class="bi bi-tags"></i> Metadonnées</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<div class="px-4 py-4 text-center">
|
||||
|
Loading…
Reference in New Issue
Block a user