function cargarPDF1() { const fileInput = document.getElementById('pdfInputcurp1'); 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(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 claveUnica = 'Clave Única de Registro de Población'; const indiceInicio = texto.indexOf(claveUnica); if (indiceInicio !== -1) { const textoDespues = texto.substring(indiceInicio + claveUnica.length).trim(); const nuevoNombre = obtenerNuevoNombre(textoDespues); // Guardar el archivo con el nuevo nombre const blob = new Blob([pdfData], { type: 'application/pdf' }); saveAs(blob, nuevoNombre + '_.pdf'); } else { alert('No se encontró la clave única en el PDF.'); } }); }); }); }; reader.readAsArrayBuffer(file); } } function obtenerNuevoNombre(texto) { // Cortar el texto a los siguientes 18 caracteres const nombreCortado = texto.substring(0, 18); return nombreCortado; }