Acoustic Impedance Calculator

Material: ${materialName}

Acoustic Impedance: ${rayl} Rayl (Pa·s/m)

`; // Populate table const tableBody = document.getElementById('result-table-body'); tableBody.innerHTML = ` Density ${density.toFixed(2)} kg/m³ Sound Speed ${speed.toFixed(2)} m/s Acoustic Impedance ${impedance.toExponential(3)} Rayl (Pa·s/m) `; document.getElementById('results').style.display = 'block'; } function generatePDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Title doc.setFontSize(18); doc.text('Acoustic Impedance Report', 105, 15, { align: 'center' }); // Date doc.setFontSize(10); doc.text(`Generated: ${new Date().toLocaleString()}`, 105, 22, { align: 'center' }); // Material info doc.setFontSize(12); const materialName = document.getElementById('result-values').querySelector('strong').nextSibling.textContent.trim(); doc.text(`Material: ${materialName}`, 14, 35); // Results table const tableBody = document.getElementById('result-table-body'); const rows = tableBody.querySelectorAll('tr'); let yPos = 50; doc.setFontSize(14); doc.text('Calculation Results:', 14, yPos); yPos += 10; doc.setFontSize(12); rows.forEach(row => { const cells = row.querySelectorAll('td'); doc.text(`${cells[0].textContent}:`, 20, yPos); doc.text(`${cells[1].textContent} ${cells[2].textContent}`, 80, yPos); yPos += 7; }); // Save PDF doc.save('Acoustic_Impedance_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