Changes to splitPDF() function

This commit is contained in:
2026-07-28 09:58:09 +02:00
parent 46eb5d02dc
commit df6110fc59
+12 -6
View File
@@ -245,19 +245,25 @@ async function splitPDF(numRows, inputFile, tempFiles) {
// if there are duplicates (back to back duplicates), I only have to print one copy // if there are duplicates (back to back duplicates), I only have to print one copy
if (pagesNumber > numRows) { // comparison between the number of pages of the pdf file and those of the excel file if (pagesNumber > numRows) { // comparison between the number of pages of the pdf file and those of the excel file
let displayNumPage = 1; let displayNumPage = 1;
let i; let lastPrintedText = null;
for (i = 1; i < pagesNumber && displayNumPage <= numRows; i += 2) {
if (result.pages[i].text.trim() === result.pages[i - 1].text.trim()) {
continue;
}
for (let i = 0; i < pagesNumber; i++) {
let pageText = result.pages[i].text.trim();
// Only print if the current page is different from the immediate previous page
if (pageText !== lastPrintedText) {
/*console.log(`--- PAGE ${displayNumPage} ---`); /*console.log(`--- PAGE ${displayNumPage} ---`);
console.log(result.pages[i].text); console.log(pageText);
console.log("\n");*/ console.log("\n");*/
// Remember this text for the next iteration
lastPrintedText = pageText;
await processPage(srcPdf, i, tempFiles); await processPage(srcPdf, i, tempFiles);
displayNumPage++; displayNumPage++;
} }
i++;
}
} }
else { else {
for (let i = 0; i < pagesNumber; i++) { for (let i = 0; i < pagesNumber; i++) {