From df6110fc5938f58b027a6028419d77c1b6c35948 Mon Sep 17 00:00:00 2001 From: "Denise D." Date: Tue, 28 Jul 2026 09:58:09 +0200 Subject: [PATCH] Changes to splitPDF() function --- file.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/file.js b/file.js index 0286409..e37fbd7 100644 --- a/file.js +++ b/file.js @@ -245,18 +245,24 @@ async function splitPDF(numRows, inputFile, tempFiles) { // 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 let displayNumPage = 1; - let i; - for (i = 1; i < pagesNumber && displayNumPage <= numRows; i += 2) { - if (result.pages[i].text.trim() === result.pages[i - 1].text.trim()) { - continue; + let lastPrintedText = null; + + 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(pageText); + console.log("\n");*/ + + // Remember this text for the next iteration + lastPrintedText = pageText; + + await processPage(srcPdf, i, tempFiles); + displayNumPage++; } - - /*console.log(`--- PAGE ${ displayNumPage } ---`); - console.log(result.pages[i].text); - console.log("\n");*/ - - await processPage(srcPdf, i, tempFiles); - displayNumPage++; + i++; } } else {