mirror of
https://github.com/24eme/signaturepdf.git
synced 2023-08-25 09:33:08 +02:00
on sauve les métadonnées et on DL le pdf
This commit is contained in:
parent
6c28618fbe
commit
6bed0fdc1d
@ -21,9 +21,13 @@ pdfjsLib.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.js?legacy';
|
|||||||
var nbPDF = 0;
|
var nbPDF = 0;
|
||||||
var pages = [];
|
var pages = [];
|
||||||
var pdfRenderTasks = [];
|
var pdfRenderTasks = [];
|
||||||
|
let pdffile = null
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
pdffile = pdfBlob
|
||||||
|
|
||||||
let loadingTask = pdfjsLib.getDocument(url);
|
let loadingTask = pdfjsLib.getDocument(url);
|
||||||
document.querySelector('#text_document_name span').innerText = filename;
|
document.querySelector('#text_document_name span').innerText = filename;
|
||||||
await loadingTask.promise.then(function(pdf) {
|
await loadingTask.promise.then(function(pdf) {
|
||||||
@ -115,6 +119,29 @@ const deleteMetadata = function(el) {
|
|||||||
input.remove()
|
input.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const save = async function () {
|
||||||
|
const PDFDocument = window['PDFLib'].PDFDocument
|
||||||
|
const PDFHexString = window['PDFLib'].PDFHexString
|
||||||
|
const PDFName = window['PDFLib'].PDFName
|
||||||
|
|
||||||
|
const arrayBuffer = await pdffile.arrayBuffer()
|
||||||
|
const pdf = await PDFDocument.load(arrayBuffer)
|
||||||
|
|
||||||
|
console.log(pdf.getInfoDict())
|
||||||
|
pdf.getInfoDict().set(PDFName.of('fooMetadata'), PDFHexString.fromText("test de métadonéé"))
|
||||||
|
|
||||||
|
const newPDF = new Blob([pdf.save()], {type: "application/pdf"})
|
||||||
|
DL = function (d,f) {
|
||||||
|
let a = document.createElement("a"),
|
||||||
|
u = URL.createObjectURL(d);
|
||||||
|
a.download = f,
|
||||||
|
a.href = u,
|
||||||
|
a.click(),
|
||||||
|
setTimeout(() => URL.revokeObjectURL(u))
|
||||||
|
}
|
||||||
|
DL(newPDF, "a.pdf")
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@ -134,6 +161,10 @@ var createEventsListener = function() {
|
|||||||
deleteMetadata(event.target)
|
deleteMetadata(event.target)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
document.getElementById('save').addEventListener('click', function (e) {
|
||||||
|
save()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPDFBlobFromCache(cacheUrl) {
|
async function getPDFBlobFromCache(cacheUrl) {
|
||||||
|
16
public/vendor/pdf-lib.min.js
vendored
Normal file
16
public/vendor/pdf-lib.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -82,18 +82,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="position-absolute bg-white bottom-0 pb-2 ps-2 pe-2 w-100 border-top shadow-lg">
|
<div class="position-absolute bg-white bottom-0 pb-2 ps-2 pe-2 w-100 border-top shadow-lg">
|
||||||
<form id="form_pdf" action="/organize" method="post" enctype="multipart/form-data">
|
<div id="btn_container" class="d-grid gap-2 mt-2">
|
||||||
<input id="input_pdf" name="pdf[]" type="file" class="d-none" />
|
<button class="btn btn-primary" type="submit" id="save"><i class="bi bi-download"></i> Enregistrer et télécharger le PDF</button>
|
||||||
<input id="input_pages" type="hidden" value="" name="pages" />
|
</div>
|
||||||
<div id="btn_container" class="d-grid gap-2 mt-2">
|
|
||||||
<button class="btn btn-primary" type="submit" id="save"><i class="bi bi-download"></i> Enregistrer et télécharger le PDF</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="bottom_bar" class="position-fixed bottom-0 start-0 bg-white w-100 p-2 shadow-sm d-md-none">
|
<div id="bottom_bar" class="position-fixed bottom-0 start-0 bg-white w-100 p-2 shadow-sm d-md-none">
|
||||||
<div id="bottom_bar_action" class="d-grid gap-2">
|
<div id="bottom_bar_action" class="d-grid gap-2">
|
||||||
<button class="btn btn-primary" type="submit" id="save_mobile"><i class="bi bi-download"></i> Télécharger le PDF</button>
|
<button class="btn btn-primary" id="save_mobile"><i class="bi bi-download"></i> Télécharger le PDF</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -102,6 +98,7 @@
|
|||||||
|
|
||||||
<script src="/vendor/bootstrap.min.js?5.1.3"></script>
|
<script src="/vendor/bootstrap.min.js?5.1.3"></script>
|
||||||
<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>
|
<script>
|
||||||
var maxSize = <?php echo $maxSize ?>;
|
var maxSize = <?php echo $maxSize ?>;
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user