feat: implement segment-based PDF download functionality with a dedicated UI for multi-page export
Build and Push Multi-Platform Images / build-and-push (push) Successful in 34s

This commit is contained in:
2026-05-06 09:46:23 +02:00
parent e08a5697f0
commit 415f8bbcf3
5 changed files with 162 additions and 29 deletions
@@ -53,6 +53,36 @@ export async function cleanupTemp(filePath: string | null): Promise<void> {
}
}
/**
* Baut ein PDF aus einer Teilmenge von Originalseiten auf (rotiert, keine gelöschten Seiten).
* segmentPages enthält 1-basierte Originalseitenzahlen; gelöschte Seiten müssen vom Aufrufer
* bereits herausgefiltert worden sein.
*/
export async function buildSegmentBuffer(
doc: InboxDocument,
pdfPath: string,
segmentPages: number[],
): Promise<Buffer> {
const bytes = await fs.readFile(pdfPath);
const srcPdf = await PDFDocument.load(bytes, { ignoreEncryption: true });
const outPdf = await PDFDocument.create();
const rotations = doc.Rotations ?? {};
const indices = segmentPages.map((p) => p - 1);
const copied = await outPdf.copyPages(srcPdf, indices);
copied.forEach((page, i) => {
const rot = rotations[String(segmentPages[i])];
if (rot !== undefined) {
const normalized = ((Math.round(rot / 90) * 90) % 360 + 360) % 360;
if (normalized !== 0) page.setRotation(degrees(normalized));
}
outPdf.addPage(page);
});
return Buffer.from(await outPdf.save());
}
export async function extractSectionToTemp(
pdfPath: string,
pageIndices: number[],