Capitalised pdfJsDocument and pdfLibDocument

This commit is contained in:
Saud Fatayerji 2023-11-15 02:38:07 +03:00
parent 5f23491189
commit 57415bea85
10 changed files with 21 additions and 21 deletions

View File

@ -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++) {

View File

@ -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));
}

View File

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

View File

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

View File

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

View File

@ -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[] = [];

View File

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

View File

@ -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});

View File

@ -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("");

View File

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