- Refactor PDF loading across workflow nodes to use loadPdfDocument utility
- Replaced direct calls to PDFDocument.load with loadPdfDocument in multiple nodes to standardize PDF loading process.
This commit is contained in:
@@ -3,7 +3,7 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class AddBlankPageNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -47,7 +47,7 @@ export class AddBlankPageNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
const firstPage = pdfDoc.getPages()[0];
|
||||
const { width, height } = firstPage
|
||||
? firstPage.getSize()
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument, rgb } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class BackgroundColorNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -34,7 +35,7 @@ export class BackgroundColorNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const newDoc = await PDFDocument.create();
|
||||
|
||||
for (let i = 0; i < srcDoc.getPageCount(); i++) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument, PageSizes } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
const paperSizeLookup: Record<string, [number, number]> = {
|
||||
Letter: PageSizes.Letter,
|
||||
@@ -88,7 +89,7 @@ export class BookletNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const sourceDoc = await PDFDocument.load(input.bytes);
|
||||
const sourceDoc = await loadPdfDocument(input.bytes);
|
||||
const totalPages = sourceDoc.getPageCount();
|
||||
const pagesPerSheet = rows * cols;
|
||||
const outputDoc = await PDFDocument.create();
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class CbzToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -55,7 +55,7 @@ export class CbzToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const blob = await pymupdf.convertToPdf(file, { filetype: 'cbz' });
|
||||
const bytes = new Uint8Array(await blob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -3,13 +3,13 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import {
|
||||
performCondenseCompression,
|
||||
performPhotonCompression,
|
||||
} from '../../utils/compress.js';
|
||||
import type { CondenseCustomSettings } from '../../utils/compress.js';
|
||||
import { isPyMuPDFAvailable } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class CompressNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -115,7 +115,7 @@ export class CompressNode extends BaseWorkflowNode {
|
||||
pdfBytes = await performPhotonCompression(arrayBuffer, level);
|
||||
}
|
||||
|
||||
const document = await PDFDocument.load(pdfBytes);
|
||||
const document = await loadPdfDocument(pdfBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,7 +3,7 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class CropNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -51,7 +51,7 @@ export class CropNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
const pages = pdfDoc.getPages();
|
||||
|
||||
for (const page of pages) {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { decryptPdfBytes } from '../../utils/pdf-decrypt.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class DecryptNode extends BaseWorkflowNode {
|
||||
readonly category = 'Secure PDF' as const;
|
||||
@@ -37,7 +37,7 @@ export class DecryptNode extends BaseWorkflowNode {
|
||||
input.bytes,
|
||||
password
|
||||
);
|
||||
const document = await PDFDocument.load(resultBytes, {
|
||||
const document = await loadPdfDocument(resultBytes, {
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { deletePdfPages, parseDeletePages } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class DeletePagesNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -32,11 +32,11 @@ export class DeletePagesNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const totalPages = srcDoc.getPageCount();
|
||||
const pagesToDelete = parseDeletePages(deleteStr, totalPages);
|
||||
const resultBytes = await deletePdfPages(input.bytes, pagesToDelete);
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
return {
|
||||
type: 'pdf',
|
||||
document: resultDoc,
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class DeskewNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -51,7 +51,7 @@ export class DeskewNode extends BaseWorkflowNode {
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(await resultPdf.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,13 +3,13 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import {
|
||||
signPdf,
|
||||
parsePfxFile,
|
||||
parseCombinedPem,
|
||||
} from '../../logic/digital-sign-pdf.js';
|
||||
import type { CertificateData } from '@/types';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class DigitalSignNode extends BaseWorkflowNode {
|
||||
readonly category = 'Secure PDF' as const;
|
||||
@@ -117,7 +117,7 @@ export class DigitalSignNode extends BaseWorkflowNode {
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(signedBytes);
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { parsePageRange } from '../../utils/pdf-operations';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class DividePagesNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -42,7 +43,7 @@ export class DividePagesNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const newDoc = await PDFDocument.create();
|
||||
const totalPages = srcDoc.getPageCount();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class EditMetadataNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -61,7 +61,7 @@ export class EditMetadataNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
|
||||
if (title) pdfDoc.setTitle(title);
|
||||
if (author) pdfDoc.setAuthor(author);
|
||||
|
||||
@@ -2,9 +2,9 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { parseEmailFile, renderEmailToHtml } from '../../logic/email-to-pdf.js';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class EmailToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -87,7 +87,11 @@ export class EmailToPdfNode extends BaseWorkflowNode {
|
||||
pageSize,
|
||||
});
|
||||
|
||||
const pdfBlob = await (pymupdf as any).htmlToPdf(htmlContent, {
|
||||
const pdfBlob = await (
|
||||
pymupdf as unknown as {
|
||||
htmlToPdf(html: string, options: unknown): Promise<Blob>;
|
||||
}
|
||||
).htmlToPdf(htmlContent, {
|
||||
pageSize,
|
||||
margins: { top: 50, right: 50, bottom: 50, left: 50 },
|
||||
attachments: email.attachments
|
||||
@@ -99,7 +103,7 @@ export class EmailToPdfNode extends BaseWorkflowNode {
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { initializeQpdf } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class EncryptNode extends BaseWorkflowNode {
|
||||
readonly category = 'Secure PDF' as const;
|
||||
@@ -90,9 +90,7 @@ export class EncryptNode extends BaseWorkflowNode {
|
||||
}
|
||||
|
||||
const resultBytes = new Uint8Array(encryptedData);
|
||||
const document = await PDFDocument.load(resultBytes, {
|
||||
ignoreEncryption: true,
|
||||
});
|
||||
const document = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class EpubToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -54,7 +54,7 @@ export class EpubToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const blob = await pymupdf.convertToPdf(file, { filetype: 'epub' });
|
||||
const bytes = new Uint8Array(await blob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class ExcelToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -62,7 +62,7 @@ export class ExcelToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData, MultiPDFData } from '../types';
|
||||
import { requirePdfInput, extractAllPdfs } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { parsePageRange } from '../../utils/pdf-operations';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class ExtractPagesNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -37,7 +38,7 @@ export class ExtractPagesNode extends BaseWorkflowNode {
|
||||
|
||||
const allItems = [];
|
||||
for (const input of allPdfs) {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const totalPages = srcDoc.getPageCount();
|
||||
const indices = parsePageRange(rangeStr, totalPages);
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class Fb2ToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -54,7 +54,7 @@ export class Fb2ToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const blob = await pymupdf.convertToPdf(file, { filetype: 'fb2' });
|
||||
const bytes = new Uint8Array(await blob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -4,8 +4,8 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { fixPageSize } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class FixPageSizeNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -90,7 +90,7 @@ export class FixPageSizeNode extends BaseWorkflowNode {
|
||||
customUnits,
|
||||
});
|
||||
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { flattenAnnotations } from '../../utils/flatten-annotations.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class FlattenNode extends BaseWorkflowNode {
|
||||
readonly category = 'Secure PDF' as const;
|
||||
@@ -24,7 +24,7 @@ export class FlattenNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
|
||||
try {
|
||||
const form = pdfDoc.getForm();
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { convertFontsToOutlines } from '../../utils/ghostscript-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class FontToOutlineNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -28,7 +28,7 @@ export class FontToOutlineNode extends BaseWorkflowNode {
|
||||
new Uint8Array(input.bytes)
|
||||
);
|
||||
const bytes = new Uint8Array(resultBytes);
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,8 +3,9 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
|
||||
import { StandardFonts, rgb } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class HeaderFooterNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -89,7 +90,7 @@ export class HeaderFooterNode extends BaseWorkflowNode {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
if (!hasAny) return input;
|
||||
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
||||
const pages = pdfDoc.getPages();
|
||||
const totalPages = pages.length;
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class ImageInputNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -57,7 +57,7 @@ export class ImageInputNode extends BaseWorkflowNode {
|
||||
const pymupdf = await loadPyMuPDF();
|
||||
const pdfBlob = await pymupdf.imagesToPdf(this.files);
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
const result: PDFData = {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class JsonToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -65,7 +65,7 @@ export class JsonToPdfNode extends BaseWorkflowNode {
|
||||
pageSize: 'a4',
|
||||
});
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const pdfDoc = await PDFDocument.load(bytes);
|
||||
const pdfDoc = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document: pdfDoc,
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { initializeQpdf } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class LinearizeNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -50,7 +50,7 @@ export class LinearizeNode extends BaseWorkflowNode {
|
||||
}
|
||||
}
|
||||
|
||||
const document = await PDFDocument.load(resultBytes);
|
||||
const document = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,9 +2,9 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
const md = new MarkdownIt({ html: true, linkify: true, typographer: true });
|
||||
|
||||
@@ -65,11 +65,15 @@ export class MarkdownToPdfNode extends BaseWorkflowNode {
|
||||
blockquote { border-left: 3px solid #ccc; margin-left: 0; padding-left: 12px; color: #555; }
|
||||
table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #ccc; padding: 6px 12px; }
|
||||
</style></head><body>${md.render(textContent)}</body></html>`;
|
||||
const pdfBlob = await (pymupdf as any).htmlToPdf(htmlContent, {
|
||||
const pdfBlob = await (
|
||||
pymupdf as unknown as {
|
||||
htmlToPdf(html: string, options: unknown): Promise<Blob>;
|
||||
}
|
||||
).htmlToPdf(htmlContent, {
|
||||
pageSize: 'a4',
|
||||
});
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const pdfDoc = await PDFDocument.load(bytes);
|
||||
const pdfDoc = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document: pdfDoc,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { extractAllPdfs } from '../types';
|
||||
import { mergePdfs } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class MergeNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -26,7 +26,7 @@ export class MergeNode extends BaseWorkflowNode {
|
||||
throw new Error('No PDFs connected to Merge node');
|
||||
|
||||
const mergedBytes = await mergePdfs(allPdfs.map((p) => p.bytes));
|
||||
const mergedDoc = await PDFDocument.load(mergedBytes);
|
||||
const mergedDoc = await loadPdfDocument(mergedBytes);
|
||||
|
||||
return {
|
||||
pdf: {
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class MobiToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -54,7 +54,7 @@ export class MobiToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const blob = await pymupdf.convertToPdf(file, { filetype: 'mobi' });
|
||||
const bytes = new Uint8Array(await blob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument, rgb } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class NUpNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -73,7 +74,7 @@ export class NUpNode extends BaseWorkflowNode {
|
||||
};
|
||||
const [cols, rows] = gridDims[n];
|
||||
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const newDoc = await PDFDocument.create();
|
||||
const pageCount = srcDoc.getPageCount();
|
||||
const firstPage = srcDoc.getPages()[0];
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class OdgToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -56,7 +56,7 @@ export class OdgToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
type PageNumberPosition,
|
||||
type PageNumberFormat,
|
||||
} from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class PageNumbersNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -68,7 +68,7 @@ export class PageNumbersNode extends BaseWorkflowNode {
|
||||
color: { r: c.r, g: c.g, b: c.b },
|
||||
});
|
||||
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class PagesToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -56,7 +56,7 @@ export class PagesToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,9 +2,9 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { readFileAsArrayBuffer } from '../../utils/helpers.js';
|
||||
import { decryptPdfBytes } from '../../utils/pdf-decrypt.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class EncryptedPDFError extends Error {
|
||||
constructor(public readonly filename: string) {
|
||||
@@ -31,15 +31,14 @@ export class PDFInputNode extends BaseWorkflowNode {
|
||||
|
||||
let isEncrypted = false;
|
||||
try {
|
||||
await PDFDocument.load(bytes, { throwOnInvalidObject: false });
|
||||
await loadPdfDocument(bytes, { throwOnInvalidObject: false });
|
||||
} catch {
|
||||
isEncrypted = true;
|
||||
}
|
||||
|
||||
if (isEncrypted) {
|
||||
try {
|
||||
await PDFDocument.load(bytes, {
|
||||
ignoreEncryption: true,
|
||||
await loadPdfDocument(bytes, {
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
} catch {
|
||||
@@ -50,7 +49,7 @@ export class PDFInputNode extends BaseWorkflowNode {
|
||||
throw new EncryptedPDFError(file.name);
|
||||
}
|
||||
|
||||
const document = await PDFDocument.load(bytes, {
|
||||
const document = await loadPdfDocument(bytes, {
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
this.files.push({
|
||||
@@ -65,7 +64,7 @@ export class PDFInputNode extends BaseWorkflowNode {
|
||||
const arrayBuffer = await readFileAsArrayBuffer(file);
|
||||
const bytes = new Uint8Array(arrayBuffer as ArrayBuffer);
|
||||
const { bytes: decryptedBytes } = await decryptPdfBytes(bytes, password);
|
||||
const document = await PDFDocument.load(decryptedBytes, {
|
||||
const document = await loadPdfDocument(decryptedBytes, {
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
this.files.push({
|
||||
|
||||
@@ -43,7 +43,7 @@ export class PdfToCsvNode extends BaseWorkflowNode {
|
||||
for (let i = 0; i < pageCount; i++) {
|
||||
const page = doc.getPage(i);
|
||||
const tables = page.findTables();
|
||||
tables.forEach((table: any) => {
|
||||
tables.forEach((table: { rows: (string | null)[][] }) => {
|
||||
allRows.push(...table.rows);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData, PDFData } from '../types';
|
||||
import { requirePdfInput, extractAllPdfs } from '../types';
|
||||
import { downloadFile } from '../../utils/helpers.js';
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import type JSZip from 'jszip';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
|
||||
export class PdfToImagesNode extends BaseWorkflowNode {
|
||||
@@ -31,7 +32,7 @@ export class PdfToImagesNode extends BaseWorkflowNode {
|
||||
|
||||
private async addPdfPages(
|
||||
pdf: PDFData,
|
||||
zip: any,
|
||||
zip: JSZip,
|
||||
format: string,
|
||||
mimeType: string,
|
||||
quality: number,
|
||||
@@ -59,7 +60,10 @@ export class PdfToImagesNode extends BaseWorkflowNode {
|
||||
}
|
||||
}
|
||||
|
||||
private async addPdfPagesAsSvg(allPdfs: PDFData[], zip: any): Promise<void> {
|
||||
private async addPdfPagesAsSvg(
|
||||
allPdfs: PDFData[],
|
||||
zip: JSZip
|
||||
): Promise<void> {
|
||||
const pymupdf = await loadPyMuPDF();
|
||||
for (const pdf of allPdfs) {
|
||||
const blob = new Blob([new Uint8Array(pdf.bytes)], {
|
||||
|
||||
@@ -3,9 +3,9 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadGhostscript } from '../../utils/ghostscript-dynamic-loader.js';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class PdfToPdfANode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -68,7 +68,7 @@ export class PdfToPdfANode extends BaseWorkflowNode {
|
||||
);
|
||||
|
||||
const bytes = new Uint8Array(resultBuffer);
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -36,7 +36,7 @@ export class PdfToXlsxNode extends BaseWorkflowNode {
|
||||
for (let i = 0; i < pageCount; i++) {
|
||||
const page = doc.getPage(i);
|
||||
const tables = page.findTables();
|
||||
tables.forEach((table: any) => {
|
||||
tables.forEach((table: { rows: (string | null)[][] }) => {
|
||||
allTables.push({ page: i + 1, rows: table.rows });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class PowerPointToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -61,7 +61,7 @@ export class PowerPointToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class PubToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -56,7 +56,7 @@ export class PubToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RasterizeNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -65,7 +65,7 @@ export class RasterizeNode extends BaseWorkflowNode {
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(await rasterizedBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,9 +3,9 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RedactNode extends BaseWorkflowNode {
|
||||
readonly category = 'Secure PDF' as const;
|
||||
@@ -106,7 +106,7 @@ export class RedactNode extends BaseWorkflowNode {
|
||||
const resultBytes = new Uint8Array(doc.save());
|
||||
doc.close();
|
||||
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -3,7 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument, PDFName } from 'pdf-lib';
|
||||
import { PDFName } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RemoveAnnotationsNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -23,7 +24,7 @@ export class RemoveAnnotationsNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfDoc = await PDFDocument.load(input.bytes);
|
||||
const pdfDoc = await loadPdfDocument(input.bytes);
|
||||
const pages = pdfDoc.getPages();
|
||||
|
||||
for (const page of pages) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RemoveBlankPagesNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -61,7 +62,7 @@ export class RemoveBlankPagesNode extends BaseWorkflowNode {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const pdfjsDoc = await pdfjsLib.getDocument({ data: input.bytes })
|
||||
.promise;
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const nonBlankIndices: number[] = [];
|
||||
|
||||
for (let i = 1; i <= pdfjsDoc.numPages; i++) {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { initializeQpdf } from '../../utils/helpers.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RepairNode extends BaseWorkflowNode {
|
||||
readonly category = 'Optimize & Repair' as const;
|
||||
@@ -49,8 +49,7 @@ export class RepairNode extends BaseWorkflowNode {
|
||||
}
|
||||
|
||||
const resultBytes = new Uint8Array(repairedData);
|
||||
const resultDoc = await PDFDocument.load(resultBytes, {
|
||||
ignoreEncryption: true,
|
||||
const resultDoc = await loadPdfDocument(resultBytes, {
|
||||
throwOnInvalidObject: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class ReversePagesNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -23,7 +24,7 @@ export class ReversePagesNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const pageCount = srcDoc.getPageCount();
|
||||
const newDoc = await PDFDocument.create();
|
||||
const reversedIndices = Array.from(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { rotatePdfUniform } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class RotateNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -33,7 +33,7 @@ export class RotateNode extends BaseWorkflowNode {
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const resultBytes = await rotatePdfUniform(input.bytes, angle);
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
return {
|
||||
type: 'pdf',
|
||||
document: resultDoc,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { splitPdf, parsePageRange } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class SplitNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -32,11 +32,11 @@ export class SplitNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const totalPages = srcDoc.getPageCount();
|
||||
const indices = parsePageRange(rangeStr, totalPages);
|
||||
const resultBytes = await splitPdf(input.bytes, indices);
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
return {
|
||||
type: 'pdf',
|
||||
document: resultDoc,
|
||||
|
||||
@@ -3,8 +3,8 @@ import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { SocketData } from '../types';
|
||||
import { requirePdfInput, processBatch } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { WasmProvider } from '../../utils/wasm-provider.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class TableOfContentsNode extends BaseWorkflowNode {
|
||||
readonly category = 'Organize & Manage' as const;
|
||||
@@ -107,7 +107,7 @@ export class TableOfContentsNode extends BaseWorkflowNode {
|
||||
});
|
||||
|
||||
const bytes = new Uint8Array(resultBytes);
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class TextToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -89,7 +89,7 @@ export class TextToPdfNode extends BaseWorkflowNode {
|
||||
pageSize: 'a4',
|
||||
});
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const pdfDoc = await PDFDocument.load(bytes);
|
||||
const pdfDoc = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document: pdfDoc,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class VsdToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -57,7 +57,7 @@ export class VsdToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { addTextWatermark, parsePageRange } from '../../utils/pdf-operations';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { hexToRgb } from '../../utils/helpers.js';
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class WatermarkNode extends BaseWorkflowNode {
|
||||
readonly category = 'Edit & Annotate' as const;
|
||||
@@ -100,7 +101,7 @@ export class WatermarkNode extends BaseWorkflowNode {
|
||||
|
||||
return {
|
||||
pdf: await processBatch(pdfInputs, async (input) => {
|
||||
const srcDoc = await PDFDocument.load(input.bytes);
|
||||
const srcDoc = await loadPdfDocument(input.bytes);
|
||||
const totalPages = srcDoc.getPageCount();
|
||||
|
||||
const pageIndices =
|
||||
@@ -163,7 +164,7 @@ export class WatermarkNode extends BaseWorkflowNode {
|
||||
resultBytes = new Uint8Array(await flattenedDoc.save());
|
||||
}
|
||||
|
||||
const resultDoc = await PDFDocument.load(resultBytes);
|
||||
const resultDoc = await loadPdfDocument(resultBytes);
|
||||
|
||||
return {
|
||||
type: 'pdf',
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class WordToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -62,7 +62,7 @@ export class WordToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class WpdToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -56,7 +56,7 @@ export class WpdToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { getLibreOfficeConverter } from '../../utils/libreoffice-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class WpsToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -56,7 +56,7 @@ export class WpsToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const resultBlob = await converter.convertToPdf(file);
|
||||
const bytes = new Uint8Array(await resultBlob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class XmlToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -59,7 +59,7 @@ export class XmlToPdfNode extends BaseWorkflowNode {
|
||||
pageSize: 'a4',
|
||||
});
|
||||
const bytes = new Uint8Array(await pdfBlob.arrayBuffer());
|
||||
const pdfDoc = await PDFDocument.load(bytes);
|
||||
const pdfDoc = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document: pdfDoc,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { ClassicPreset } from 'rete';
|
||||
import { BaseWorkflowNode } from './base-node';
|
||||
import { pdfSocket } from '../sockets';
|
||||
import type { PDFData, SocketData, MultiPDFData } from '../types';
|
||||
import { PDFDocument } from 'pdf-lib';
|
||||
import { loadPyMuPDF } from '../../utils/pymupdf-loader.js';
|
||||
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
|
||||
|
||||
export class XpsToPdfNode extends BaseWorkflowNode {
|
||||
readonly category = 'Input' as const;
|
||||
@@ -55,7 +55,7 @@ export class XpsToPdfNode extends BaseWorkflowNode {
|
||||
for (const file of this.files) {
|
||||
const blob = await pymupdf.convertToPdf(file, { filetype: 'xps' });
|
||||
const bytes = new Uint8Array(await blob.arrayBuffer());
|
||||
const document = await PDFDocument.load(bytes);
|
||||
const document = await loadPdfDocument(bytes);
|
||||
results.push({
|
||||
type: 'pdf',
|
||||
document,
|
||||
|
||||
Reference in New Issue
Block a user