Estoy tratando de manipular Autotable jsPDF, pero no puedo evitar generar mi pdf con estilos predeterminados. Pruebo los métodos que he leído en varios sitios, pero todos están desactualizados y han cambiado varias veces. Me gustaría agregar un título al comienzo de la tabla que esté centrado (fuera de ella), agregar color a los encabezados de la tabla y tal vez pegar una firma debajo. He probado varios modos y la única forma en que puedo imprimir un PDF sin morir en el camino es así. Intenté manipularlo desde css pero no acepta mis cambios.
function generatePdf() { var doc = new jspdf.jsPDF(); doc.autoTable({html: '.tftable'}); doc.save ("detallePrestamo.pdf"); } generatePdf()Hago esta solución, comentarios en cada línea para que se entienda qué hace cada propiedad y cómo se debe escribir
function generatePdf() { var doc = new jspdf.jsPDF(); var offsetY = 4.797777777777778; //var offsetY is for spacing var lineHeight = 6.49111111111111; //var lineHeight is for Spacing var fontSize = 12; doc.text(85, 10, "Tabla de Prestamo");//asignate coordinates to the title doc.autoTable({startY: 15,html: '.tftable', styles : { halign : 'center'}, headStyles :{fillColor : [124, 95, 240]}, alternateRowStyles: {fillColor : [231, 215, 252]}, tableLineColor: [124, 95, 240], tableLineWidth: 0.1,}); //use headStyles to bring styles to the table head, and alternateRowStyles to color the rows but one yes and one no doc.setFontSize(fontSize); var img = new Image(); //this mount a variable to img img.src = 'images/signaturePDF.png' //asign the src to the img variable doc.addImage(img, 'png', 100, doc.autoTable.previous.finalY + lineHeight * 1.5 + offsetY, 20, 20)// use the method doc.autoTable.previous.finalY + lineHeight * 1.5 + offsetY to be able to position the image of the signature below the table at a safe distance from it doc.text(90, doc.autoTable.previous.finalY + lineHeight * 5 + offsetY, "Juan Jose Urquiza") // later add the text below the signature doc.text(89, doc.autoTable.previous.finalY + lineHeight * 6 + offsetY, "Gerente FinanceAR") //more text doc.save ("detallePrestamo.pdf"); }