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

suppression métadonnées

This commit is contained in:
Gabriel Poma 2023-04-20 15:52:27 +02:00
parent 8d9f49a3e8
commit 2653effbc8

View File

@ -22,6 +22,7 @@ var nbPDF = 0;
var pages = []; var pages = [];
var pdfRenderTasks = []; var pdfRenderTasks = [];
let pdffile = null let pdffile = null
let deletedMetadata = [];
var loadPDF = async function(pdfBlob, filename, pdfIndex) { var loadPDF = async function(pdfBlob, filename, pdfIndex) {
let url = await URL.createObjectURL(pdfBlob); let url = await URL.createObjectURL(pdfBlob);
@ -116,6 +117,8 @@ const deleteMetadata = function(el) {
if (confirm("Souhaitez-vous supprimer ce champ ?") === false) return; if (confirm("Souhaitez-vous supprimer ce champ ?") === false) return;
const input = el.closest('.input-metadata') const input = el.closest('.input-metadata')
const label = input.querySelector('label').innerText
deletedMetadata.push(label)
input.remove() input.remove()
} }
@ -133,12 +136,21 @@ const save = async function () {
const PDFHexString = window['PDFLib'].PDFHexString const PDFHexString = window['PDFLib'].PDFHexString
const PDFName = window['PDFLib'].PDFName const PDFName = window['PDFLib'].PDFName
const arrayBuffer = await pdffile.arrayBuffer() const arrayBuffer = await pdffile.arrayBuffer();
const pdf = await PDFDocument.load(arrayBuffer) const pdf = await PDFDocument.load(arrayBuffer);
pdf.getInfoDict().set(PDFName.of('fooMetadata'), PDFHexString.fromText("test de métadonéé")) deletedMetadata.forEach(function (el) {
pdf.getInfoDict().delete(PDFName.of(el))
});
const newPDF = new Blob([await pdf.save()], {type: "application/pdf"}) ([...document.getElementsByClassName('input-metadata')] || []).forEach(function (el) {
const label = el.querySelector('label').innerText
const input = el.querySelector('input').value
pdf.getInfoDict().set(PDFName.of(label), PDFHexString.fromText(input));
});
const newPDF = new Blob([await pdf.save()], {type: "application/pdf"});
DL(newPDF, "a.pdf") DL(newPDF, "a.pdf")
} }