mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 16:57:14 +01:00
- Replaced direct calls to PDFDocument.load with loadPdfDocument in multiple nodes to standardize PDF loading process.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { ClassicPreset } from 'rete';
|
|
import { BaseWorkflowNode } from './base-node';
|
|
import { pdfSocket } from '../sockets';
|
|
import type { SocketData } from '../types';
|
|
import { requirePdfInput, processBatch } from '../types';
|
|
import { PDFName } from 'pdf-lib';
|
|
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
|
|
|
export class RemoveAnnotationsNode extends BaseWorkflowNode {
|
|
readonly category = 'Edit & Annotate' as const;
|
|
readonly icon = 'ph-eraser';
|
|
readonly description = 'Strip all annotations';
|
|
|
|
constructor() {
|
|
super('Remove Annotations');
|
|
this.addInput('pdf', new ClassicPreset.Input(pdfSocket, 'PDF'));
|
|
this.addOutput('pdf', new ClassicPreset.Output(pdfSocket, 'Clean PDF'));
|
|
}
|
|
|
|
async data(
|
|
inputs: Record<string, SocketData[]>
|
|
): Promise<Record<string, SocketData>> {
|
|
const pdfInputs = requirePdfInput(inputs, 'Remove Annotations');
|
|
|
|
return {
|
|
pdf: await processBatch(pdfInputs, async (input) => {
|
|
const pdfDoc = await loadPdfDocument(input.bytes);
|
|
const pages = pdfDoc.getPages();
|
|
|
|
for (const page of pages) {
|
|
const annots = page.node.Annots();
|
|
if (annots) {
|
|
page.node.delete(PDFName.of('Annots'));
|
|
}
|
|
}
|
|
|
|
const pdfBytes = await pdfDoc.save();
|
|
return {
|
|
type: 'pdf',
|
|
document: pdfDoc,
|
|
bytes: new Uint8Array(pdfBytes),
|
|
filename: input.filename.replace(/\.pdf$/i, '_clean.pdf'),
|
|
};
|
|
}),
|
|
};
|
|
}
|
|
}
|