// const downloadReport = async () => {
// if (![Link]) return;
// setIsGeneratingPdf(true); // Start loading
// try {
// // Get all page elements
// const pageElements =
// [Link](".page-container");
// if ([Link] === 0) {
// [Link]("No pages found");
// return;
// }
// // Optimize dimensions and quality for faster processing
// const scaleFactor = 2; // Reduced from 2 for faster rendering
// const pdfWidth = 840;
// const pdfHeight = 1000;
// // Create PDF with correct dimensions
// const pdf = new jsPDF({
// unit: "px",
// format: [pdfWidth, pdfHeight],
// orientation: "portrait",
// compress: true, // Enable compression for smaller file size
// });
// // Convert NodeList to array of HTMLElements
// const pageElementsArray = [Link](pageElements) as HTMLElement[];
// // Process pages in smaller batches for better performance
// const batchSize = 2; // Process 2 pages at a time
// // Process pages in batches
// for (let i = 0; i < [Link]; i += batchSize) {
// const batch = [Link](i, i + batchSize);
// // Process pages in each batch concurrently
// const batchPromises = [Link](async (pageElement, idx) => {
// // Force page to be exactly the right size before capture
// [Link] = `${pdfWidth}px`;
// [Link] = `${pdfHeight}px`;
// [Link] = "hidden";
// [Link] = "0";
// [Link] = "relative";
// // Capture with optimized settings
// const canvas = await html2canvas(pageElement, {
// scale: scaleFactor,
// useCORS: true,
// allowTaint: true,
// logging: false,
// width: pdfWidth,
// height: pdfHeight,
// imageTimeout: 0,
// backgroundColor: "#ffffff",
// });
// // Use JPEG with moderate quality for smaller size
// const imgData = [Link]("image/jpeg", 1.0);
// return { imgData, index: i + idx };
// });
// // Wait for all pages in the batch to be processed
// const results = await [Link](batchPromises);
// // Add pages to PDF in correct order
// for (const { imgData, index } of results) {
// if (index > 0) {
// [Link]([pdfWidth, pdfHeight], "portrait");
// }
// [Link](imgData, "JPEG", 0, 0, pdfWidth, pdfHeight);
// [Link](`Page ${index + 1} captured successfully`);
// }
// }
// // Save the PDF with a more descriptive name including date
// const date = new Date().toISOString().split("T")[0];
// [Link](`InSAR_Insights_${date}.pdf`);
// } catch (error) {
// [Link]("Error generating PDF:", error);
// } finally {
// setIsGeneratingPdf(false); // Stop loading
// }
// };