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:
parent
494bc2c09f
commit
48aae48f0e
4 changed files with 73 additions and 40 deletions
|
@ -76,6 +76,8 @@ donate=Donate
|
||||||
color=Color
|
color=Color
|
||||||
sponsor=Sponsor
|
sponsor=Sponsor
|
||||||
info=Info
|
info=Info
|
||||||
|
page=Page
|
||||||
|
pages=Pages
|
||||||
|
|
||||||
legal.privacy=Privacy Policy
|
legal.privacy=Privacy Policy
|
||||||
legal.terms=Terms and Conditions
|
legal.terms=Terms and Conditions
|
||||||
|
|
|
@ -76,6 +76,8 @@ donate=Donate
|
||||||
color=Color
|
color=Color
|
||||||
sponsor=Sponsor
|
sponsor=Sponsor
|
||||||
info=Info
|
info=Info
|
||||||
|
page=पृष्ठ
|
||||||
|
pages=पृष्ठों
|
||||||
|
|
||||||
legal.privacy=Privacy Policy
|
legal.privacy=Privacy Policy
|
||||||
legal.terms=Terms and Conditions
|
legal.terms=Terms and Conditions
|
||||||
|
|
|
@ -11,7 +11,7 @@ document.getElementById("fileInput-input").addEventListener("change", function (
|
||||||
/**
|
/**
|
||||||
* @param {FileList} files
|
* @param {FileList} files
|
||||||
*/
|
*/
|
||||||
function displayFiles(files) {
|
async function displayFiles(files) {
|
||||||
const list = document.getElementById("selectedFiles");
|
const list = document.getElementById("selectedFiles");
|
||||||
|
|
||||||
while (list.firstChild) {
|
while (list.firstChild) {
|
||||||
|
@ -19,11 +19,16 @@ function displayFiles(files) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
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");
|
const item = document.createElement("li");
|
||||||
item.className = "list-group-item";
|
item.className = "list-group-item";
|
||||||
item.innerHTML = `
|
item.innerHTML = `
|
||||||
<div class="d-flex justify-content-between align-items-center w-100">
|
<div class="d-flex justify-content-between align-items-center w-100">
|
||||||
<div class="filename">${files[i].name}</div>
|
<div class="filename">${files[i].name}</div>
|
||||||
|
<div class="page-info">
|
||||||
|
<span class="page-count">${pageCount} ${pageLabel}</span>
|
||||||
|
</div>
|
||||||
<div class="arrows d-flex">
|
<div class="arrows d-flex">
|
||||||
<button class="btn btn-secondary move-up"><span>↑</span></button>
|
<button class="btn btn-secondary move-up"><span>↑</span></button>
|
||||||
<button class="btn btn-secondary move-down"><span>↓</span></button>
|
<button class="btn btn-secondary move-down"><span>↓</span></button>
|
||||||
|
@ -37,6 +42,13 @@ function displayFiles(files) {
|
||||||
attachMoveButtons();
|
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() {
|
function attachMoveButtons() {
|
||||||
var moveUpButtons = document.querySelectorAll(".move-up");
|
var moveUpButtons = document.querySelectorAll(".move-up");
|
||||||
for (var i = 0; i < moveUpButtons.length; i++) {
|
for (var i = 0; i < moveUpButtons.length; i++) {
|
||||||
|
|
|
@ -1,46 +1,63 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}" xmlns:th="https://www.thymeleaf.org">
|
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}"
|
||||||
<head>
|
xmlns:th="https://www.thymeleaf.org">
|
||||||
<th:block th:insert="~{fragments/common :: head(title=#{merge.title}, header=#{merge.header})}"></th:block>
|
|
||||||
<link rel="stylesheet" th:href="@{'/css/merge.css'}">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
<head>
|
||||||
<div id="page-container">
|
<th:block th:insert="~{fragments/common :: head(title=#{merge.title}, header=#{merge.header})}"></th:block>
|
||||||
<div id="content-wrap">
|
<link rel="stylesheet" th:href="@{'/css/merge.css'}">
|
||||||
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
|
</head>
|
||||||
<br><br>
|
|
||||||
<div class="container" id="dropContainer">
|
<body>
|
||||||
<div class="row justify-content-center">
|
<div id="page-container">
|
||||||
<div class="col-md-6 bg-card">
|
<div id="content-wrap">
|
||||||
<div class="tool-header">
|
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
|
||||||
<span class="material-symbols-rounded tool-header-icon organize">add_to_photos</span>
|
<br><br>
|
||||||
<span class="tool-header-text" th:text="#{merge.header}"></span>
|
<div class="container" id="dropContainer">
|
||||||
</div>
|
<div class="row justify-content-center">
|
||||||
<form action="api/v1/general/merge-pdfs" method="post" enctype="multipart/form-data">
|
<div class="col-md-6 bg-card">
|
||||||
<div class="mb-3">
|
<div class="tool-header">
|
||||||
<label th:text="#{multiPdfDropPrompt}" for="fileInput-input"></label>
|
<span class="material-symbols-rounded tool-header-icon organize">add_to_photos</span>
|
||||||
<div th:replace="~{fragments/common :: fileSelector(name='fileInput', multipleInputsForSingleRequest=true, accept='application/pdf')}"></div>
|
<span class="tool-header-text" th:text="#{merge.header}"></span>
|
||||||
</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>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<ul id="selectedFiles" class="list-group"></ul>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<button type="button" id="sortByNameBtn" class="btn btn-info" th:text="#{merge.sortByName}"></button>
|
|
||||||
<button type="button" id="sortByDateBtn" class="btn btn-info" th:text="#{merge.sortByDate}"></button>
|
|
||||||
<button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{merge.submit}"></button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<script th:src="@{'/js/merge.js'}"></script>
|
|
||||||
</div>
|
</div>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<ul id="selectedFiles" class="list-group"></ul>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<button type="button" id="sortByNameBtn" class="btn btn-info" th:text="#{merge.sortByName}"></button>
|
||||||
|
<button type="button" id="sortByDateBtn" class="btn btn-info" th:text="#{merge.sortByDate}"></button>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
|
||||||
</html>
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in a new issue