feat: support selective page range extraction for email attachment print previews
Build and Push Multi-Platform Images / build-and-push (push) Successful in 35s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 35s
This commit is contained in:
@@ -158,7 +158,24 @@ export class EmailImportService {
|
|||||||
async generatePrintPdf(attachmentId: number, barcodeData: any): Promise<Buffer> {
|
async generatePrintPdf(attachmentId: number, barcodeData: any): Promise<Buffer> {
|
||||||
const content = await this.contentRepo.findOne({ where: { AttachmentEntityId: attachmentId } });
|
const content = await this.contentRepo.findOne({ where: { AttachmentEntityId: attachmentId } });
|
||||||
if (!content) throw new HttpException('Inhalt nicht gefunden', HttpStatus.NOT_FOUND);
|
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> {
|
async applyBarcodeToPdf(pdfBytes: Buffer, barcodeData: any): Promise<Buffer> {
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ export const emailImportApi = {
|
|||||||
await api.post('/api/email-import/belegnummer/release', { date: dateStr, number });
|
await api.post('/api/email-import/belegnummer/release', { date: dateStr, number });
|
||||||
},
|
},
|
||||||
|
|
||||||
printPreview: async (attachmentId: number, barcodeData: any): Promise<Blob> => {
|
printPreview: async (attachmentId: number, barcodeData: any, pages?: { start: number; end: number }): Promise<Blob> => {
|
||||||
const res = await api.post(`/api/email-import/attachments/${attachmentId}/print-preview`, barcodeData, {
|
const res = await api.post(`/api/email-import/attachments/${attachmentId}/print-preview`, { ...barcodeData, _pages: pages }, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
});
|
});
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
@@ -366,7 +366,10 @@ export default function MailImportWizard({ visible, onClose, email, attachments
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = await emailImportApi.printPreview(attachmentId, barcode);
|
const item = importData.find(i => i.virtualId === virtualId);
|
||||||
|
const pages = item?.pages;
|
||||||
|
|
||||||
|
const blob = await emailImportApi.printPreview(attachmentId, barcode, pages);
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
|
||||||
// Navigate the already open window to the PDF
|
// Navigate the already open window to the PDF
|
||||||
|
|||||||
Reference in New Issue
Block a user