Trade War & Tariff Impact Estimation Tool

Trade War & Tariff Impact Estimator

Scenario Definition

Product/Sector: ${product}

Exporting Country: ${exporter}

Importing Country: ${importer}

Annual Import Value: $${value.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}

Current Tariff: ${currentRate}%

New Additional Tariff: ${newRate}%

Consumer Pass-Through Assumption: ${passRate}%


`; } function addResultItem(title, value, note = "") { const itemDiv = document.createElement('div'); itemDiv.className = 'result-item'; let content = `

${title}

${value}

`; if (note) { content += `

Note: ${note}

`; } itemDiv.innerHTML = content; resultsAreaEl.appendChild(itemDiv); } function displayMessage(text, type) { messageArea.textContent = text; messageArea.className = type === 'error' ? 'message-error' : 'message-info'; } // PDF Download Functionality if(downloadPdfButton) { downloadPdfButton.addEventListener('click', function () { const pdfExportContent = document.getElementById('pdfExportContent'); if (!pdfExportContent) { displayMessage('Error: PDF content area not found.', 'error'); return; } const originalDisplay = pdfExportContent.style.display; pdfExportContent.style.display = 'block'; // Ensure it's visible for capture html2canvas(pdfExportContent, { scale: 2, useCORS: true, logging: false }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', // portrait unit: 'mm', // millimeters format: 'a4' // A4 page size }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const canvasAspectRatio = canvasWidth / canvasHeight; const margin = 15; // 15mm margin const pageEffectiveWidth = pdfWidth - 2 * margin; const pageEffectiveHeight = pdfHeight - 2 * margin; let finalImgWidth, finalImgHeight; // Determine if the image is wider or taller than the effective page area, respecting aspect ratio if ((canvasWidth / pageEffectiveWidth) > (canvasHeight / pageEffectiveHeight)) { // Image is relatively wider than the page area, so width is the constraint finalImgWidth = pageEffectiveWidth; finalImgHeight = finalImgWidth / canvasAspectRatio; } else { // Image is relatively taller or same aspect ratio, so height is the constraint finalImgHeight = pageEffectiveHeight; finalImgWidth = finalImgHeight * canvasAspectRatio; } // Center the image on the page within the margins const x = margin + (pageEffectiveWidth - finalImgWidth) / 2; const y = margin; // Align to top margin (title will be added before this) pdf.setFontSize(18); // Title font size // Place title with a small top margin, centered pdf.text("Tariff Impact Estimation Report", pdfWidth / 2, margin - 5 , { align: "center" }); // Add the image (captured content) // The y position for the image needs to be after the title pdf.addImage(imgData, 'PNG', x, y + 5, finalImgWidth, finalImgHeight); // Add some space after title pdf.save('tariff-impact-estimation.pdf'); pdfExportContent.style.display = originalDisplay; // Restore original display }).catch(error => { console.error('Error generating PDF:', error); displayMessage('Failed to generate PDF. See console for details.', 'error'); pdfExportContent.style.display = originalDisplay; // Restore original display }); }); } });
Scroll to Top