- Add favicon.ico to public directory for browser tab display - Update favicon references across all HTML pages with proper link tags for SVG, PNG, and ICO formats - Add Apple touch icon support for iOS devices - Create new repair-pdf.ts logic module for PDF repair functionality - Create new repair-pdf-page.ts utility module for page-level repair operations - Add repair-pdf.html page with UI for PDF repair tool - Register repair PDF tool in tools configuration and PDF tools registry - Update UI rendering utilities to support new repair tool - Improve favicon handling with multiple format fallbacks for cross-browser compatibility - Standardize favicon paths to use absolute URLs for consistency - Clean up whitespace and formatting in licensing.html for code consistency
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { showLoader, hideLoader, showAlert } from '../ui.js';
|
|
import { downloadFile } from '../utils/helpers.js';
|
|
import { state } from '../state.js';
|
|
|
|
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
|
|
import JSZip from 'jszip';
|
|
|
|
export async function reversePages() {
|
|
const pdfDocs = state.files.filter(
|
|
(file: File) => file.type === 'application/pdf'
|
|
);
|
|
if (!pdfDocs.length) {
|
|
showAlert('Error', 'PDF not loaded.');
|
|
return;
|
|
}
|
|
showLoader('Reversing page order...');
|
|
try {
|
|
const zip = new JSZip();
|
|
for (let j = 0; j < pdfDocs.length; j++) {
|
|
const file = pdfDocs[j];
|
|
const arrayBuffer = await file.arrayBuffer();
|
|
const pdfDoc = await PDFLibDocument.load(arrayBuffer, { ignoreEncryption: true, throwOnInvalidObject: false });
|
|
const newPdf = await PDFLibDocument.create();
|
|
const pageCount = pdfDoc.getPageCount();
|
|
const reversedIndices = Array.from(
|
|
{ length: pageCount },
|
|
(_, i) => pageCount - 1 - i
|
|
);
|
|
|
|
const copiedPages = await newPdf.copyPages(pdfDoc, reversedIndices);
|
|
copiedPages.forEach((page: any) => newPdf.addPage(page));
|
|
|
|
const newPdfBytes = await newPdf.save();
|
|
const originalName = file.name.replace(/\.pdf$/i, '');
|
|
const fileName = `${originalName}_reversed.pdf`;
|
|
zip.file(fileName, newPdfBytes);
|
|
}
|
|
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
|
downloadFile(zipBlob, 'reversed_pdfs.zip');
|
|
} catch (e) {
|
|
console.error(e);
|
|
showAlert('Error', 'Could not reverse the PDF pages.');
|
|
} finally {
|
|
hideLoader();
|
|
}
|
|
}
|