/*
RFC-0656: PDF stable normalizer — strips non-deterministic metadata fields (/CreationDate, /ModDate, /ID) before hashing.
- Do not alter PDF content — only metadata fields that vary between builds are stripped.
- RFC-0656: initial PDF stable normalizer using pdf-lib.
*/
import { PDFDocument } from "pdf-lib";
export async function normalizePdf(bytes: Uint8Array): Promise {
const pdf = await PDFDocument.load(bytes, { ignoreEncryption: true });
pdf.setCreationDate(new Date(0));
pdf.setModificationDate(new Date(0));
pdf.context.trailerInfo.ID = undefined;
return await pdf.save({ useObjectStreams: false });
}