Update src/Pages/BookingScreen/Components/BookingFunctionality/MobileMultiPdfPrint.jsx
enable dwld option in mobile
This commit is contained in:
parent
592098e672
commit
4a2fee1bc1
|
|
@ -9,6 +9,7 @@ import { PrintStyleFunction } from '../../../paymentpdfPage/PrintStyleFunction';
|
|||
import { PDFDocument } from 'pdf-lib';
|
||||
import { PublicQrCodepost } from '../../../../Features/ConfigMasterPage/ConfigMasterPage';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { downloadFile } from '../../../../utils/downloadFile';
|
||||
|
||||
const MainHomeUrl = import.meta.env.ENV_MAIN_BASE_URL;
|
||||
const uploadApiUrl = import.meta.env.ENV_IMAGE_UPLOAD_API_URL;
|
||||
|
|
@ -136,24 +137,45 @@ export const MobileMultiPdfPrint = async ({
|
|||
await new Promise((r) => setTimeout(r, 5));
|
||||
}
|
||||
|
||||
// 🔥 MERGE ALL PDFs
|
||||
// // 🔥 MERGE ALL PDFs
|
||||
// const combinedPdfBlob = await mergePdfBlobs(allBlobs);
|
||||
// const base64Pdf = await blobToBase64(combinedPdfBlob);
|
||||
|
||||
// // 🔥 DOWNLOAD
|
||||
// if (PrintComing === 'download') {
|
||||
// const blobUrl = createSecureBlobUrl(combinedPdfBlob);
|
||||
|
||||
// const link = document.createElement('a');
|
||||
// link.href = blobUrl;
|
||||
// link.download = 'Receipts.pdf';
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
|
||||
// setTimeout(() => {
|
||||
// document.body.removeChild(link);
|
||||
// revokeSecureBlobUrl(blobUrl);
|
||||
// }, 100);
|
||||
// }
|
||||
const combinedPdfBlob = await mergePdfBlobs(allBlobs);
|
||||
const base64Pdf = await blobToBase64(combinedPdfBlob);
|
||||
|
||||
// 🔥 DOWNLOAD
|
||||
|
||||
if (PrintComing === 'download') {
|
||||
const blobUrl = createSecureBlobUrl(combinedPdfBlob);
|
||||
// ✅ Convert Blob → ArrayBuffer for downloadFile
|
||||
const buffer = await combinedPdfBlob.arrayBuffer();
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.href = blobUrl;
|
||||
link.download = 'Receipts.pdf';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
downloadFile(
|
||||
buffer,
|
||||
"Receipts.pdf",
|
||||
"application/pdf",
|
||||
(success) => {
|
||||
if (!success) {
|
||||
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
revokeSecureBlobUrl(blobUrl);
|
||||
}, 100);
|
||||
console.error('Failed to download the file. Please try again.');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 RETURN BLOB
|
||||
|
|
@ -769,7 +791,33 @@ export const MobileMultiCreditPdfPrint = async ({
|
|||
onProgress(Math.round((processedVisible / total) * 100));
|
||||
}
|
||||
|
||||
// merge blobs - use existing merge function if available, otherwise fallback
|
||||
// // merge blobs - use existing merge function if available, otherwise fallback
|
||||
// const combinedPdfBlob =
|
||||
// typeof mergePdfBlobs === 'function'
|
||||
// ? await mergePdfBlobs(allBlobs)
|
||||
// : await mergePdfBlobsFallback(allBlobs);
|
||||
|
||||
// const base64Pdf = await blobToBase64(combinedPdfBlob);
|
||||
|
||||
// // Action handlers
|
||||
// if (PrintComing === 'download') {
|
||||
// const blobUrl =
|
||||
// typeof createSecureBlobUrl === 'function'
|
||||
// ? createSecureBlobUrl(combinedPdfBlob)
|
||||
// : URL.createObjectURL(combinedPdfBlob);
|
||||
// const link = document.createElement('a');
|
||||
// link.href = blobUrl;
|
||||
// link.download = 'Receipts.pdf';
|
||||
// document.body.appendChild(link);
|
||||
// link.click();
|
||||
// setTimeout(() => {
|
||||
// document.body.removeChild(link);
|
||||
// if (typeof revokeSecureBlobUrl === 'function')
|
||||
// revokeSecureBlobUrl(blobUrl);
|
||||
// else URL.revokeObjectURL(blobUrl);
|
||||
// }, 300);
|
||||
// return { success: true };
|
||||
// }
|
||||
const combinedPdfBlob =
|
||||
typeof mergePdfBlobs === 'function'
|
||||
? await mergePdfBlobs(allBlobs)
|
||||
|
|
@ -779,24 +827,22 @@ export const MobileMultiCreditPdfPrint = async ({
|
|||
|
||||
// Action handlers
|
||||
if (PrintComing === 'download') {
|
||||
const blobUrl =
|
||||
typeof createSecureBlobUrl === 'function'
|
||||
? createSecureBlobUrl(combinedPdfBlob)
|
||||
: URL.createObjectURL(combinedPdfBlob);
|
||||
const link = document.createElement('a');
|
||||
link.href = blobUrl;
|
||||
link.download = 'Receipts.pdf';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
if (typeof revokeSecureBlobUrl === 'function')
|
||||
revokeSecureBlobUrl(blobUrl);
|
||||
else URL.revokeObjectURL(blobUrl);
|
||||
}, 300);
|
||||
// ✅ Convert Blob → ArrayBuffer for downloadFile
|
||||
const buffer = await combinedPdfBlob.arrayBuffer();
|
||||
|
||||
downloadFile(
|
||||
buffer,
|
||||
"Receipts.pdf",
|
||||
"application/pdf",
|
||||
(success) => {
|
||||
if (!success) {
|
||||
console.error('Failed to download the file. Please try again.');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
if (PrintComing === 'whatsapp') {
|
||||
const orderIdsArray = PrintOrderDetails.map((r) => r?.receiptNo).filter(
|
||||
Boolean
|
||||
|
|
|
|||
Loading…
Reference in New Issue