【问题标题】:jsPDF autotable color in header and center text in rowsjsPDF自动颜色在标题和行中的中心文本
【发布时间】:2021-11-02 16:00:12
【问题描述】:

我正在尝试操作 Autotable jsPDF,但我忍不住用默认样式生成了我的 pdf。我尝试了在各个站点上阅读过的方法,但是它们都已过时,并且已经更改了几次。 我想在居中(在其外部)的表格的开头添加一个标题,为表格标题添加颜色,并可能在其下方粘贴一个签名。我尝试了各种模式,唯一可以打印 PDF 而不会在途中死掉的方法就是这样。我尝试从 css 操作它,但它不需要我的更改。

    function generatePdf() {
    var doc = new jspdf.jsPDF();
    doc.autoTable({html: '.tftable'});
    doc.save ("detallePrestamo.pdf");

}
generatePdf()

【问题讨论】:

    标签: javascript pdf colors jspdf jspdf-autotable


    【解决方案1】:

    我做了这个解决方案,在每一行上使用 cmets,以便了解每个属性的作用以及应该如何编写

    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");
    
    }
    

    这是我在 image 中的结果

    【讨论】:

    • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2012-02-24
    • 1970-01-01
    相关资源
    最近更新 更多