mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Capitalised pdfJsDocument and pdfLibDocument
This commit is contained in:
parent
5f23491189
commit
57415bea85
@ -6,7 +6,7 @@ import { Image } from 'image-js';
|
||||
import { getImagesOnPage } from "./getImagesOnPage.js";
|
||||
|
||||
export async function detectEmptyPages(file: PdfFile, whiteThreashold: number): Promise<number[]> {
|
||||
const pdfDoc = await file.pdfjsDocument;
|
||||
const pdfDoc = await file.pdfJsDocument;
|
||||
|
||||
const emptyPages: number[] = [];
|
||||
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
||||
|
@ -10,7 +10,7 @@ export async function mergePDFs(params: MergeParamsType): Promise<PdfFile> {
|
||||
const mergedPdf = await PDFDocument.create();
|
||||
|
||||
for (let i = 0; i < params.files.length; i++) {
|
||||
const pdfToMerge = await params.files[i].pdflibDocument;
|
||||
const pdfToMerge = await params.files[i].pdfLibDocument;
|
||||
const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices());
|
||||
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ export type RotateParamsType = {
|
||||
export async function rotatePages(params: RotateParamsType): Promise<PdfFile> {
|
||||
const { file, rotation } = params;
|
||||
|
||||
const pages = (await file.pdflibDocument).getPages();
|
||||
const pages = (await file.pdfLibDocument).getPages();
|
||||
|
||||
if (Array.isArray(rotation)) {
|
||||
if (rotation.length != pages.length) {
|
||||
|
@ -10,7 +10,7 @@ export type ScaleContentParamsType = {
|
||||
export async function scaleContent(params: ScaleContentParamsType): Promise<PdfFile> {
|
||||
const { file, scaleFactor } = params;
|
||||
|
||||
const pdfDoc = await file.pdflibDocument;
|
||||
const pdfDoc = await file.pdfLibDocument;
|
||||
const pages = pdfDoc.getPages();
|
||||
|
||||
if (Array.isArray(scaleFactor)) {
|
||||
|
@ -10,7 +10,7 @@ export type ScalePageParamsType = {
|
||||
export async function scalePage(params: ScalePageParamsType): Promise<PdfFile> {
|
||||
const { file, pageSize } = params;
|
||||
|
||||
const pdfDoc = await file.pdflibDocument;
|
||||
const pdfDoc = await file.pdfLibDocument;
|
||||
const pages = pdfDoc.getPages();
|
||||
|
||||
if (Array.isArray(pageSize)) {
|
||||
|
@ -41,7 +41,7 @@ export async function splitOn(params: SplitOnParamsType) {
|
||||
console.log("File: ", file);
|
||||
|
||||
// Remove detected Pages & Split
|
||||
const pdfDoc = await file.pdflibDocument;
|
||||
const pdfDoc = await file.pdfLibDocument;
|
||||
const numberOfPages = pdfDoc.getPageCount();
|
||||
|
||||
let pagesArray: number[] = [];
|
||||
@ -71,7 +71,7 @@ export async function splitOn(params: SplitOnParamsType) {
|
||||
|
||||
async function getPagesWithQRCode(file: PdfFile) {
|
||||
console.log("FileInQRPrev: ", file);
|
||||
const pdfDoc = await file.pdfjsDocument;
|
||||
const pdfDoc = await file.pdfJsDocument;
|
||||
console.log("FileInQRAfter: ", file);
|
||||
|
||||
const pagesWithQR: number[] = [];
|
||||
|
@ -10,7 +10,7 @@ export type SplitPdfParamsType = {
|
||||
export async function splitPDF(params: SplitPdfParamsType): Promise<PdfFile[]> {
|
||||
const { file, splitAfterPageArray } = params;
|
||||
|
||||
const pdflibDocument = await file.pdflibDocument;
|
||||
const pdflibDocument = await file.pdfLibDocument;
|
||||
|
||||
const numberOfPages = pdflibDocument.getPages().length;
|
||||
|
||||
|
@ -21,7 +21,7 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType)
|
||||
throw new Error("Operation not supported");
|
||||
}
|
||||
|
||||
const pdflibDocument = await file.pdflibDocument;
|
||||
const pdflibDocument = await file.pdfLibDocument;
|
||||
|
||||
const pageCount = pdflibDocument.getPageCount();
|
||||
const sortIndecies = sortFunction(pageCount);
|
||||
@ -36,7 +36,7 @@ export type RearrangePagesParamsType = {
|
||||
export async function rearrangePages(params: RearrangePagesParamsType): Promise<PdfFile> {
|
||||
const { file, fancyPageSelector } = params;
|
||||
|
||||
const pdflibDocument = await file.pdflibDocument;
|
||||
const pdflibDocument = await file.pdfLibDocument;
|
||||
|
||||
const pagesToExtractArray = parseFancyPageSelector(fancyPageSelector, pdflibDocument.getPageCount());
|
||||
const newDocument = selectPages({file: file, pagesToExtractArray});
|
||||
@ -50,7 +50,7 @@ export type SelectPagesParamsType = {
|
||||
export async function selectPages(params: SelectPagesParamsType): Promise<PdfFile> {
|
||||
const { file, pagesToExtractArray } = params;
|
||||
|
||||
const pdflibDocument = await file.pdflibDocument;
|
||||
const pdflibDocument = await file.pdfLibDocument;
|
||||
|
||||
const subDocument = await PDFDocument.create();
|
||||
|
||||
@ -75,7 +75,7 @@ export type RemovePagesParamsType = {
|
||||
export async function removePages(params: RemovePagesParamsType): Promise<PdfFile> {
|
||||
const { file, pagesToRemoveArray } = params;
|
||||
|
||||
const pdflibDocument = await file.pdflibDocument;
|
||||
const pdflibDocument = await file.pdfLibDocument;
|
||||
|
||||
const pagesToExtractArray = invertSelection(pagesToRemoveArray, pdflibDocument.getPageIndices())
|
||||
return selectPages({file: file, pagesToExtractArray});
|
||||
|
@ -17,7 +17,7 @@ export type UpdateMetadataParams = {
|
||||
}
|
||||
|
||||
export async function updateMetadata(params: UpdateMetadataParams): Promise<PdfFile> {
|
||||
const pdfDoc = await params.file.pdflibDocument;
|
||||
const pdfDoc = await params.file.pdfLibDocument;
|
||||
|
||||
if (params.deleteAll) {
|
||||
pdfDoc.setAuthor("");
|
||||
|
@ -44,7 +44,7 @@ export class PdfFile {
|
||||
this.representationType = RepresentationType.Uint8Array;
|
||||
}
|
||||
|
||||
get pdflibDocument() : Promise<PDFLibDocument> {
|
||||
get pdfLibDocument() : Promise<PDFLibDocument> {
|
||||
switch (this.representationType) {
|
||||
case RepresentationType.PDFLibDocument:
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -56,17 +56,17 @@ export class PdfFile {
|
||||
var pdfLibDoc = await PDFLibDocument.load(uint8Array, {
|
||||
updateMetadata: false,
|
||||
});
|
||||
this.pdflibDocument = pdfLibDoc;
|
||||
this.pdfLibDocument = pdfLibDoc;
|
||||
resolve(pdfLibDoc);
|
||||
});
|
||||
}
|
||||
}
|
||||
set pdflibDocument(value: PDFLibDocument) {
|
||||
set pdfLibDocument(value: PDFLibDocument) {
|
||||
this.representation = value;
|
||||
this.representationType = RepresentationType.PDFLibDocument;
|
||||
}
|
||||
|
||||
get pdfjsDocument() : Promise<PDFJSDocument> {
|
||||
get pdfJsDocument() : Promise<PDFJSDocument> {
|
||||
switch (this.representationType) {
|
||||
case RepresentationType.PDFJSDocument:
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -75,12 +75,12 @@ export class PdfFile {
|
||||
default:
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const pdfjsDoc = await PDFJS.getDocument(await this.uint8Array).promise;
|
||||
this.pdfjsDocument = pdfjsDoc;
|
||||
this.pdfJsDocument = pdfjsDoc;
|
||||
resolve(pdfjsDoc);
|
||||
});
|
||||
}
|
||||
}
|
||||
set pdfjsDocument(value: PDFJSDocument) {
|
||||
set pdfJsDocument(value: PDFJSDocument) {
|
||||
this.representation = value;
|
||||
this.representationType = RepresentationType.PDFJSDocument;
|
||||
}
|
||||
@ -111,7 +111,7 @@ export class PdfFile {
|
||||
static async cacheAsPdfLibDocuments(files: PdfFile[]): Promise<Map<PdfFile, PDFLibDocument>> {
|
||||
const docCache = new Map<PdfFile, PDFLibDocument>();
|
||||
await Promise.all(files.map(async (file) => {
|
||||
const pdfLibDocument = await file.pdflibDocument;
|
||||
const pdfLibDocument = await file.pdfLibDocument;
|
||||
docCache.set(file, pdfLibDocument);
|
||||
}));
|
||||
return docCache;
|
||||
@ -119,7 +119,7 @@ export class PdfFile {
|
||||
static async cacheAsPdfJsDocuments(files: PdfFile[]): Promise<Map<PdfFile, PDFJSDocument>> {
|
||||
const docCache = new Map<PdfFile, PDFJSDocument>();
|
||||
await Promise.all(files.map(async (file) => {
|
||||
const pdfLibDocument = await file.pdfjsDocument;
|
||||
const pdfLibDocument = await file.pdfJsDocument;
|
||||
docCache.set(file, pdfLibDocument);
|
||||
}));
|
||||
return docCache;
|
||||
|
Loading…
x
Reference in New Issue
Block a user