fix: dynamic PDF height based on receipt content length
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -273,6 +273,10 @@ export async function downloadReceiptPDF(txnNumber?: string) {
|
|||||||
const el = document.getElementById('pos-receipt-print')
|
const el = document.getElementById('pos-receipt-print')
|
||||||
if (!el) return
|
if (!el) return
|
||||||
|
|
||||||
|
// Calculate height from actual content
|
||||||
|
const heightPx = el.scrollHeight + 16 // 16px padding
|
||||||
|
const heightMm = Math.ceil(heightPx * 0.265) + 8 // px to mm + margin
|
||||||
|
|
||||||
const html2pdf = (await import('html2pdf.js')).default
|
const html2pdf = (await import('html2pdf.js')).default
|
||||||
html2pdf()
|
html2pdf()
|
||||||
.set({
|
.set({
|
||||||
@@ -280,7 +284,7 @@ export async function downloadReceiptPDF(txnNumber?: string) {
|
|||||||
filename: `receipt-${txnNumber ?? 'unknown'}.pdf`,
|
filename: `receipt-${txnNumber ?? 'unknown'}.pdf`,
|
||||||
image: { type: 'jpeg', quality: 0.95 },
|
image: { type: 'jpeg', quality: 0.95 },
|
||||||
html2canvas: { scale: 2, useCORS: true, width: 280 },
|
html2canvas: { scale: 2, useCORS: true, width: 280 },
|
||||||
jsPDF: { unit: 'mm', format: [72, 250], orientation: 'portrait' },
|
jsPDF: { unit: 'mm', format: [72, heightMm], orientation: 'portrait' },
|
||||||
})
|
})
|
||||||
.from(el)
|
.from(el)
|
||||||
.save()
|
.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user