cleaned up node server
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Metadata
|
||||
* @property {string | null | undefined} Title - The title of the document.
|
||||
@@ -14,10 +17,10 @@
|
||||
*
|
||||
* @param {Uint16Array} snapshot
|
||||
* @param {Metadata} metadata - Set property to null or "" to clear, undefined properties will be skipped.
|
||||
* @param {import('pdf-lib')} PDFLib
|
||||
* @param {PDFLib} PDFLib
|
||||
* @returns
|
||||
*/
|
||||
export async function editMetadata(snapshot, metadata, PDFLib) {
|
||||
export async function editMetadata(snapshot, metadata) {
|
||||
// Load the original PDF file
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
|
||||
parseSpeed: PDFLib.ParseSpeeds.Fastest,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
export async function extractPages(snapshot, pagesToExtractArray, PDFLib) {
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
export async function extractPages(snapshot, pagesToExtractArray) {
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot)
|
||||
|
||||
// TODO: invent a better format for pagesToExtractArray and convert it.
|
||||
return createSubDocument(pdfDoc, pagesToExtractArray, PDFLib);
|
||||
return createSubDocument(pdfDoc, pagesToExtractArray);
|
||||
};
|
||||
|
||||
export async function createSubDocument(pdfDoc, pagesToExtractArray, PDFLib) {
|
||||
export async function createSubDocument(pdfDoc, pagesToExtractArray) {
|
||||
const subDocument = await PDFLib.PDFDocument.create();
|
||||
|
||||
// Check that array max number is not larger pdf pages number
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
export async function impose(snapshot, nup, format, pdfcpuWrapper) {
|
||||
return await pdfcpuWrapper.oneToOne([
|
||||
"pdfcpu.wasm",
|
||||
"nup",
|
||||
"-c",
|
||||
"disable",
|
||||
'f:' + format,
|
||||
"/output.pdf",
|
||||
String(nup),
|
||||
"input.pdf",
|
||||
], snapshot);
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
export const mergePDFs = async (snapshots, PDFLib) => {
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
export const mergePDFs = async (snapshots) => {
|
||||
|
||||
const mergedPdf = await PDFLib.PDFDocument.create();
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
/**
|
||||
* @typedef {"CUSTOM_PAGE_ORDER"|"REVERSE_ORDER"|"DUPLEX_SORT"|"BOOKLET_SORT"|"ODD_EVEN_SPLIT"|"REMOVE_FIRST"|"REMOVE_LAST"|"REMOVE_FIRST_AND_LAST"} OrderOperation
|
||||
*/
|
||||
@@ -10,7 +13,7 @@
|
||||
* @param {import('pdf-lib')} PDFLib
|
||||
* @returns
|
||||
*/
|
||||
export async function organizePages(snapshot, operation, customOrderString, PDFLib) {
|
||||
export async function organizePages(snapshot, operation, customOrderString) {
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot);
|
||||
let subDocument = await PDFLib.PDFDocument.create();
|
||||
const copiedPages = await subDocument.copyPages(pdfDoc, pdfDoc.getPageIndices());
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export async function rotatePages (snapshot, rotation, PDFLib) {
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
export async function rotatePages (snapshot, rotation) {
|
||||
// Load the original PDF file
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
|
||||
parseSpeed: PDFLib.ParseSpeeds.Fastest,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export async function scaleContent(snapshot, scaleFactor, PDFLib) {
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
export async function scaleContent(snapshot, scaleFactor) {
|
||||
// Load the original PDF file
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
|
||||
parseSpeed: PDFLib.ParseSpeeds.Fastest,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
export async function scalePage(snapshot, pageSize, PDFLib) {
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
export async function scalePage(snapshot, pageSize) {
|
||||
// Load the original PDF file
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot, {
|
||||
parseSpeed: PDFLib.ParseSpeeds.Fastest,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
import PDFLib from 'pdf-lib';
|
||||
|
||||
import { createSubDocument } from "./extractPages.js";
|
||||
|
||||
export async function splitPDF(snapshot, splitAfterPageArray, PDFLib) {
|
||||
export async function splitPDF(snapshot, splitAfterPageArray) {
|
||||
const pdfDoc = await PDFLib.PDFDocument.load(snapshot)
|
||||
|
||||
const numberOfPages = pdfDoc.getPages().length;
|
||||
@@ -11,13 +14,13 @@ export async function splitPDF(snapshot, splitAfterPageArray, PDFLib) {
|
||||
|
||||
for (let i = 0; i < numberOfPages; i++) {
|
||||
if(i > splitAfter && pagesArray.length > 0) {
|
||||
subDocuments.push(await createSubDocument(pdfDoc, pagesArray, PDFLib));
|
||||
subDocuments.push(await createSubDocument(pdfDoc, pagesArray));
|
||||
splitAfter = splitAfterPageArray.shift();
|
||||
pagesArray = [];
|
||||
}
|
||||
pagesArray.push(i);
|
||||
}
|
||||
subDocuments.push(await createSubDocument(pdfDoc, pagesArray, PDFLib));
|
||||
subDocuments.push(await createSubDocument(pdfDoc, pagesArray));
|
||||
pagesArray = [];
|
||||
|
||||
return subDocuments;
|
||||
|
||||
Reference in New Issue
Block a user