FR EN ES

Convertir Texto a PDF

Pega tus notas, artículos o código y genera al instante un documento PDF profesional paginado. 100% privado en tu navegador.

🔒 100% Local y Privado ⚡ < 1ms Instantáneo 📱 Compatibilidad Universal 🌐 Funciona sin conexión
0 caractères · 0 mots 🔒 100% privé en mémoire RAM

¿Cómo crear documentos PDF limpios a partir de texto?

Crear un PDF directamente desde texto plano sin procesadores de texto pesados es una herramienta esencial para tomar notas, guardar actas o exportar código fuente.

Características destacadas:

  • Paginación automática: El texto se distribuye de manera fluida en páginas A4 con ajuste de línea y saltos de página automáticos.
  • Tipografía estándar: Fuentes vectoriales de alta legibilidad (Helvetica, Times-Roman o Courier monoespaciada para código).
  • Encabezado y paginación: Título superior opcional y numeración automática en el pie de página (ej: Página 1/3).
  • 100% Confidencial: Tus textos nunca se transmiten a través de Internet.
¿Te ha resultado útil esta herramienta?
(function(){ var titleInput = document.getElementById('docTitleInput'); var fontSelect = document.getElementById('docFontSelect'); var fontSizeSelect = document.getElementById('docFontSizeSelect'); var formatSelect = document.getElementById('docFormatSelect'); var textInput = document.getElementById('docTextInput'); var charDisplay = document.getElementById('charCountDisplay'); var generateBtn = document.getElementById('generatePdfBtn'); var statusMsg = document.getElementById('statusMsg'); textInput.addEventListener('input', function(){ var text = textInput.value; var chars = text.length; var words = text.trim() ? text.trim().split(/\s+/).length : 0; charDisplay.textContent = chars + ' caractère' + (chars > 1 ? 's' : '') + ' · ' + words + ' mot' + (words > 1 ? 's' : ''); }); generateBtn.addEventListener('click', async function(){ var rawText = textInput.value.trim(); if(!rawText) { alert('Veuillez saisir ou coller du texte avant de générer le PDF.'); return; } generateBtn.disabled = true; statusMsg.textContent = '⏳ Génération vectorielle du PDF...'; try { var pdfDoc = await PDFLib.PDFDocument.create(); var fontName = fontSelect.value; var font; if(fontName === 'TimesRoman') font = await pdfDoc.embedFont(PDFLib.StandardFonts.TimesRoman); else if(fontName === 'Courier') font = await pdfDoc.embedFont(PDFLib.StandardFonts.Courier); else font = await pdfDoc.embedFont(PDFLib.StandardFonts.Helvetica); var fontBold = await pdfDoc.embedFont(fontName === 'Courier' ? PDFLib.StandardFonts.CourierBold : (fontName === 'TimesRoman' ? PDFLib.StandardFonts.TimesRomanBold : PDFLib.StandardFonts.HelveticaBold)); var fontSize = parseInt(fontSizeSelect.value, 10) || 12; var lineHeight = fontSize * 1.45; var margin = 50; // points (~17.6mm) var isA4 = formatSelect.value === 'A4'; var pageWidth = isA4 ? 595.28 : 612; var pageHeight = isA4 ? 841.89 : 792; var contentWidth = pageWidth - (margin * 2); // Wrap text into lines var paragraphs = rawText.split(/\r?\n/); var allLines = []; paragraphs.forEach(function(para){ if(!para.trim()) { allLines.push(''); return; } var words = para.split(' '); var curLine = ''; for(var w = 0; w < words.length; w++) { var testLine = curLine ? curLine + ' ' + words[w] : words[w]; var width = font.widthOfTextAtSize(testLine, fontSize); if(width <= contentWidth) { curLine = testLine; } else { if(curLine) allLines.push(curLine); curLine = words[w]; } } if(curLine) allLines.push(curLine); }); var titleText = titleInput.value.trim(); var startY = pageHeight - margin - 20; var bottomLimit = margin + 30; // Distribute lines across pages var pages = []; var curPageLines = []; var currentY = startY; if(titleText) currentY -= 35; // leave space for title for(var i = 0; i < allLines.length; i++) { if(currentY - lineHeight < bottomLimit) { pages.push(curPageLines); curPageLines = []; currentY = startY; } curPageLines.push(allLines[i]); currentY -= (allLines[i] === '' ? lineHeight * 0.75 : lineHeight); } if(curPageLines.length > 0) pages.push(curPageLines); var totalP = pages.length; pages.forEach(function(pLines, pIdx){ var page = pdfDoc.addPage([pageWidth, pageHeight]); var yPos = startY; // Header title on page 1 if(pIdx === 0 && titleText) { page.drawText(titleText, { x: margin, y: pageHeight - margin, size: fontSize + 6, font: fontBold, color: PDFLib.rgb(0.1, 0.1, 0.15) }); yPos -= 35; } pLines.forEach(function(line){ if(line) { page.drawText(line, { x: margin, y: yPos, size: fontSize, font: font, color: PDFLib.rgb(0.15, 0.15, 0.2) }); } yPos -= (line === '' ? lineHeight * 0.75 : lineHeight); }); // Footer: Page numbers var pageStr = (pIdx + 1) + ' / ' + totalP; var numWidth = font.widthOfTextAtSize(pageStr, 9); page.drawText(pageStr, { x: (pageWidth - numWidth) / 2, y: margin - 15, size: 9, font: font, color: PDFLib.rgb(0.5, 0.5, 0.55) }); }); var pdfBytes = await pdfDoc.save(); var blob = new Blob([pdfBytes], { type: 'application/pdf' }); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; var safeName = (titleText ? titleText.toLowerCase().replace(/[^a-z0-9]+/g, '-') : 'document') + '.pdf'; a.download = safeName; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); statusMsg.innerHTML = '✓ Document PDF généré et téléchargé avec succès (' + totalP + ' page' + (totalP > 1 ? 's' : '') + ') !'; } catch(err) { console.error(err); statusMsg.innerHTML = 'Erreur : ' + err.message + ''; } finally { generateBtn.disabled = false; } }); })();