Skip to content

Commit

Permalink
organization: when saving we only copy the pages to be extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
wincelau committed Dec 14, 2024
1 parent 946ae65 commit 79a7a90
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions public/js/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,22 +559,29 @@ async function save(order) {
const pdf = await PDFDocument.create();
let filename = "";
let pages = [];
const pagesOrganize = order.split(',');

for (let i = 0; i < document.querySelector('#input_pdf').files.length; i++) {
if(filename) {
filename += '_';
}
filename += document.querySelector('#input_pdf').files.item(i).name.replace(/\.pdf$/, '');
pdfFile = await PDFDocument.load(await document.querySelector('#input_pdf').files.item(i).arrayBuffer());

const pdfPages = await pdf.copyPages(pdfFile, pdfFile.getPageIndices());
const indices = [];
const letter = getLetter(i);
for(let k in pagesOrganize) {
if(pagesOrganize[k].startsWith(letter)) {
indices.push(parseInt(pagesOrganize[k].split('-')[0].replace(letter, '')) - 1)
}
}

const pdfPages = await pdf.copyPages(pdfFile, indices);
for(j in pdfPages) {
const numPage = parseInt(j) + 1;
pages[getLetter(i)+numPage.toString()] = pdfPages[j];
pages[letter+(indices[j]+1).toString()] = pdfPages[j];
}
}

const pagesOrganize = order.split(',');

for(let i in pagesOrganize) {
const pageOrganize = pagesOrganize[i].split('-')[0];
const rotation = pagesOrganize[i].split('-')[1];
Expand Down

0 comments on commit 79a7a90

Please sign in to comment.