mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-10-25 11:17:28 +02:00 
			
		
		
		
	Changed PdfFile.filename to exclude file extensions. Other naming fixes
This commit is contained in:
		
							parent
							
								
									667583984f
								
							
						
					
					
						commit
						576b0e02f6
					
				| @ -1,13 +1,13 @@ | |||||||
| 
 | 
 | ||||||
| import Operations from '../../utils/pdf-operations'; | import Operations from '../../utils/pdf-operations'; | ||||||
| import { respondWithPdfFile, response_mustHaveExactlyOneFile } from '../../utils/endpoint-utils'; | import { respondWithPdfFile, respondWithPdfFiles, response_mustHaveExactlyOneFile } from '../../utils/endpoint-utils'; | ||||||
| import { PdfFile, PdfFileSchema } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile' | import { PdfFile, PdfFileSchema } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile' | ||||||
| 
 | 
 | ||||||
| import express, { Request, Response, RequestHandler } from 'express'; | import express, { Request, Response, RequestHandler } from 'express'; | ||||||
| const router = express.Router(); | const router = express.Router(); | ||||||
| import multer from 'multer'; | import multer from 'multer'; | ||||||
| const upload = multer(); | const upload = multer(); | ||||||
| import Joi, { array } from 'joi'; | import Joi from 'joi'; | ||||||
| 
 | 
 | ||||||
| function registerEndpoint(endpoint: string, | function registerEndpoint(endpoint: string, | ||||||
|                           nameToAppend: string, |                           nameToAppend: string, | ||||||
| @ -37,32 +37,34 @@ function registerEndpoint(endpoint: string, | |||||||
|         } |         } | ||||||
|      |      | ||||||
|         const processed = await operationFunction(value) |         const processed = await operationFunction(value) | ||||||
|         if (Array.isArray(processed)) { | 
 | ||||||
|             // TODO zip multiple files
 |         if (body.files && Array.isArray(processed)) { // MIMO
 | ||||||
|         } else { |             respondWithPdfFiles(res, processed, nameToAppend); | ||||||
|             processed.filename = appendToFilename(processed.filename, nameToAppend); |         } else if (body.file && Array.isArray(processed)) { // SIMO
 | ||||||
|  |             respondWithPdfFiles(res, processed, body.file.filename + nameToAppend); | ||||||
|  |         } else if (body.files && !Array.isArray(processed)) { // MISO
 | ||||||
|  |             respondWithPdfFile(res, processed); | ||||||
|  |         } else if (body.file && !Array.isArray(processed)) { // SISO
 | ||||||
|             respondWithPdfFile(res, processed); |             respondWithPdfFile(res, processed); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | registerEndpoint("/merge-pdfs", "", upload.any(), Operations.mergePDFs, Joi.object({ | ||||||
|  * appends a string before the last '.' of the given filename |  | ||||||
|  */ |  | ||||||
| function appendToFilename(filename: string, str: string) { |  | ||||||
|     return filename.replace(/(\.[^.]+)$/, str+'$1') |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| registerEndpoint("/merge-pdfs", "_merged", upload.single("file"), Operations.mergePDFs, Joi.object({ |  | ||||||
|     files: Joi.array().items(PdfFileSchema).required(), |     files: Joi.array().items(PdfFileSchema).required(), | ||||||
| }).required()) | }).required()); | ||||||
| 
 | 
 | ||||||
| registerEndpoint("/rotate-pdf", "_rotated", upload.single("file"), Operations.rotatePages, Joi.object({ | registerEndpoint("/split-pdf", "_split", upload.single("file"), Operations.splitPDF, Joi.object({ | ||||||
|  |     file: PdfFileSchema.required(), | ||||||
|  |     pageNumbers: Joi.string().required(), | ||||||
|  | }).required()); | ||||||
|  | 
 | ||||||
|  | registerEndpoint("/rotate-pdf", "", upload.single("file"), Operations.rotatePages, Joi.object({ | ||||||
|     file: PdfFileSchema.required(), |     file: PdfFileSchema.required(), | ||||||
|     rotation: Joi.alternatives().try(Joi.number(), Joi.array().items(Joi.number())).required(), |     rotation: Joi.alternatives().try(Joi.number(), Joi.array().items(Joi.number())).required(), | ||||||
| }).required()) | }).required()); | ||||||
| 
 | 
 | ||||||
| registerEndpoint("/update-metadata", "_edited-metadata", upload.single("file"), Operations.updateMetadata, Joi.object({ | registerEndpoint("/update-metadata", "", upload.single("file"), Operations.updateMetadata, Joi.object({ | ||||||
|     file: PdfFileSchema.required(), |     file: PdfFileSchema.required(), | ||||||
|     deleteAll: Joi.string(), |     deleteAll: Joi.string(), | ||||||
|     author: Joi.string(), |     author: Joi.string(), | ||||||
| @ -75,6 +77,6 @@ registerEndpoint("/update-metadata", "_edited-metadata", upload.single("file"), | |||||||
|     title: Joi.string(), |     title: Joi.string(), | ||||||
|     trapped: Joi.string(), |     trapped: Joi.string(), | ||||||
|     allRequestParams: Joi.object().pattern(Joi.string(), Joi.string()), |     allRequestParams: Joi.object().pattern(Joi.string(), Joi.string()), | ||||||
| }).required()) | }).required()); | ||||||
| 
 | 
 | ||||||
| export default router; | export default router; | ||||||
| @ -1,13 +1,12 @@ | |||||||
| import express, { Request, Response } from 'express'; | import express, { Request, Response } from 'express'; | ||||||
| import crypto from 'crypto'; | import crypto from 'crypto'; | ||||||
| import stream from "stream"; |  | ||||||
| import Archiver from 'archiver'; |  | ||||||
| import multer from 'multer' | import multer from 'multer' | ||||||
| const upload = multer(); | const upload = multer(); | ||||||
| 
 | 
 | ||||||
| import Operations from "../../utils/pdf-operations"; | import Operations from "../../utils/pdf-operations"; | ||||||
| import { traverseOperations } from "@stirling-pdf/shared-operations/src/workflow/traverseOperations"; | import { traverseOperations } from "@stirling-pdf/shared-operations/src/workflow/traverseOperations"; | ||||||
| import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'; | import { PdfFile, RepresentationType } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'; | ||||||
|  | import { respondWithPdfFiles } from '../../utils/endpoint-utils'; | ||||||
| 
 | 
 | ||||||
| const activeWorkflows: any = {}; | const activeWorkflows: any = {}; | ||||||
| 
 | 
 | ||||||
| @ -50,7 +49,7 @@ router.post("/:workflowUuid?", [ | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             console.log("Download"); |             console.log("Download"); | ||||||
|             await downloadHandler(res, pdfResults); |             await respondWithPdfFiles(res, pdfResults, "workflow-results"); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             console.log("Start Aync Workflow"); |             console.log("Start Aync Workflow"); | ||||||
| @ -164,7 +163,7 @@ router.get("/result/:workflowUuid", async (req: Request, res: Response) => { | |||||||
|         return |         return | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     await downloadHandler(res, workflow.result); |     await respondWithPdfFiles(res, workflow.result, "workflow-results"); | ||||||
|     // Delete workflow / results when done.
 |     // Delete workflow / results when done.
 | ||||||
|     delete activeWorkflows[req.params.workflowUuid]; |     delete activeWorkflows[req.params.workflowUuid]; | ||||||
| }); | }); | ||||||
| @ -187,43 +186,4 @@ function generateWorkflowID() { | |||||||
|     return crypto.randomUUID(); |     return crypto.randomUUID(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function downloadHandler(res: Response, pdfResults: PdfFile[]) { |  | ||||||
|     if(pdfResults.length == 0) { |  | ||||||
|         res.status(500).json({"warning": "The workflow had no outputs."}); |  | ||||||
|     }  |  | ||||||
|     else if(pdfResults.length > 1) { |  | ||||||
|         // TODO: Also allow the user to download multiple files without zip compressen, because this is kind of slow...
 |  | ||||||
|         res.writeHead(200, { |  | ||||||
|             'Content-Type': 'application/zip', |  | ||||||
|             'Content-disposition': 'attachment; filename=workflow-results.zip' |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         var zip = Archiver('zip'); |  | ||||||
| 
 |  | ||||||
|         // Stream the file to the user.
 |  | ||||||
|         zip.pipe(res); |  | ||||||
| 
 |  | ||||||
|         console.log("Adding Files to ZIP..."); |  | ||||||
| 
 |  | ||||||
|         for (let i = 0; i < pdfResults.length; i++) { |  | ||||||
|             // TODO: Implement other file types (mostly fro image & text extraction)
 |  | ||||||
|             // TODO: Check for name collisions
 |  | ||||||
|             zip.append(Buffer.from(await pdfResults[i].uint8Array), { name: pdfResults[i].filename + ".pdf" });    |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         zip.finalize(); |  | ||||||
|         console.log("Sent"); |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         const readStream = new stream.PassThrough(); |  | ||||||
|         readStream.end(await pdfResults[0].uint8Array); |  | ||||||
| 
 |  | ||||||
|         // TODO: Implement other file types (mostly fro image & text extraction)
 |  | ||||||
|         res.set("Content-disposition", 'attachment; filename=' + pdfResults[0].filename + ".pdf"); |  | ||||||
|         res.set("Content-Type", "application/pdf"); |  | ||||||
| 
 |  | ||||||
|         readStream.pipe(res); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default router; | export default router; | ||||||
| @ -1,19 +1,64 @@ | |||||||
| 
 | 
 | ||||||
| import { Response } from 'express'; | import { Response } from 'express'; | ||||||
| import { PdfFile } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile' | import { PdfFile } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile' | ||||||
|  | import Archiver from 'archiver'; | ||||||
| 
 | 
 | ||||||
| export async function respondWithFile(res: Response, bytes: Uint8Array, name: string, mimeType: string): Promise<void> { | export async function respondWithFile(res: Response, uint8Array: Uint8Array, filename: string, mimeType: string): Promise<void> { | ||||||
|     res.writeHead(200, { |     res.writeHead(200, { | ||||||
|         'Content-Type': mimeType, |         'Content-Type': mimeType, | ||||||
|         'Content-disposition': 'attachment;filename=' + name, |         'Content-disposition': `attachment; filename="${filename}"`, | ||||||
|         'Content-Length': bytes.length |         'Content-Length': uint8Array.length | ||||||
|     }); |     }); | ||||||
|     res.end(bytes); |     res.end(uint8Array); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function respondWithPdfFile(res: Response, file: PdfFile): Promise<void> { | export async function respondWithPdfFile(res: Response, file: PdfFile): Promise<void> { | ||||||
|     const byteArray = await file.uint8Array; |     const byteArray = await file.uint8Array; | ||||||
|     respondWithFile(res, byteArray, file.filename, "application/pdf"); |     respondWithFile(res, byteArray, file.filename+".pdf", "application/pdf"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export async function respondWithZip(res: Response, filename: string, files: {uint8Array: Uint8Array, filename: string}[]): Promise<void> { | ||||||
|  |     if (files.length == 0) { | ||||||
|  |         res.status(500).json({"warning": "The workflow had no outputs."}); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     console.log(filename) | ||||||
|  |     res.writeHead(200, { | ||||||
|  |         'Content-Type': 'application/zip', | ||||||
|  |         'Content-disposition': `attachment; filename="${filename}.zip"`, | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     // TODO: Also allow changing the compression level
 | ||||||
|  |     var zip = Archiver('zip'); | ||||||
|  | 
 | ||||||
|  |     // Stream the file to the user.
 | ||||||
|  |     zip.pipe(res); | ||||||
|  | 
 | ||||||
|  |     console.log("Adding Files to ZIP..."); | ||||||
|  | 
 | ||||||
|  |     for (let i = 0; i < files.length; i++) { | ||||||
|  |         zip.append(Buffer.from(files[i].uint8Array), { name: files[i].filename });    | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     zip.finalize(); | ||||||
|  |     console.log("Sent"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export async function respondWithPdfFiles(res: Response, pdfFiles: PdfFile|PdfFile[], filename: string) { | ||||||
|  |     const pdfResults = Array.isArray(pdfFiles) ? pdfFiles : [pdfFiles]; | ||||||
|  | 
 | ||||||
|  |     if(pdfResults.length == 0) { | ||||||
|  |         res.status(500).json({"warning": "The workflow had no outputs."}); | ||||||
|  |     } | ||||||
|  |     else if (pdfResults.length == 1) { | ||||||
|  |         respondWithPdfFile(res, pdfResults[0]) | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         const promises = pdfResults.map(async (pdf) => {return{uint8Array: await pdf.uint8Array, filename: pdf.filename + ".pdf"}}) | ||||||
|  |         const files = await Promise.all(promises); | ||||||
|  |         respondWithZip(res, filename, files); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function response_mustHaveExactlyOneFile(res: Response): void { | export function response_mustHaveExactlyOneFile(res: Response): void { | ||||||
|  | |||||||
| @ -12,7 +12,8 @@ export type ImposeParamsBaseType = { | |||||||
|     pdfcpuWrapper: any; |     pdfcpuWrapper: any; | ||||||
| } | } | ||||||
| export async function impose(params: ImposeParamsBaseType): Promise<PdfFile> { | export async function impose(params: ImposeParamsBaseType): Promise<PdfFile> { | ||||||
|     const result = new PdfFile(params.file.originalFilename, await params.pdfcpuWrapper.oneToOne([ |     const uint8Array = await params.pdfcpuWrapper.oneToOne( | ||||||
|  |         [ | ||||||
|             "pdfcpu.wasm", |             "pdfcpu.wasm", | ||||||
|             "nup", |             "nup", | ||||||
|             "-c", |             "-c", | ||||||
| @ -21,7 +22,17 @@ export async function impose(params: ImposeParamsBaseType): Promise<PdfFile> { | |||||||
|             "/output.pdf", |             "/output.pdf", | ||||||
|             String(params.nup), |             String(params.nup), | ||||||
|             "input.pdf", |             "input.pdf", | ||||||
|         ], await params.file.uint8Array), RepresentationType.Uint8Array, params.file.filename + "_imposed"); |         ], | ||||||
|  |         await params.file.uint8Array | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     const result = new PdfFile( | ||||||
|  |         params.file.originalFilename, | ||||||
|  |         uint8Array, | ||||||
|  |         RepresentationType.Uint8Array, | ||||||
|  |         params.file.filename + "_imposed" | ||||||
|  |     ); | ||||||
|  |      | ||||||
|     console.log("ImposeResult: ", result); |     console.log("ImposeResult: ", result); | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| @ -15,5 +15,6 @@ export async function mergePDFs(params: MergeParamsType): Promise<PdfFile> { | |||||||
|         copiedPages.forEach((page) => mergedPdf.addPage(page)); |         copiedPages.forEach((page) => mergedPdf.addPage(page)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return new PdfFile("mergedPDF", mergedPdf, RepresentationType.PDFLibDocument); |     const newName = "("+params.files.map(input => input.filename).join("_and_") + ")_merged" | ||||||
|  |     return new PdfFile("mergedPDF", mergedPdf, RepresentationType.PDFLibDocument, newName); | ||||||
| }; | }; | ||||||
| @ -1,6 +1,6 @@ | |||||||
| 
 | 
 | ||||||
| import { degrees } from 'pdf-lib'; | import { degrees } from 'pdf-lib'; | ||||||
| import { PdfFile } from '../wrappers/PdfFile'; | import { PdfFile, RepresentationType } from '../wrappers/PdfFile'; | ||||||
| 
 | 
 | ||||||
| export type RotateParamsType = { | export type RotateParamsType = { | ||||||
|     file: PdfFile; |     file: PdfFile; | ||||||
| @ -10,7 +10,8 @@ export type RotateParamsType = { | |||||||
| export async function rotatePages(params: RotateParamsType): Promise<PdfFile> { | export async function rotatePages(params: RotateParamsType): Promise<PdfFile> { | ||||||
|     const { file, rotation } = params; |     const { file, rotation } = params; | ||||||
|      |      | ||||||
|     const pages = (await file.pdfLibDocument).getPages(); |     const pdfDoc = await file.pdfLibDocument; | ||||||
|  |     const pages = pdfDoc.getPages(); | ||||||
| 
 | 
 | ||||||
|     if (Array.isArray(rotation)) { |     if (Array.isArray(rotation)) { | ||||||
|         if (rotation.length != pages.length) { |         if (rotation.length != pages.length) { | ||||||
| @ -28,5 +29,5 @@ export async function rotatePages(params: RotateParamsType): Promise<PdfFile> { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return file; |     return new PdfFile(file.originalFilename, pdfDoc, RepresentationType.PDFLibDocument, file.filename+"_rotated"); | ||||||
| }; | }; | ||||||
| @ -1,6 +1,6 @@ | |||||||
| 
 | 
 | ||||||
| import { PDFPage } from 'pdf-lib'; | import { PDFPage } from 'pdf-lib'; | ||||||
| import { PdfFile } from '../wrappers/PdfFile'; | import { PdfFile, RepresentationType } from '../wrappers/PdfFile'; | ||||||
| 
 | 
 | ||||||
| export type ScaleContentParamsType = { | export type ScaleContentParamsType = { | ||||||
|     file: PdfFile; |     file: PdfFile; | ||||||
| @ -24,7 +24,7 @@ export async function scaleContent(params: ScaleContentParamsType): Promise<PdfF | |||||||
|         pages.forEach(page => scalePage(page, scaleFactor)); |         pages.forEach(page => scalePage(page, scaleFactor)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return file; |     return new PdfFile(file.originalFilename, pdfDoc, RepresentationType.PDFLibDocument, file.filename+"_scaledContent"); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function scalePage(page: PDFPage, scaleFactor: number) { | function scalePage(page: PDFPage, scaleFactor: number) { | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| 
 | 
 | ||||||
| import { PDFPage } from 'pdf-lib'; | import { PDFPage } from 'pdf-lib'; | ||||||
| import { PdfFile } from '../wrappers/PdfFile'; | import { PdfFile, RepresentationType } from '../wrappers/PdfFile'; | ||||||
| 
 | 
 | ||||||
| export type ScalePageParamsType = { | export type ScalePageParamsType = { | ||||||
|     file: PdfFile; |     file: PdfFile; | ||||||
| @ -24,7 +24,7 @@ export async function scalePage(params: ScalePageParamsType): Promise<PdfFile> { | |||||||
|         pages.forEach(page => resize(page, pageSize)); |         pages.forEach(page => resize(page, pageSize)); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return file; |     return new PdfFile(file.originalFilename, pdfDoc, RepresentationType.PDFLibDocument, file.filename+"_scaledPages"); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| function resize(page: PDFPage, newSize: {width?:number,height?:number}) { | function resize(page: PDFPage, newSize: {width?:number,height?:number}) { | ||||||
|  | |||||||
| @ -41,7 +41,7 @@ export async function splitOn(params: SplitOnParamsType) { | |||||||
|     console.log("File: ", file); |     console.log("File: ", file); | ||||||
| 
 | 
 | ||||||
|     // Remove detected Pages & Split
 |     // Remove detected Pages & Split
 | ||||||
|     const pdfDoc = await file.pdfLibDocument; |     const pdfDoc = await file.pdflibDocument; | ||||||
|     const numberOfPages = pdfDoc.getPageCount(); |     const numberOfPages = pdfDoc.getPageCount(); | ||||||
| 
 | 
 | ||||||
|     let pagesArray: number[] = []; |     let pagesArray: number[] = []; | ||||||
| @ -71,7 +71,7 @@ export async function splitOn(params: SplitOnParamsType) { | |||||||
| 
 | 
 | ||||||
|     async function getPagesWithQRCode(file: PdfFile) { |     async function getPagesWithQRCode(file: PdfFile) { | ||||||
|         console.log("FileInQRPrev: ", file); |         console.log("FileInQRPrev: ", file); | ||||||
|         const pdfDoc = await file.pdfJsDocument; |         const pdfDoc = await file.pdfjsDocument; | ||||||
|         console.log("FileInQRAfter: ", file); |         console.log("FileInQRAfter: ", file); | ||||||
| 
 | 
 | ||||||
|         const pagesWithQR: number[] = []; |         const pagesWithQR: number[] = []; | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType) | |||||||
|         throw new Error("Operation not supported"); |         throw new Error("Operation not supported"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const pdflibDocument = await file.pdfLibDocument; |     const pdflibDocument = await file.pdflibDocument; | ||||||
|      |      | ||||||
|     const pageCount = pdflibDocument.getPageCount(); |     const pageCount = pdflibDocument.getPageCount(); | ||||||
|     const sortIndecies = sortFunction(pageCount); |     const sortIndecies = sortFunction(pageCount); | ||||||
| @ -36,7 +36,7 @@ export type RearrangePagesParamsType = { | |||||||
| export async function rearrangePages(params: RearrangePagesParamsType): Promise<PdfFile> { | export async function rearrangePages(params: RearrangePagesParamsType): Promise<PdfFile> { | ||||||
|     const { file, fancyPageSelector } = params; |     const { file, fancyPageSelector } = params; | ||||||
| 
 | 
 | ||||||
|     const pdflibDocument = await file.pdfLibDocument; |     const pdflibDocument = await file.pdflibDocument; | ||||||
| 
 | 
 | ||||||
|     const pagesToExtractArray = parseFancyPageSelector(fancyPageSelector, pdflibDocument.getPageCount()); |     const pagesToExtractArray = parseFancyPageSelector(fancyPageSelector, pdflibDocument.getPageCount()); | ||||||
|     const newDocument = selectPages({file: file, pagesToExtractArray}); |     const newDocument = selectPages({file: file, pagesToExtractArray}); | ||||||
| @ -50,7 +50,7 @@ export type SelectPagesParamsType = { | |||||||
| export async function selectPages(params: SelectPagesParamsType): Promise<PdfFile> { | export async function selectPages(params: SelectPagesParamsType): Promise<PdfFile> { | ||||||
|     const { file, pagesToExtractArray } = params; |     const { file, pagesToExtractArray } = params; | ||||||
| 
 | 
 | ||||||
|     const pdflibDocument = await file.pdfLibDocument; |     const pdflibDocument = await file.pdflibDocument; | ||||||
| 
 | 
 | ||||||
|     const subDocument = await PDFDocument.create(); |     const subDocument = await PDFDocument.create(); | ||||||
| 
 | 
 | ||||||
| @ -75,7 +75,7 @@ export type RemovePagesParamsType = { | |||||||
| export async function removePages(params: RemovePagesParamsType): Promise<PdfFile> { | export async function removePages(params: RemovePagesParamsType): Promise<PdfFile> { | ||||||
|     const { file, pagesToRemoveArray } = params; |     const { file, pagesToRemoveArray } = params; | ||||||
| 
 | 
 | ||||||
|     const pdflibDocument = await file.pdfLibDocument; |     const pdflibDocument = await file.pdflibDocument; | ||||||
| 
 | 
 | ||||||
|     const pagesToExtractArray = invertSelection(pagesToRemoveArray, pdflibDocument.getPageIndices()) |     const pagesToExtractArray = invertSelection(pagesToRemoveArray, pdflibDocument.getPageIndices()) | ||||||
|     return selectPages({file: file, pagesToExtractArray}); |     return selectPages({file: file, pagesToExtractArray}); | ||||||
|  | |||||||
| @ -86,8 +86,13 @@ export class PdfFile { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     constructor(originalFilename: string, representation: Uint8Array | PDFLibDocument | PDFJSDocument, representationType: RepresentationType, filename?: string) { |     constructor(originalFilename: string, representation: Uint8Array | PDFLibDocument | PDFJSDocument, representationType: RepresentationType, filename?: string) { | ||||||
|  |         if (originalFilename.toLowerCase().endsWith(".pdf")) | ||||||
|  |             originalFilename = originalFilename.slice(0, -4); | ||||||
|         this.originalFilename = originalFilename; |         this.originalFilename = originalFilename; | ||||||
|  |          | ||||||
|         this.filename = filename ? filename : originalFilename; |         this.filename = filename ? filename : originalFilename; | ||||||
|  |         if (this.filename.toLowerCase().endsWith(".pdf")) | ||||||
|  |         this.filename = this.filename.slice(0, -4); | ||||||
| 
 | 
 | ||||||
|         this.representation = representation; |         this.representation = representation; | ||||||
|         this.representationType = representationType; |         this.representationType = representationType; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user