M&A Activity Tracker

M&A Activity Tracker

Search Results

Deal Name Target Co. Acquirer Co. Announce Date Deal Value Status Industry Actions

Select a deal from the search results to view its details.

My Watchlist

${domElements.noSearchResults.textContent}

`; } else { const clonedTableContainer = searchResultsTableContainer.cloneNode(true); // Remove action buttons from cloned table for PDF clonedTableContainer.querySelectorAll('.action-buttons').forEach(cell => cell.remove()); clonedTableContainer.querySelectorAll('th:last-child').forEach(th => th.remove()); // Remove the "Actions" header clonedTableContainer.querySelector('h3').remove(); // Remove the "Search Results" sub-heading if not desired in PDF contentToPrint.appendChild(clonedTableContainer); } filename = `ma-search-results.pdf`; } else if (currentActiveTab === 'deal-details-tab' && currentSelectedDeal) { contentToPrint = domElements.dealDetailsOutput.cloneNode(true); contentToPrint.querySelector('button').remove(); // Remove "Add to Watchlist" button contentToPrint.querySelector('h3').textContent = `${pageTitle} - Deal Details: ${currentSelectedDeal.dealName}`; // Apply specific inline styles to the cloned content for consistent PDF appearance contentToPrint.style.cssText = ` background-color: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 8px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); `; contentToPrint.querySelectorAll('.detail-item strong').forEach(el => { el.style.display = 'inline-block'; el.style.width = '150px'; el.style.color = '#2c3e50'; }); contentToPrint.querySelectorAll('.detail-item span').forEach(el => { el.style.color = '#555'; }); if (contentToPrint.querySelector('.deal-summary')) { contentToPrint.querySelector('.deal-summary').style.cssText = ` margin-top: 20px; padding: 15px; background-color: #f0f8ff; border-left: 5px solid #007bff; border-radius: 5px; font-style: italic; `; } filename = `${currentSelectedDeal.id}-deal-details.pdf`; } else { displayMessage('error', 'No relevant content to generate PDF for. Please search for deals or view a deal\'s details first.'); domElements.downloadPdfButton.disabled = false; domElements.downloadPdfButton.textContent = 'Download Report as PDF'; return; } if (!contentToPrint) { displayMessage('error', 'Could not prepare content for PDF.'); domElements.downloadPdfButton.disabled = false; domElements.downloadPdfButton.textContent = 'Download Report as PDF'; return; } try { // Create a temporary div to render the content for html2canvas const tempDiv = document.createElement('div'); tempDiv.style.position = 'absolute'; tempDiv.style.left = '-9999px'; tempDiv.style.width = 'calc(1000px - 60px)'; /* Match .ma-tracker-container width - padding */ tempDiv.style.padding = '30px'; tempDiv.style.backgroundColor = '#ffffff'; tempDiv.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.08)'; tempDiv.style.borderRadius = '10px'; tempDiv.style.boxSizing = 'border-box'; tempDiv.appendChild(contentToPrint); document.body.appendChild(tempDiv); const canvas = await html2canvas(tempDiv, { scale: 2, // Higher scale for better quality useCORS: true, logging: false, // Disable logging for cleaner console allowTaint: true, // Allow images to be loaded }); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF('p', 'mm', 'a4'); const imgWidth = 210 - 20; // A4 width - margin (10mm on each side) const pageHeight = 297; // A4 height const imgHeight = (canvas.height * imgWidth) / canvas.width; let heightLeft = imgHeight; let position = 10; // Initial position from top pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= (pageHeight - position); // Account for initial margin while (heightLeft >= -10) { // Small buffer to ensure last bit is captured position = 10; // Reset position for new page top margin pdf.addPage(); // Calculate the Y position for the next part of the image // The image is rendered from the top of the canvas, so we subtract the already rendered height pdf.addImage(imgData, 'PNG', 10, -(imgHeight - (heightLeft + (pageHeight - 10))), imgWidth, imgHeight); heightLeft -= (pageHeight - position); } pdf.save(filename); document.body.removeChild(tempDiv); // Clean up the temporary div displayMessage('success', 'PDF generated successfully!'); } catch (error) { console.error('Error generating PDF:', error); displayMessage('error', 'Failed to generate PDF. Please try again. (Check console for details)'); } finally { domElements.downloadPdfButton.disabled = false; domElements.downloadPdfButton.textContent = 'Download Report as PDF'; } }
Scroll to Top