Merge branch 'main' into feat/auto-placing-fields

This commit is contained in:
Catalin Pit
2025-11-07 08:57:07 +02:00
committed by GitHub
251 changed files with 15428 additions and 6391 deletions

View File

@ -1,14 +1,23 @@
import { PDFDocument } from '@cantoo/pdf-lib';
import { removePlaceholdersFromPDF } from './auto-place-fields';
import { AppError } from '../../errors/app-error';
import { flattenAnnotations } from './flatten-annotations';
import { flattenForm, removeOptionalContentGroups } from './flatten-form';
export const normalizePdf = async (pdf: Buffer) => {
const pdfDoc = await PDFDocument.load(pdf).catch(() => null);
const pdfDoc = await PDFDocument.load(pdf).catch((e) => {
console.error(`PDF normalization error: ${e.message}`);
if (!pdfDoc) {
return pdf;
throw new AppError('INVALID_DOCUMENT_FILE', {
message: 'The document is not a valid PDF',
});
});
if (pdfDoc.isEncrypted) {
throw new AppError('INVALID_DOCUMENT_FILE', {
message: 'The document is encrypted',
});
}
removeOptionalContentGroups(pdfDoc);