Gilbert to Ampere-turns Converter

Enter a value and click 'Convert' to see the result.

Please enter a valid positive number for Gilbert.

'; downloadPdfButton.style.display = 'none'; // Hide PDF button if input is invalid. return; } // Conversion factor: 1 Gilbert = 10 / (4 * PI) Ampere-turns const ampereTurnsValue = gilbertValue * (10 / (4 * Math.PI)); // Display the result in the result area, formatted to 4 decimal places. resultArea.innerHTML = `

${gilbertValue} Gb is equal to ${ampereTurnsValue.toFixed(4)} AT.

`; downloadPdfButton.style.display = 'block'; // Show PDF button after a valid calculation. } /** * Clears the input field and resets the result area. */ function clearInputsAndResults() { const gilbertInput = document.getElementById('gilbertInput'); const resultArea = document.getElementById('resultArea'); const downloadPdfButton = document.getElementById('downloadPdfButton'); // Clear the input field's value. if (gilbertInput) { gilbertInput.value = ''; } // Reset the content of the result area to its initial state. if (resultArea) { resultArea.innerHTML = '

Enter a value and click \'Convert\' to see the result.

'; } // Hide the PDF download button. if (downloadPdfButton) { downloadPdfButton.style.display = 'none'; } } /** * Generates and downloads a PDF document containing the conversion details. */ function generatePdf() { // Check if the jsPDF library is loaded before attempting to use it. if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { console.error('jsPDF library not loaded. Cannot generate PDF.'); // Provide user feedback without using alert() const resultArea = document.getElementById('resultArea'); if (resultArea) { resultArea.innerHTML = '

PDF generation failed. Library not loaded.

'; } return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Initialize a new jsPDF document. // Get input and result elements for content. const gilbertInput = document.getElementById('gilbertInput'); const resultArea = document.getElementById('resultArea'); if (!gilbertInput || !resultArea) { console.error('Cannot generate PDF: Input or result elements missing.'); return; } // Retrieve the values used in the conversion. const gilbertValue = parseFloat(gilbertInput.value); const ampereTurnsValue = gilbertValue * (10 / (4 * Math.PI)); // Recalculate for PDF accuracy const title = "Gilbert to Ampere-turns Conversion"; const inputLine = `Input Value: ${gilbertValue} Gilbert (Gb)`; const outputLine = `Converted Value: ${ampereTurnsValue.toFixed(4)} Ampere-turns (AT)`; // Set font size and color for the title, consistent with the tool's theme. doc.setFontSize(22); doc.setTextColor(44, 62, 80); // Darker blue/grey, matching H2 doc.text(title, 105, 30, { align: 'center' }); // Center the title // Set font size and color for the content, consistent with the tool's theme. doc.setFontSize(14); doc.setTextColor(51, 51, 51); // Dark grey for content text // Add input and output lines to the PDF. doc.text(inputLine, 20, 60); doc.text(outputLine, 20, 70); // Save the PDF with a descriptive filename. doc.save("Gilbert_to_Ampere_Turns_Conversion.pdf"); }
Scroll to Top