Tech Blog Post Generator

Tech Blog Post Generator

Generate high-quality technical articles in seconds.

Define Your Article

Your generated article will appear here.

'; }; const handleDownloadPdf = () => { if (!window.jspdf) { console.error('jsPDF not loaded.'); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); pdf.addFont('courier', 'normal', 'normal'); const pageW = pdf.internal.pageSize.getWidth(); const pageH = pdf.internal.pageSize.getHeight(); const margin = 50; const maxLineWidth = pageW - margin * 2; let cursorY = margin; const addPageIfNeeded = (spaceNeeded) => { if (cursorY + spaceNeeded > pageH - margin) { pdf.addPage(); cursorY = margin; } }; const articleText = generatedArticleEl.value || "No article generated."; const lines = articleText.split('\n'); let isCodeBlock = false; for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (line.startsWith('```')) { isCodeBlock = !isCodeBlock; if(isCodeBlock) cursorY += 10; else cursorY += 5; continue; } if (isCodeBlock) { let codeBlockText = ''; while (i + 1 < lines.length && !lines[i + 1].startsWith('```')) { codeBlockText += lines[++i] + '\n'; } const wrappedCode = pdf.setFont('courier', 'normal').setFontSize(9).setTextColor(48, 59, 78) // Slate-700 .splitTextToSize(codeBlockText, maxLineWidth - 20); const blockHeight = wrappedCode.length * 10 + 20; addPageIfNeeded(blockHeight); pdf.setFillColor(241, 245, 249); // Slate-100 pdf.setDrawColor(226, 232, 240); // Slate-200 pdf.rect(margin, cursorY - 5, maxLineWidth, blockHeight, 'FD'); pdf.text(wrappedCode, margin + 10, cursorY + 10); cursorY += blockHeight; } else if (line.startsWith('## ')) { const titleText = line.substring(3); const titleLines = pdf.setFont('helvetica', 'bold').setFontSize(22).setTextColor(15, 23, 42) // Slate-900 .splitTextToSize(titleText, maxLineWidth); addPageIfNeeded(titleLines.length * 22 + 15); pdf.text(titleLines, margin, cursorY); cursorY += titleLines.length * 22 + 15; } else if (line.startsWith('### ')) { cursorY += 12; const headingText = line.substring(4); const headingLines = pdf.setFont('helvetica', 'bold').setFontSize(15).setTextColor(30, 64, 175) // Blue-800 .splitTextToSize(headingText, maxLineWidth); addPageIfNeeded(headingLines.length * 15 + 10); pdf.text(headingLines, margin, cursorY); cursorY += headingLines.length * 15 + 5; } else if (line.trim() !== "") { const paraLines = pdf.setFont('helvetica', 'normal').setFontSize(11).setTextColor(51, 65, 85) // Slate-600 .splitTextToSize(line, maxLineWidth); addPageIfNeeded(paraLines.length * 12 + 8); pdf.text(paraLines, margin, cursorY); cursorY += paraLines.length * 12 + 8; } } pdf.save(`Tech-Blog-Post-${(articleTopicEl.value || 'Untitled').replace(/\s+/g, '-')}.pdf`); }; // --- Event Listeners --- if (generateBtn) generateBtn.addEventListener('click', handleGenerateClick); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', handleDownloadPdf); });
Scroll to Top