首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表格处理pdf下载格式

表格处理pdf下载格式
EN

Stack Overflow用户
提问于 2019-10-16 01:05:03
回答 1查看 1K关注 0票数 1

我有一些困难,使pdf格式的方式,我是追求。现在看来,这个表是在设置的位置上绘制的,而不是在我试图放在顶部的头数据之后绘制的。逻辑是在autoTable函数中的最后一个元素之后开始绘制表。我还希望使表中的字体大小更小,尽管AutoTable setFontSize似乎也不适用于该表。

如果您在本页底部下载pdf,您可以看到结果:https://rhinoaustralia.com/price-list/

守则如下:

代码语言:javascript
复制
//trigger download of data.pdf file
$("#download-pdf").click(function(){
var today = new Date(); 
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDay();
table.download("pdf", "price-list.pdf", {
orientation:"portrait", //set page orientation to portrait
title:"Price List", //add title to report
autoTable:function(doc)
{ 
    var margins = 30;
    var marginsIndent = 20;
    doc.text("Name: ", margins, margins);
    doc.text(document.getElementById("user-name").value, margins + 60, margins);
    doc.text("Club: ", margins, margins+10);
    doc.text(document.getElementById("user-club").value, margins + 60, margins + 10);
    doc.text("Phone: ", margins, margins+20);
    doc.text(document.getElementById("user-tel").value, margins + 60, margins + 20);
    doc.text("Email: ", margins, margins+30);
    doc.text(document.getElementById("user-email").value, margins +60, margins + 30);
    doc.text("Date: ", margins, margins+40);
    doc.text(date, margins + 60, margins + 40);
    doc.setFontSize(10); //Want the tables font to be this size
},
})
});

我认为我对制表器中的autoTable集成的理解是错误的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-26 04:55:25

现在一切都如期而至。我所追求的部分是pdf创建结束时的返回样式。有一个startY值将表向下推到第一页上的x个单位数量。

代码语言:javascript
复制
//trigger download of data.pdf file
$("#download-pdf").click(function()
{
    var logo = "Base64CodeImg"; //Really long string of the logo in base 64
    var today = new Date(); 
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDay();
    var doc = new jsPDF("p", "mm", "a4");

    table.download("pdf", "price-list.pdf", {
    orientation:"portrait", //set page orientation to portrait
    autoTable:function(doc)
    { 
        var margins = 30;
        var leftMargin = 40;
        var marginsIndent = 40;
        doc.addImage(logo, 'PNG', 400, 20, 120, 120);
        doc.text("Name: ", marginsIndent, 40);
        doc.text(document.getElementById("user-name").value, marginsIndent + 60, 40);
        doc.text("Club: ", marginsIndent, 60);
        doc.text(document.getElementById("user-club").value, marginsIndent + 60, 60);
        doc.text("Phone: ", marginsIndent, 80);
        doc.text(document.getElementById("user-tel").value, marginsIndent + 60, 80);
        doc.text("Email: ", marginsIndent, 100);
        doc.text(document.getElementById("user-email").value, marginsIndent +60, 100);
        doc.text("Date: ", marginsIndent,120);
        doc.text(date, marginsIndent + 60, 120);
        doc.setFontSize(10); //Want the tables font to be this size
        return {
            styles: {cellPadding: 2, fontSize: 8},
            startY: 180, //This was the way to push the start of the table down
        };
    },
    })
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58404395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档