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
This commit is contained in:
Charan19001A0231 2024-10-05 02:44:15 +05:30 committed by GitHub
parent 494bc2c09f
commit 48aae48f0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 40 deletions

View file

@ -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

View file

@ -76,6 +76,8 @@ donate=Donate
color=Color
sponsor=Sponsor
info=Info
page=पृष्ठ
pages=पृष्ठों
legal.privacy=Privacy Policy
legal.terms=Terms and Conditions

View file

@ -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 = `
<div class="d-flex justify-content-between align-items-center w-100">
<div class="filename">${files[i].name}</div>
<div class="page-info">
<span class="page-count">${pageCount} ${pageLabel}</span>
</div>
<div class="arrows d-flex">
<button class="btn btn-secondary move-up"><span>&uarr;</span></button>
<button class="btn btn-secondary move-down"><span>&darr;</span></button>
@ -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++) {

View file

@ -1,11 +1,13 @@
<!DOCTYPE html>
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}" xmlns:th="https://www.thymeleaf.org">
<head>
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}"
xmlns:th="https://www.thymeleaf.org">
<head>
<th:block th:insert="~{fragments/common :: head(title=#{merge.title}, header=#{merge.header})}"></th:block>
<link rel="stylesheet" th:href="@{'/css/merge.css'}">
</head>
</head>
<body>
<body>
<div id="page-container">
<div id="content-wrap">
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
@ -20,11 +22,14 @@
<form action="api/v1/general/merge-pdfs" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label th:text="#{multiPdfDropPrompt}" for="fileInput-input"></label>
<div th:replace="~{fragments/common :: fileSelector(name='fileInput', multipleInputsForSingleRequest=true, accept='application/pdf')}"></div>
<div
th:replace="~{fragments/common :: fileSelector(name='fileInput', multipleInputsForSingleRequest=true, accept='application/pdf')}">
</div>
</div>
<div class="mb-3">
<input type="checkbox" name="removeCertSign" id="removeCertSign">
<label for="removeCertSign" th:text="#{merge.removeCertSign}">Remove digital signature in the merged file?</label>
<label for="removeCertSign" th:text="#{merge.removeCertSign}">Remove digital signature in the merged
file?</label>
</div>
<div class="mb-3">
<ul id="selectedFiles" class="list-group"></ul>
@ -35,6 +40,17 @@
<button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{merge.submit}"></button>
</div>
</form>
<span id="pageTranslation" th:text="#{page}" style="display:none;"></span>
<span id="pagesTranslation" th:text="#{pages}" style="display:none;"></span>
<script type="text/javascript">
const pageTranslation = document.getElementById('pageTranslation').innerText; // Get translation for a single page
const pagesTranslation = document.getElementById('pagesTranslation').innerText; // Get translation for multiple pages
</script>
<script type="module">
import * as pdfjsLib from '/pdfjs-legacy/pdf.mjs';
pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdfjs-legacy/pdf.worker.mjs';
</script>
<script th:src="@{'/js/merge.js'}"></script>
</div>
</div>
@ -42,5 +58,6 @@
</div>
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
</div>
</body>
</body>
</html>