From 6841b38eac4a29bb42802876306fad168c935ea5 Mon Sep 17 00:00:00 2001
From: 414nx <138794497+414nx@users.noreply.github.com>
Date: Fri, 17 Oct 2025 12:07:45 -0600
Subject: [PATCH 1/3] add whitespace-pre-line to div id=alert-message so that
\n can be used for line breaks in alert messages
---
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/index.html b/index.html
index 39f2da5..6c4ba4a 100644
--- a/index.html
+++ b/index.html
@@ -265,7 +265,7 @@
Alert
-
+
This is an alert message.
Date: Fri, 17 Oct 2025 12:50:53 -0600
Subject: [PATCH 2/3] modifies handleMultiFileUpload function to check if PDFs
are password protected when using merge or alternate-merge
---
src/js/handlers/fileHandler.ts | 50 ++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/src/js/handlers/fileHandler.ts b/src/js/handlers/fileHandler.ts
index bb6f642..4659eb7 100644
--- a/src/js/handlers/fileHandler.ts
+++ b/src/js/handlers/fileHandler.ts
@@ -323,7 +323,53 @@ async function handleSinglePdfUpload(toolId, file) {
}
}
-function handleMultiFileUpload(toolId) {
+async function handleMultiFileUpload(toolId) {
+ if (toolId == 'merge' || toolId == 'alternate-merge') {
+ const pdfFilesUnloaded: File[] = [];
+
+ state.files.forEach((file) => {
+ if (file.type == 'application/pdf') {
+ pdfFilesUnloaded.push(file);
+ }
+ });
+
+ const pdfFilesLoaded: {
+ file: File;
+ pdfDoc: PDFLibDocument;
+ }[] = [];
+
+ for (const file of pdfFilesUnloaded) {
+ const pdfBytes = await readFileAsArrayBuffer(file);
+ const pdfDoc = await PDFLibDocument.load(pdfBytes as ArrayBuffer, {
+ ignoreEncryption: true,
+ });
+
+ pdfFilesLoaded.push({
+ file,
+ pdfDoc,
+ });
+ }
+
+ const foundEncryptedPdfs = pdfFilesLoaded.filter(
+ (pdf) => pdf.pdfDoc.isEncrypted
+ );
+
+ if (foundEncryptedPdfs.length > 0) {
+ const encryptedPDFTitles = [];
+ foundEncryptedPdfs.forEach((encPdf) => {
+ encryptedPDFTitles.push(encPdf.file.name);
+ });
+
+ const errorMessage = `PDFs found that are password-protected\nPlease use the Decrypt or Change Permissions tool first.\n\n${encryptedPDFTitles.join('\n')}`;
+
+ showAlert('Protected PDFs', errorMessage);
+
+ switchView('grid');
+
+ return;
+ }
+ }
+
const processBtn = document.getElementById('process-btn');
if (processBtn) {
(processBtn as HTMLButtonElement).disabled = false;
@@ -393,7 +439,7 @@ export function setupFileInputHandler(toolId) {
}
if (isMultiFileTool) {
- handleMultiFileUpload(toolId);
+ await handleMultiFileUpload(toolId);
} else if (singlePdfLoadTools.includes(toolId)) {
await handleSinglePdfUpload(toolId, state.files[0]);
} else if (simpleTools.includes(toolId)) {
From 560d45d2908afc9e6542cad4463ce59d6198a4f9 Mon Sep 17 00:00:00 2001
From: 414nx <138794497+414nx@users.noreply.github.com>
Date: Sat, 18 Oct 2025 02:45:24 -0600
Subject: [PATCH 3/3] changed for loop into promise.all for parallel loading of
PDFs during encryption check multifileupload, added better seperation between
alert text for encrypted pdf found merge warning, changed loose equality
check in encrypted pdf check logic in handlemultifileupload to strict
equality
---
src/js/handlers/fileHandler.ts | 43 ++++++++++++++++------------------
1 file changed, 20 insertions(+), 23 deletions(-)
diff --git a/src/js/handlers/fileHandler.ts b/src/js/handlers/fileHandler.ts
index 4659eb7..dd558ff 100644
--- a/src/js/handlers/fileHandler.ts
+++ b/src/js/handlers/fileHandler.ts
@@ -324,43 +324,40 @@ async function handleSinglePdfUpload(toolId, file) {
}
async function handleMultiFileUpload(toolId) {
- if (toolId == 'merge' || toolId == 'alternate-merge') {
+ if (toolId === 'merge' || toolId === 'alternate-merge') {
const pdfFilesUnloaded: File[] = [];
state.files.forEach((file) => {
- if (file.type == 'application/pdf') {
+ if (file.type === 'application/pdf') {
pdfFilesUnloaded.push(file);
}
});
- const pdfFilesLoaded: {
- file: File;
- pdfDoc: PDFLibDocument;
- }[] = [];
+ const pdfFilesLoaded = await Promise.all(
+ pdfFilesUnloaded.map(async (file) => {
+ const pdfBytes = await readFileAsArrayBuffer(file);
+ const pdfDoc = await PDFLibDocument.load(pdfBytes as ArrayBuffer, {
+ ignoreEncryption: true,
+ });
- for (const file of pdfFilesUnloaded) {
- const pdfBytes = await readFileAsArrayBuffer(file);
- const pdfDoc = await PDFLibDocument.load(pdfBytes as ArrayBuffer, {
- ignoreEncryption: true,
- });
+ return {
+ file,
+ pdfDoc,
+ };
+ })
+ );
- pdfFilesLoaded.push({
- file,
- pdfDoc,
- });
- }
-
- const foundEncryptedPdfs = pdfFilesLoaded.filter(
+ const foundEncryptedPDFs = pdfFilesLoaded.filter(
(pdf) => pdf.pdfDoc.isEncrypted
);
- if (foundEncryptedPdfs.length > 0) {
- const encryptedPDFTitles = [];
- foundEncryptedPdfs.forEach((encPdf) => {
- encryptedPDFTitles.push(encPdf.file.name);
+ if (foundEncryptedPDFs.length > 0) {
+ const encryptedPDFFileNames = [];
+ foundEncryptedPDFs.forEach((encryptedPDF) => {
+ encryptedPDFFileNames.push(encryptedPDF.file.name);
});
- const errorMessage = `PDFs found that are password-protected\nPlease use the Decrypt or Change Permissions tool first.\n\n${encryptedPDFTitles.join('\n')}`;
+ const errorMessage = `PDFs found that are password-protected\n\nPlease use the Decrypt or Change Permissions tool on these files first:\n\n${encryptedPDFFileNames.join('\n')}`;
showAlert('Protected PDFs', errorMessage);