document.getElementById('pdfInput').addEventListener('change', cargarPDF1); function cargarPDF1() { const fileInput = document.getElementById('pdfInput'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const pdfData = new Uint8Array(e.target.result); // Cargar el PDF y extraer texto pdfjsLib.getDocument({data: pdfData}).promise.then(function(pdf) { pdf.getPage(1).then(function(page) { page.getTextContent().then(function(textContent) { const texto = textContent.items.map(function (item) { return item.str; }).join(' '); // Buscar el texto específico y obtener el nuevo nombre const fraseInicio = 'Clave Única de Registro de Población'; const fraseFin = 'Número de Certificado de Nacimiento'; const nombreExtraido = obtenerTextoEntreFrases(texto, fraseInicio, fraseFin); if (nombreExtraido) { // Mostrar el nombre sugerido en el cuadro de texto document.getElementById('customText').value = nombreExtraido; } else { document.getElementById('customText').value = ''; // Limpiar el cuadro de texto } }); }); }); }; reader.readAsArrayBuffer(file); } else { document.getElementById('customText').value = ''; // Limpiar el cuadro de texto } } function obtenerTextoEntreFrases(texto, fraseInicio, fraseFin) { const indiceInicio = texto.indexOf(fraseInicio); const indiceFin = texto.indexOf(fraseFin, indiceInicio + fraseInicio.length); if (indiceInicio !== -1 && indiceFin !== -1) { const textoEntreFrases = texto.substring(indiceInicio + fraseInicio.length, indiceFin).trim(); return textoEntreFrases; } else { return null; } }