Acoustic Power Density Converter

Calculation Type: ${calculationType}

`; resultHTML += `

Power Density: ${data['Power Density'].value.toExponential(4)} ${data['Power Density'].unit}

`; document.getElementById('result-values').innerHTML = resultHTML; // Populate table const tableBody = document.getElementById('result-table-body'); tableBody.innerHTML = ''; for (const [key, value] of Object.entries(data)) { const row = document.createElement('tr'); const cell1 = document.createElement('td'); cell1.textContent = key; row.appendChild(cell1); const cell2 = document.createElement('td'); cell2.textContent = typeof value.value === 'number' ? value.value.toExponential(4) : value.value; row.appendChild(cell2); const cell3 = document.createElement('td'); cell3.textContent = value.unit; row.appendChild(cell3); tableBody.appendChild(row); } document.getElementById('results').style.display = 'block'; } function generatePDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Title doc.setFontSize(18); doc.text('Acoustic Power Density Report', 105, 15, { align: 'center' }); // Date doc.setFontSize(10); doc.text(`Generated: ${new Date().toLocaleString()}`, 105, 22, { align: 'center' }); // Add results summary doc.setFontSize(12); const resultValues = document.getElementById('result-values').textContent; const lines = resultValues.split('\n').filter(line => line.trim() !== ''); let yPos = 40; lines.forEach(line => { doc.text(line.trim(), 14, yPos); yPos += 7; }); // Add table data yPos += 10; doc.setFontSize(14); doc.text('Detailed Parameters:', 14, yPos); yPos += 10; doc.setFontSize(12); const table = document.getElementById('result-table-body'); const rows = table.querySelectorAll('tr'); rows.forEach(row => { const cells = row.querySelectorAll('td'); doc.text(`${cells[0].textContent}: ${cells[1].textContent} ${cells[2].textContent}`, 20, yPos); yPos += 7; }); // Save PDF doc.save('Acoustic_Power_Density_Report.pdf'); } catch (error) { console.error('PDF generation error:', error); alert('PDF generation failed. Please try again or check your internet connection.'); } }
Scroll to Top