// Imposition for booklet(s) // // This script re-arrange the pages of your document in order to make an imposed sheet layouts for printing. // Two pages per sheet, double-sided class Booklet extends Paged.Handler { constructor(chunker, polisher, caller) { super(chunker, polisher, caller); this.pagedbooklet; this.sourceSize; this.pageStart; this.pageEnd; } onAtPage(node, item, list) {} onDeclaration(declaration, dItem, dList, rule) { if (declaration.property == "--paged-layout") { if (declaration.value.value.includes("booklet")) { this.pagedbooklet = true; let valuesBooklet = declaration.value.value.split(' '); let index = valuesBooklet.indexOf("booklet"); /* Set first page of the imposition */ if(valuesBooklet[index + 1]){ this.pageStart = parseInt(valuesBooklet[index + 1]); }else{ this.pageStart = 1; } /* Set last page of the imposition */ if(valuesBooklet[index + 2]){ this.pageEnd = parseInt(valuesBooklet[index + 2]); } } } } afterRendered(pages) { /* Verify this.pageEnd */ if(!this.pageEnd){ let allPagesBefore = document.querySelectorAll(".pagedjs_page").length; this.pageEnd = allPagesBefore; } /* Verify this.pageStart */ if(this.pageStart == 0){ this.pageStart = 1; }else if(this.pageStart % 2 == 0){ this.pageStart = this.pageStart - 1; } // Bouton pour activer/désactiver l'imposition const imposeButton = document.querySelector("#imposition-toggle"); let styleElement; // Variable pour stocker l'élément