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

metadata: fields list by default define in configuration

This commit is contained in:
Vincent LAURENT 2023-04-20 15:37:01 +02:00
parent 49bf6e50ab
commit b30be5b344
3 changed files with 27 additions and 5 deletions

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

@ -33,18 +33,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']);
}
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");
} }
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");
} }
for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) {
@ -89,12 +94,26 @@ var pageRender = async function(pageIndex) {
}); });
} }
var addMetadata = function(key, value) { var addMetadata = function(key, value, type) {
let input = document.querySelector('.input-metadata input[name="'+key+'"]');
if(input && input.value === null) {
input.value = value;
return;
}
if(input) {
input.focus();
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');

View File

@ -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>