1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-11-23 15:21:25 +01:00

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,46 +1,63 @@
<!DOCTYPE html>
<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>
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}"
xmlns:th="https://www.thymeleaf.org">
<body>
<div id="page-container">
<div id="content-wrap">
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
<br><br>
<div class="container" id="dropContainer">
<div class="row justify-content-center">
<div class="col-md-6 bg-card">
<div class="tool-header">
<span class="material-symbols-rounded tool-header-icon organize">add_to_photos</span>
<span class="tool-header-text" th:text="#{merge.header}"></span>
</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>
<script th:src="@{'/js/merge.js'}"></script>
<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>
<body>
<div id="page-container">
<div id="content-wrap">
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
<br><br>
<div class="container" id="dropContainer">
<div class="row justify-content-center">
<div class="col-md-6 bg-card">
<div class="tool-header">
<span class="material-symbols-rounded tool-header-icon organize">add_to_photos</span>
<span class="tool-header-text" th:text="#{merge.header}"></span>
</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>
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
</div>
</body>
</html>
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
</div>
</body>
</html>