Update src/Pages/BookingScreen/Components/BookingFunctionality/MobileMultiPdfPrint.jsx

enable dwld option in mobile
This commit is contained in:
TamilSelvan 2026-03-27 16:54:37 +05:30
parent 592098e672
commit 4a2fee1bc1
1 changed files with 80 additions and 34 deletions

View File

@ -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;
@ -55,12 +56,12 @@ export const MobileMultiPdfPrint = async ({
printerTemplateStyle = 'Style 13', printerTemplateStyle = 'Style 13',
printDatas = {}, printDatas = {},
PrintOrderDetails = [], PrintOrderDetails = [],
setPrintOrderDetails = () => {}, setPrintOrderDetails = () => { },
PrintComing = '', PrintComing = '',
emailId = '', emailId = '',
dispatch, dispatch,
UserId = '', UserId = '',
onProgress = () => {}, onProgress = () => { },
returnBlob = false, returnBlob = false,
}) => { }) => {
try { try {
@ -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
@ -242,7 +264,7 @@ export const MobileMultiPdfPrint = async ({
setTimeout(() => { setTimeout(() => {
try { try {
window.location.href = intentUrl; window.location.href = intentUrl;
} catch {console.log("some errors")} } catch { console.log("some errors") }
}, 500); }, 500);
} }
@ -377,7 +399,7 @@ export const MobileMultiPdfPrint = async ({
// revokeSecureBlobUrl(blobUrl); // revokeSecureBlobUrl(blobUrl);
// }, 100); // }, 100);
// } // }
// // Return blob if requested (after download completes) // // Return blob if requested (after download completes)
// if (returnBlob && PrintComing === 'download') { // if (returnBlob && PrintComing === 'download') {
// setPrintOrderDetails([]); // setPrintOrderDetails([]);
@ -585,7 +607,7 @@ export const MobileMultiCreditPdfPrint = async ({
emailId = '', emailId = '',
dispatch, dispatch,
UserId = '', UserId = '',
onProgress = () => {}, onProgress = () => { },
BATCH_SIZE = 5, BATCH_SIZE = 5,
}) => { }) => {
if (!BSCreditCustomerPrint) { if (!BSCreditCustomerPrint) {
@ -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
@ -908,7 +954,7 @@ export const MobileMultiCreditPdfPrint = async ({
).forEach((el) => { ).forEach((el) => {
try { try {
el.parentElement.removeChild(el); el.parentElement.removeChild(el);
} catch (e) {} } catch (e) { }
}); });
} catch (e) { } catch (e) {
console.warn('Cleanup error', e); console.warn('Cleanup error', e);