1const logueado = localStorage.getItem('isUserLogged'); 2if (!logueado) { 3 document.getElementById('desaparece').classList.add('d-none'); 4} 5document.addEventListener('DOMContentLoaded', () => { 6 document.getElementById('downloadBtn').addEventListener('click', () => { 7 const { jsPDF } = window.jspdf; 8 9 // Seleccionar el contenido del contenedor especÃfico 10 const content = document.getElementById('contenedor'); 11 12 if (!content) { 13 console.error('El contenedor no se encuentra en el DOM.'); 14 return; 15 } 16 17 // Crear una instancia de jsPDF 18 const pdf = new jsPDF('p', 'mm', 'a4'); 19 20 // Obtener todos los elementos de texto e imágenes dentro del contenedor 21 const elements = content.querySelectorAll('h2, h3, p, img'); 22 23 let yPosition = 10; // Posición inicial en el PDF 24 25 elements.forEach(element => { 26 if (element.tagName === 'H2') { 27 pdf.setFontSize(16); 28 pdf.text(element.innerText, 10, yPosition); 29 yPosition += 10; // Incrementar la posición para el siguiente elemento 30 } else if (element.tagName === 'H3') { 31 pdf.setFontSize(14); 32 pdf.text(element.innerText, 10, yPosition); 33 yPosition += 10; 34 } else if (element.tagName === 'P') { 35 pdf.setFontSize(12); 36 pdf.text(element.innerText, 10, yPosition); 37 yPosition += 8; 38 } else if (element.tagName === 'IMG') { 39 // Si es una imagen, la añadimos al PDF 40 const imgData = element.src; 41 pdf.addImage(imgData, 'JPEG', 10, yPosition, 30, 30); 42 yPosition += 35; // Ajustar la posición después de la imagen 43 } 44 45 // Si la posición supera el lÃmite de la página, añadir una nueva página 46 if (yPosition > 280) { 47 pdf.addPage(); 48 yPosition = 10; // Reiniciar la posición en la nueva página 49 } 50 }); 51 52 // Descargar el archivo PDF 53 pdf.save('informacion.pdf'); 54 }); 55}); 56function logout() { 57 localStorage.clear(); 58}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.