1
0
Fork 0
mirror of https://github.com/24eme/signaturepdf synced 2026-03-14 13:55:44 +01:00

format: customizable page format

This commit is contained in:
Vincent LAURENT 2025-07-20 19:25:53 +02:00
commit 2daec0a59f
2 changed files with 53 additions and 5 deletions

View file

@ -330,9 +330,26 @@ function updateFormats() {
document.querySelector('#printable_paper_size_infos').innerText = selectFormat.selectedOptions[0].text;
document.querySelector('#printable_paper_size_infos').classList.add('text-muted');
document.querySelector('#printable_paper_size_infos').classList.remove('fw-bold');
if(!selectFormat.value) {
document.querySelector('#input_paper_width').disabled = true;
document.querySelector('#input_paper_height').disabled = true;
document.querySelector('#select_size_unit').disabled = true;
document.querySelector('#input_paper_width').value = null;
document.querySelector('#input_paper_height').value = null;
document.querySelector('#select_size_unit').value = null;
}
if(selectFormat.value) {
document.querySelector('#printable_paper_size_infos').classList.remove('text-muted');
document.querySelector('#printable_paper_size_infos').classList.add('fw-bold');
document.querySelector('#input_paper_width').disabled = false;
document.querySelector('#input_paper_height').disabled = false;
document.querySelector('#select_size_unit').disabled = false;
}
if(selectFormat.value && selectFormat.value.match(/[0-9]+x[0-9]+/)) {
document.querySelector('#input_paper_width').value = selectFormat.value.split('x')[0];
document.querySelector('#input_paper_height').value = selectFormat.value.split('x')[1];
document.querySelector('#select_size_unit').value = 'mm';
}
document.querySelector('#printable_paper_size_infos').title = document.querySelector('#printable_paper_size_infos').innerText;
@ -642,13 +659,12 @@ async function save(order) {
const pageOrganize = pagesOrganize[i].split('-')[0];
const rotation = pagesOrganize[i].split('-')[1];
const pdfPage = pages[pageOrganize];
const format = document.querySelector('#select_paper_format').value;
if(rotation) {
pdfPage.setRotation(window['PDFLib'].degrees(parseInt(rotation)));
}
if(format) {
let width = mm2points(parseInt(format.split("x")[0]));
let height = mm2points(parseInt(format.split("x")[1]));
if(document.querySelector('#input_paper_width').value && document.querySelector('#input_paper_height').value) {
let width = mm2points(parseInt(document.querySelector('#input_paper_width').value));
let height = mm2points(parseInt(document.querySelector('#input_paper_height').value));
if(pdfPage.getHeight() > pdfPage.getWidth()) {
resizePage(pdfPage, Math.min(height, width), Math.max(height, width));
@ -936,6 +952,13 @@ function createEventsListener() {
document.querySelector('#select_formatting').addEventListener('change', function(event) {
updateFormats();
});
document.querySelector('#bloc_size').addEventListener('change', function(event) {
if(!["input_paper_width", "input_paper_height", "select_size_unit"].includes(event.target.id)) {
return;
}
document.querySelector('#select_paper_format').value = "custom";
updateFormats();
});
}
async function uploadFromUrl(url) {

View file

@ -155,11 +155,36 @@
<option value="176x250">B5 (176 × 250 mm)</option>
<option value="216x356">Legal (8.5 × 14 pouces / 216 × 356 mm)</option>
<option value="279x432">Tabloid (11 × 17 pouces / 279 × 432 mm)</option>
<!--<option value="custom">Other Custom ...</option>-->
<option value="custom">Other Custom ...</option>
</optgroup>
</select>
<label for="select-format"><?php echo _("Paper size") ?></label>
</div>
<div id="bloc_size" class="row mt-3">
<div class="col">
<div class="form-floating">
<input type="number" class="form-control" id="input_paper_width" value="">
<label for="input_paper_width"><?php echo _("Width") ?></label>
</div>
</div>
<div class="col">
<div class="form-floating">
<input type="number" class="form-control" id="input_paper_height" value="">
<label for="input_paper_height"><?php echo _("Height") ?></label>
</div>
</div>
<div class="col">
<div class="form-floating">
<select class="form-select" id="select_size_unit">
<option value=""></option>
<option value="mm"><?php echo _("mm") ?></option>
<option value="in"><?php echo _("in") ?></option>
</select>
<label for="floatingInputGrid">Unit</label>
</div>
</div>
</div>
<hr />
<div class="form-floating mt-3">
<select class="form-select" id="select_formatting">
<option value="" selected><?php echo _("Normal") ?></option>