https://developers.google.com/funding-choices/fc-api-docs NewsWave

Sunday, September 10, 2023



Text to PDF Converter

Text to PDF Converter

body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; padding: 0; } .container { max-width: 800px; margin: 0 auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 5px; text-align: center; } h1 { color: #333; } .input-container { margin: 20px 0; } textarea { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; resize: vertical; } .btn { padding: 10px 20px; font-size: 16px; background-color: #007BFF; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .btn:hover { background-color: #0056b3; } // Import pdfmake library import pdfMake from 'pdfmake/build/pdfmake'; import pdfFonts from 'pdfmake/build/vfs_fonts'; // Initialize pdfMake pdfMake.vfs = pdfFonts.pdfMake.vfs; // Get HTML elements const textInput = document.getElementById('textInput'); const convertButton = document.getElementById('convertButton'); const downloadLink = document.getElementById('downloadLink'); // Add event listener to the convert button convertButton.addEventListener('click', () => { const text = textInput.value; if (text.trim() !== '') { generatePDF(text); } }); // Function to generate and display PDF function generatePDF(text) { const docDefinition = { content: [ { text: 'Converted PDF', style: 'header' }, { text: text, margin: [0, 20] }, ], styles: { header: { fontSize: 18, bold: true, margin: [0, 0, 0, 20], }, }, }; const pdf = pdfMake.createPdf(docDefinition); pdf.getDataUrl((dataUrl) => { downloadLink.href = dataUrl; downloadLink.style.display = 'block'; }); }

No comments:

Post a Comment