mirror of
https://github.com/24eme/signaturepdf
synced 2026-03-14 13:55:44 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
09735151a6
10 changed files with 59 additions and 27 deletions
|
|
@ -205,3 +205,47 @@ function trimSvgWhitespace(svgContent) {
|
|||
function getLetter(i) {
|
||||
return String.fromCharCode(96 + i+1).toUpperCase();
|
||||
}
|
||||
|
||||
async function convertInputFileImagesToPDF(inputFile) {
|
||||
let dataTransfer = new DataTransfer();
|
||||
for (let i = 0; i < inputFile.files.length; i++) {
|
||||
console.log(inputFile.files[i].type);
|
||||
if(["image/png", "image/jpeg"].includes(inputFile.files[i].type)) {
|
||||
dataTransfer.items.add(await imageToPdf(inputFile.files[i]));
|
||||
} else {
|
||||
dataTransfer.items.add(inputFile.files[i]);
|
||||
}
|
||||
}
|
||||
inputFile.files = dataTransfer.files
|
||||
}
|
||||
|
||||
async function imageToPdf(file) {
|
||||
const pdfDoc = await window['PDFLib'].PDFDocument.create();
|
||||
const imageBytes = await file.arrayBuffer();
|
||||
let image = null;
|
||||
if(file.type == "image/png") {
|
||||
image = await pdfDoc.embedPng(imageBytes);
|
||||
} else if(file.type == "image/jpeg") {
|
||||
image = await pdfDoc.embedJpg(imageBytes);
|
||||
}
|
||||
|
||||
if(!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { width, height } = image.scale(1);
|
||||
|
||||
const page = pdfDoc.addPage([width, height]);
|
||||
page.drawImage(image, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width,
|
||||
height,
|
||||
});
|
||||
|
||||
const pdfBytes = await pdfDoc.save();
|
||||
|
||||
return new File([pdfBytes], file.name+'.pdf', {
|
||||
type: 'application/pdf'
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
function handleFileChange() {
|
||||
async function handleFileChange() {
|
||||
const fileInput = document.getElementById('input_pdf_upload');
|
||||
await convertInputFileImagesToPDF(fileInput);
|
||||
|
||||
if(fileInput.files[0].size > maxSize) {
|
||||
alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo");
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ async function pageMetadata(url) {
|
|||
|
||||
responsiveDisplay();
|
||||
createEventsListener();
|
||||
await convertInputFileImagesToPDF(document.getElementById('input_pdf_upload'));
|
||||
loadPDF(document.getElementById('input_pdf_upload').files[0]);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -517,6 +517,7 @@ function updateGlobalState() {
|
|||
|
||||
async function uploadAndLoadPDF(input_upload) {
|
||||
showLoading('Loading')
|
||||
await convertInputFileImagesToPDF(input_upload)
|
||||
for (let i = 0; i < input_upload.files.length; i++) {
|
||||
nbPDF++;
|
||||
await loadPDF(input_upload.files[i], input_upload.files[i].name, nbPDF);
|
||||
|
|
|
|||
|
|
@ -1077,6 +1077,7 @@ async function pageSignature(url) {
|
|||
displaysSVG();
|
||||
stateAddLock();
|
||||
createEventsListener();
|
||||
await convertInputFileImagesToPDF(document.getElementById('input_pdf_upload'));
|
||||
loadPDF(document.getElementById('input_pdf_upload').files[0]);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<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-4" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?> <small class="opacity-75" style="cursor: help" title="<?php echo _("The PDF must not exceed "); ?> <?php echo round($maxSize / 1024 / 1024) ?> <?php echo _("Mb"); ?>"><i class="bi bi-info-circle"></i></small></label>
|
||||
<input name="input_pdf_upload" id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" onchange="handleFileChange()" />
|
||||
<input name="input_pdf_upload" id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf,image/png,image/jpeg" onchange="handleFileChange()" />
|
||||
<p class="mt-2 small fw-light text-dark"><?php echo _("The PDF will be processed by the server without being retained or stored") ?></p>
|
||||
<?php if ($error_message == "PDF optimized"): ?>
|
||||
<div class="alert alert-danger">
|
||||
|
|
@ -45,8 +45,7 @@
|
|||
<?php include('components/footer.html.php'); ?>
|
||||
</div>
|
||||
|
||||
<span id="is_mobile" class="d-md-none"></span>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/bootstrap.bundle.min.js?5.1.3"></script>
|
||||
<?php include('components/common.html.php'); ?>
|
||||
<script>
|
||||
var maxSize = <?php echo $maxSize ?>;
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
<a href="<?php echo $REVERSE_PROXY_URL; ?>/organization" class="list-group-item list-group-item-action"><i class="bi bi-download"></i> <?php echo _("Extract pages") ?></a>
|
||||
<a href="<?php echo $REVERSE_PROXY_URL; ?>/organization" class="list-group-item list-group-item-action"><i class="bi bi-arrow-clockwise"></i> <?php echo _("Rotate pages") ?></a>
|
||||
<a href="<?php echo $REVERSE_PROXY_URL; ?>/organization" class="list-group-item list-group-item-action"><i class="bi bi-trash"></i> <?php echo _("Delete pages") ?></a>
|
||||
<a href="<?php echo $REVERSE_PROXY_URL; ?>/organization" class="list-group-item list-group-item-action"><i class="bi bi-images"></i> <?php echo _("Convert images to PDF") ?></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mt-4">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<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-4" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?></label>
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf,image/png,image/jpeg" />
|
||||
<p class="mt-2 small fw-light text-dark"> </p>
|
||||
<?php if($PDF_DEMO_LINK): ?>
|
||||
<p class="mt-4"><a class="link-opacity-75 link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover small" href="#<?php echo $PDF_DEMO_LINK ?>"><?php echo _("Test with a demo PDF") ?></a></p>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
<p class="fs-5 fw-light mb-3 subtitle text-dark text-nowrap mt-2" style="overflow: hidden; text-overflow: ellipsis;"><?php echo _("Merge, sort, rotate, delete, extract pages"); ?></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-4" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?></label>
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" multiple="true" />
|
||||
<label class="form-label mt-4" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?><small class="text-muted opacity-75 d-block"><?php echo _("or an image"); ?></small></label>
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF"); ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf,image/png,image/jpeg" multiple="true" />
|
||||
<p class="mt-2 small fw-light text-dark"> </p>
|
||||
<?php if($PDF_DEMO_LINK): ?>
|
||||
<p class="mt-4"><a class="link-opacity-75 link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover small" href="#<?php echo $PDF_DEMO_LINK ?>"><?php echo _("Test with a demo PDF") ?></a></p>
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
</div>
|
||||
<div class="d-grid gap-2 mt-2">
|
||||
<button type="button" class="btn btn-sm btn-outline-dark" onclick="document.getElementById('input_pdf_upload_2').click();"><?php echo sprintf(_("%s Add a PDF"), '<i class="bi bi-plus-circle"></i>'); ?></button>
|
||||
<input id="input_pdf_upload_2" class="form-control d-none" type="file" accept=".pdf,application/pdf" multiple="true">
|
||||
<input id="input_pdf_upload_2" class="form-control d-none" type="file" accept=".pdf,application/pdf,image/png,image/jpeg" multiple="true">
|
||||
</div>
|
||||
<hr />
|
||||
<div id="container_btn_select" class="opacity-50 card">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<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-4" for="input_pdf_upload"><?php echo _("Choose a PDF"); ?> <small class="opacity-75" style="cursor: help" title="<?php echo _("The PDF should not exceed"); ?> <?php echo round($maxSize / 1024 / 1024) ?> <?php echo _("MB and"); ?> <?php echo $maxPage ?> <?php echo _("pages"); ?>"><i class="bi bi-info-circle"></i></small></label>
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF") ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf" />
|
||||
<input id="input_pdf_upload" placeholder="<?php echo _("Choose a PDF") ?>" class="form-control form-control-lg" type="file" accept=".pdf,application/pdf,image/png,image/jpeg" />
|
||||
<p class="mt-2 small fw-light text-dark"><?php echo _("The PDF will be processed by the server without being retained or stored") ?></p>
|
||||
<?php if($PDF_DEMO_LINK): ?>
|
||||
<p class="mt-4"><a class="link-opacity-75 link-primary link-offset-2 link-underline-opacity-25 link-underline-opacity-100-hover small" href="#<?php echo $PDF_DEMO_LINK ?>"><?php echo _("Test with a demo PDF") ?></a></p>
|
||||
|
|
@ -178,16 +178,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal" id="modalLoading" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content bg-transparent border-0">
|
||||
<div class="modal-body text-center my-5 text-white fs-4">
|
||||
<p></p>
|
||||
<div class="spinner-border" role="status"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if(!isset($hash) && !isset($noSharingMode)): ?>
|
||||
<div id="modal-start-share" class="modal" tabindex="-1">
|
||||
<div class="modal-dialog modal-md">
|
||||
|
|
@ -265,13 +255,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<span id="is_mobile" class="d-md-none"></span>
|
||||
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/bootstrap.bundle.min.js?5.3.3"></script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/pdf.min.mjs?4.6.82-legacy" type="module"></script>
|
||||
<script type="module">
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = '<?php echo $REVERSE_PROXY_URL; ?>/vendor/pdf.worker.min.mjs?4.6.82-legacy';
|
||||
</script>
|
||||
<?php include('components/common.html.php'); ?>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/fabric.min.js?5.4.0"></script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/signature_pad.umd.min.js?5.0.3"></script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/vendor/opentype.min.js?1.3.4"></script>
|
||||
|
|
@ -301,7 +285,6 @@
|
|||
url_font = <?php echo json_encode('/vendor/fonts/Caveat-Regular.ttf') ?>
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/js/common.js?<?php echo ($COMMIT) ? $COMMIT : filemtime($ROOT."/public/js/common.js") ?>"></script>
|
||||
<script src="<?php echo $REVERSE_PROXY_URL; ?>/js/signature.js?<?php echo ($COMMIT) ? $COMMIT : filemtime($ROOT."/public/js/signature.js") ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue