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 { PDFDocument } from 'pdf-lib';
|
||||||
import { PublicQrCodepost } from '../../../../Features/ConfigMasterPage/ConfigMasterPage';
|
import { PublicQrCodepost } from '../../../../Features/ConfigMasterPage/ConfigMasterPage';
|
||||||
import { renderToStaticMarkup } from 'react-dom/server';
|
import { renderToStaticMarkup } from 'react-dom/server';
|
||||||
|
import { downloadFile } from '../../../../utils/downloadFile';
|
||||||
|
|
||||||
const MainHomeUrl = import.meta.env.ENV_MAIN_BASE_URL;
|
const MainHomeUrl = import.meta.env.ENV_MAIN_BASE_URL;
|
||||||
const uploadApiUrl = import.meta.env.ENV_IMAGE_UPLOAD_API_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));
|
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 combinedPdfBlob = await mergePdfBlobs(allBlobs);
|
||||||
const base64Pdf = await blobToBase64(combinedPdfBlob);
|
const base64Pdf = await blobToBase64(combinedPdfBlob);
|
||||||
|
|
||||||
// 🔥 DOWNLOAD
|
// 🔥 DOWNLOAD
|
||||||
|
|
||||||
if (PrintComing === 'download') {
|
if (PrintComing === 'download') {
|
||||||
const blobUrl = createSecureBlobUrl(combinedPdfBlob);
|
// ✅ Convert Blob → ArrayBuffer for downloadFile
|
||||||
|
const buffer = await combinedPdfBlob.arrayBuffer();
|
||||||
|
|
||||||
const link = document.createElement('a');
|
downloadFile(
|
||||||
link.href = blobUrl;
|
buffer,
|
||||||
link.download = 'Receipts.pdf';
|
"Receipts.pdf",
|
||||||
document.body.appendChild(link);
|
"application/pdf",
|
||||||
link.click();
|
(success) => {
|
||||||
|
if (!success) {
|
||||||
|
|
||||||
setTimeout(() => {
|
console.error('Failed to download the file. Please try again.');
|
||||||
document.body.removeChild(link);
|
}
|
||||||
revokeSecureBlobUrl(blobUrl);
|
}
|
||||||
}, 100);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 RETURN BLOB
|
// 🔥 RETURN BLOB
|
||||||
|
|
@ -769,7 +791,33 @@ export const MobileMultiCreditPdfPrint = async ({
|
||||||
onProgress(Math.round((processedVisible / total) * 100));
|
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 =
|
const combinedPdfBlob =
|
||||||
typeof mergePdfBlobs === 'function'
|
typeof mergePdfBlobs === 'function'
|
||||||
? await mergePdfBlobs(allBlobs)
|
? await mergePdfBlobs(allBlobs)
|
||||||
|
|
@ -779,24 +827,22 @@ export const MobileMultiCreditPdfPrint = async ({
|
||||||
|
|
||||||
// Action handlers
|
// Action handlers
|
||||||
if (PrintComing === 'download') {
|
if (PrintComing === 'download') {
|
||||||
const blobUrl =
|
// ✅ Convert Blob → ArrayBuffer for downloadFile
|
||||||
typeof createSecureBlobUrl === 'function'
|
const buffer = await combinedPdfBlob.arrayBuffer();
|
||||||
? createSecureBlobUrl(combinedPdfBlob)
|
|
||||||
: URL.createObjectURL(combinedPdfBlob);
|
downloadFile(
|
||||||
const link = document.createElement('a');
|
buffer,
|
||||||
link.href = blobUrl;
|
"Receipts.pdf",
|
||||||
link.download = 'Receipts.pdf';
|
"application/pdf",
|
||||||
document.body.appendChild(link);
|
(success) => {
|
||||||
link.click();
|
if (!success) {
|
||||||
setTimeout(() => {
|
console.error('Failed to download the file. Please try again.');
|
||||||
document.body.removeChild(link);
|
}
|
||||||
if (typeof revokeSecureBlobUrl === 'function')
|
}
|
||||||
revokeSecureBlobUrl(blobUrl);
|
);
|
||||||
else URL.revokeObjectURL(blobUrl);
|
|
||||||
}, 300);
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PrintComing === 'whatsapp') {
|
if (PrintComing === 'whatsapp') {
|
||||||
const orderIdsArray = PrintOrderDetails.map((r) => r?.receiptNo).filter(
|
const orderIdsArray = PrintOrderDetails.map((r) => r?.receiptNo).filter(
|
||||||
Boolean
|
Boolean
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue