import { PDFPage, PDFName } from "pdf-lib";

export function copyPage(originalPage: PDFPage) {
	const cloneNode = originalPage.node.clone();

	const { Contents } = originalPage.node.normalizedEntries();
	if (Contents) cloneNode.set(PDFName.of('Contents'), Contents.clone());

	const cloneRef = originalPage.doc.context.register(cloneNode);
	const clonePage = PDFPage.of(cloneNode, cloneRef, originalPage.doc);
	return clonePage;
}