web share api made to print pdf

This commit is contained in:
suryacp23 2026-07-17 15:04:06 +05:30
parent 6fbfd584aa
commit edddb1b696

View File

@ -59,7 +59,7 @@ export function DailySalesReportPage() {
doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`); doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`);
}; };
const printReport = () => { const printReport = async () => {
const doc = new jsPDF(); const doc = new jsPDF();
// Headers // Headers
@ -95,10 +95,29 @@ export function DailySalesReportPage() {
headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' }, headStyles: { fillColor: [243, 244, 246], fontStyle: 'bold', halign: 'center' },
}); });
const blobUrl = doc.output('bloburl'); const blob = doc.output('blob');
// Attempt mobile native share (which includes OS-level Print)
if (navigator.share && navigator.canShare) {
const file = new File([blob], `Daily_Sales_Report_${date || 'Draft'}.pdf`, { type: 'application/pdf' });
try {
if (navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
title: 'Daily Sales Report',
});
return;
}
} catch (err) {
console.warn('Share failed or was cancelled', err);
}
}
// Fallback for PC / unsupported browsers
const blobUrl = URL.createObjectURL(blob);
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
iframe.style.display = 'none'; iframe.style.display = 'none';
iframe.src = blobUrl.toString(); iframe.src = blobUrl;
document.body.appendChild(iframe); document.body.appendChild(iframe);
iframe.onload = () => { iframe.onload = () => {