From 48aae48f0ec77262830cff6ce91e48a211fdc478 Mon Sep 17 00:00:00 2001 From: Charan19001A0231 Date: Sat, 5 Oct 2024 02:44:15 +0530 Subject: [PATCH] Added page counts to merge pdf tool (#1986) * Added page counts to merge pdf tool * used page and pages in en_GB and hindi properties file --- src/main/resources/messages_en_GB.properties | 2 + src/main/resources/messages_hi_IN.properties | 2 + src/main/resources/static/js/merge.js | 14 ++- src/main/resources/templates/merge-pdfs.html | 95 ++++++++++++-------- 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/src/main/resources/messages_en_GB.properties b/src/main/resources/messages_en_GB.properties index 761a8568..dbebccc0 100644 --- a/src/main/resources/messages_en_GB.properties +++ b/src/main/resources/messages_en_GB.properties @@ -76,6 +76,8 @@ donate=Donate color=Color sponsor=Sponsor info=Info +page=Page +pages=Pages legal.privacy=Privacy Policy legal.terms=Terms and Conditions diff --git a/src/main/resources/messages_hi_IN.properties b/src/main/resources/messages_hi_IN.properties index 1cda3712..21d4669f 100644 --- a/src/main/resources/messages_hi_IN.properties +++ b/src/main/resources/messages_hi_IN.properties @@ -76,6 +76,8 @@ donate=Donate color=Color sponsor=Sponsor info=Info +page=पृष्ठ +pages=पृष्ठों legal.privacy=Privacy Policy legal.terms=Terms and Conditions diff --git a/src/main/resources/static/js/merge.js b/src/main/resources/static/js/merge.js index 55575727..41d1fe1e 100644 --- a/src/main/resources/static/js/merge.js +++ b/src/main/resources/static/js/merge.js @@ -11,7 +11,7 @@ document.getElementById("fileInput-input").addEventListener("change", function ( /** * @param {FileList} files */ -function displayFiles(files) { +async function displayFiles(files) { const list = document.getElementById("selectedFiles"); while (list.firstChild) { @@ -19,11 +19,16 @@ function displayFiles(files) { } for (let i = 0; i < files.length; i++) { + const pageCount = await getPDFPageCount(files[i]); + const pageLabel = pageCount === 1 ? pageTranslation : pagesTranslation; const item = document.createElement("li"); item.className = "list-group-item"; item.innerHTML = `
${files[i].name}
+
+ ${pageCount} ${pageLabel} +
@@ -37,6 +42,13 @@ function displayFiles(files) { attachMoveButtons(); } +async function getPDFPageCount(file) { + const blobUrl = URL.createObjectURL(file); + const pdf = await pdfjsLib.getDocument(blobUrl).promise; + URL.revokeObjectURL(blobUrl); + return pdf.numPages; +} + function attachMoveButtons() { var moveUpButtons = document.querySelectorAll(".move-up"); for (var i = 0; i < moveUpButtons.length; i++) { diff --git a/src/main/resources/templates/merge-pdfs.html b/src/main/resources/templates/merge-pdfs.html index 8e1e0fbc..8a874788 100644 --- a/src/main/resources/templates/merge-pdfs.html +++ b/src/main/resources/templates/merge-pdfs.html @@ -1,46 +1,63 @@ - - - - - + - -
-
- -

-
-
-
-
- add_to_photos - -
-
-
- -
-
-
- - -
-
-
    -
    -
    - - - -
    -
    - + + + + + + +
    +
    + +

    +
    +
    +
    +
    + add_to_photos +
    +
    +
    + +
    +
    +
    +
    + + +
    +
    +
      +
      +
      + + + +
      +
      + + + + + +
      -
      - - + +
      + + + \ No newline at end of file