web share api made to print pdf
This commit is contained in:
parent
6fbfd584aa
commit
edddb1b696
@ -59,7 +59,7 @@ export function DailySalesReportPage() {
|
||||
doc.save(`Daily_Sales_Report_${date || 'Draft'}.pdf`);
|
||||
};
|
||||
|
||||
const printReport = () => {
|
||||
const printReport = async () => {
|
||||
const doc = new jsPDF();
|
||||
|
||||
// Headers
|
||||
@ -95,10 +95,29 @@ export function DailySalesReportPage() {
|
||||
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');
|
||||
iframe.style.display = 'none';
|
||||
iframe.src = blobUrl.toString();
|
||||
iframe.src = blobUrl;
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
iframe.onload = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user