feat: support selective page range extraction for email attachment print previews
Build and Push Multi-Platform Images / build-and-push (push) Successful in 35s

This commit is contained in:
2026-05-05 08:06:52 +02:00
parent 84a349fd35
commit b47ad17568
3 changed files with 25 additions and 5 deletions
@@ -158,7 +158,24 @@ export class EmailImportService {
async generatePrintPdf(attachmentId: number, barcodeData: any): Promise<Buffer> {
const content = await this.contentRepo.findOne({ where: { AttachmentEntityId: attachmentId } });
if (!content) throw new HttpException('Inhalt nicht gefunden', HttpStatus.NOT_FOUND);
return this.applyBarcodeToPdf(content.Content1, barcodeData);
let pdfBytes: Buffer = content.Content1;
const pages: { start: number; end: number } | undefined = barcodeData._pages;
if (pages) {
const pdfDoc = await PDFDocument.load(pdfBytes, { ignoreEncryption: true });
const total = pdfDoc.getPageCount();
const startIdx = Math.max(1, pages.start) - 1;
const endIdx = Math.min(pages.end === 999 ? total : pages.end, total) - 1;
const sliced = await PDFDocument.create();
const indices = Array.from({ length: endIdx - startIdx + 1 }, (_, i) => startIdx + i);
const copied = await sliced.copyPages(pdfDoc, indices);
copied.forEach(p => sliced.addPage(p));
pdfBytes = Buffer.from(await sliced.save());
}
const { _pages, ...barcode } = barcodeData;
return this.applyBarcodeToPdf(pdfBytes, barcode);
}
async applyBarcodeToPdf(pdfBytes: Buffer, barcodeData: any): Promise<Buffer> {