Gigapascals to Megapascals Converter
Enter a value and click 'Convert' to see the result.
Please enter a valid positive number for Gigapascals.
'; downloadPdfButton.style.display = 'none'; return; } const mpaValue = gpaValue * 1000; // 1 Gigapascal = 1000 Megapascals resultArea.innerHTML = `${gpaValue} GPa is equal to ${mpaValue.toFixed(4)} MPa.
`; downloadPdfButton.style.display = 'block'; // Show PDF button after calculation } function clearInputsAndResults() { const gpaInput = document.getElementById('gpaInput'); const resultArea = document.getElementById('resultArea'); const downloadPdfButton = document.getElementById('downloadPdfButton'); if (gpaInput) { gpaInput.value = ''; } if (resultArea) { resultArea.innerHTML = 'Enter a value and click \'Convert\' to see the result.
'; } if (downloadPdfButton) { downloadPdfButton.style.display = 'none'; // Hide PDF button when cleared } } function generatePdf() { // Check if jspdf is available if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { alert('PDF generation library not loaded. Please try again.'); console.error('jsPDF library not found.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); const gpaInput = document.getElementById('gpaInput'); const resultArea = document.getElementById('resultArea'); if (!gpaInput || !resultArea) { console.error('Cannot generate PDF: Input or result elements missing.'); return; } const gpaValue = parseFloat(gpaInput.value); const mpaValue = gpaValue * 1000; const title = "Gigapascals to Megapascals Conversion"; const inputLine = `Input: ${gpaValue} Gigapascals (GPa)`; const outputLine = `Output: ${mpaValue.toFixed(4)} Megapascals (MPa)`; // Set font and size for title doc.setFontSize(22); doc.setTextColor(0, 86, 179); // A shade of blue consistent with the tool's header doc.text(title, 105, 30, { align: 'center' }); // Set font and size for content doc.setFontSize(14); doc.setTextColor(51, 51, 51); // Dark grey for content doc.text(inputLine, 20, 60); doc.text(outputLine, 20, 70); doc.save("Gpa_to_Mpa_Conversion.pdf"); }