Renamed editMetadata to match V1 naming. Added Operations controller
This commit is contained in:
@@ -3,14 +3,14 @@ import { PDFDocument, ParseSpeeds } from 'pdf-lib';
|
||||
|
||||
|
||||
export type Metadata = {
|
||||
Title: string | null | undefined; // The title of the document.
|
||||
Author: string | null | undefined; // The author of the document.
|
||||
Subject: string | null | undefined; // The subject of the document.
|
||||
Keywords: string[] | null | undefined; // An array of keywords associated with the document.
|
||||
Producer: string | null | undefined; // The producer of the document.
|
||||
Creator: string | null | undefined; // The creator of the document.
|
||||
CreationDate: Date | null | undefined; // The date when the document was created.
|
||||
ModificationDate: Date | null | undefined; // The date when the document was last modified.
|
||||
Title?: string; // The title of the document.
|
||||
Author?: string; // The author of the document.
|
||||
Subject?: string; // The subject of the document.
|
||||
Keywords?: string[]; // An array of keywords associated with the document.
|
||||
Producer?: string; // The producer of the document.
|
||||
Creator?: string; // The creator of the document.
|
||||
CreationDate?: Date; // The date when the document was created.
|
||||
ModificationDate?: Date; // The date when the document was last modified.
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -18,7 +18,7 @@ export type Metadata = {
|
||||
* @param {Metadata} metadata - Set property to null or "" to clear, undefined properties will be skipped.
|
||||
* @returns Promise<Uint8Array>
|
||||
*/
|
||||
export async function editMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata): Promise<Uint8Array> {
|
||||
export async function updateMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata): Promise<Uint8Array> {
|
||||
// Load the original PDF file
|
||||
const pdfDoc = await PDFDocument.load(snapshot, {
|
||||
parseSpeed: ParseSpeeds.Fastest,
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
// Import injected libraries here!
|
||||
|
||||
import { editMetadata } from "./functions/editMetadata";
|
||||
import { extractPages } from "./functions/extractPages";
|
||||
import { impose } from "./functions/impose";
|
||||
import { mergePDFs } from './functions/mergePDFs';
|
||||
@@ -12,9 +11,9 @@ import { scaleContent} from './functions/scaleContent';
|
||||
import { scalePage } from './functions/scalePage';
|
||||
import { splitOn } from './functions/splitOn';
|
||||
import { splitPDF } from './functions/splitPDF';
|
||||
import { updateMetadata } from "./functions/updateMetadata";
|
||||
|
||||
export default {
|
||||
editMetadata,
|
||||
extractPages,
|
||||
impose,
|
||||
mergePDFs,
|
||||
@@ -25,4 +24,5 @@ export default {
|
||||
scalePage,
|
||||
splitOn,
|
||||
splitPDF,
|
||||
updateMetadata,
|
||||
}
|
||||
@@ -113,10 +113,10 @@ export async function * traverseOperations(operations, input, Operations) {
|
||||
return splits;
|
||||
});
|
||||
break;
|
||||
case "editMetadata":
|
||||
case "updateMetadata":
|
||||
yield* nToN(input, operation, async (input) => {
|
||||
input.fileName += "_metadataEdited";
|
||||
input.buffer = await Operations.editMetadata(input.buffer, operation.values["metadata"]);
|
||||
input.buffer = await Operations.updateMetadata(input.buffer, operation.values["metadata"]);
|
||||
});
|
||||
break;
|
||||
case "organizePages":
|
||||
|
||||
Reference in New Issue
Block a user