用JSPDF创建动态PDF

发布于 2025-02-11 09:42:08 字数 1216 浏览 1 评论 0原文

我需要创建一个动态的PDF。 文本内容可能会改变,因此他们的位置也可以改变。

标题COLS是这样的对象数组:

[
    {
        "title": "Vagas Ocupadas",
        "dataKey": "occupiedVacancies"
    },
    {
        "title": "Total de pés",
        "dataKey": "totalFeet"
    },
    {
        "title": "ID",
        "dataKey": "id"
    },
    {
        "title": "Local",
        "dataKey": "movementLocation"
    }
];

内容也是这样的对象数组:

[
    {
        "occupiedVacancies": "---",
        "totalFeet": "---",
        "id": 1,
        "movementLocation": "Poita"
    },
    
    {
        "occupiedVacancies": "---",
        "totalFeet": "---",
        "id": 8,
        "movementLocation": "Garagem2"
    },
    {
        "occupiedVacancies": 6,
        "totalFeet": 471,
        "id": 9,
        "movementLocation": "Garagem"
    }
];

需要将其下载到客户端,我尝试使用此信息:

    let doc = new jsPDF({ orientation: 'landscape', unit: 'px', floatPrecision: 2 });
    doc.setFont('Courier');
    doc.table(20, 30, this.exportData, this.cols, {printHeaders: true, autoSize: true});
    doc.save();

但是没有成功...它给了我这个错误:

getTextDimensions期望文本参数为字符串或类型 数字或一系列字符串。

I need to create a dynamic PDF.
The text content could change so their positions also.

The header cols is an object array like this:

[
    {
        "title": "Vagas Ocupadas",
        "dataKey": "occupiedVacancies"
    },
    {
        "title": "Total de pés",
        "dataKey": "totalFeet"
    },
    {
        "title": "ID",
        "dataKey": "id"
    },
    {
        "title": "Local",
        "dataKey": "movementLocation"
    }
];

And the content is also an object array like this:

[
    {
        "occupiedVacancies": "---",
        "totalFeet": "---",
        "id": 1,
        "movementLocation": "Poita"
    },
    
    {
        "occupiedVacancies": "---",
        "totalFeet": "---",
        "id": 8,
        "movementLocation": "Garagem2"
    },
    {
        "occupiedVacancies": 6,
        "totalFeet": 471,
        "id": 9,
        "movementLocation": "Garagem"
    }
];

It needs to be downloaded to the client, and I've tried using this:

    let doc = new jsPDF({ orientation: 'landscape', unit: 'px', floatPrecision: 2 });
    doc.setFont('Courier');
    doc.table(20, 30, this.exportData, this.cols, {printHeaders: true, autoSize: true});
    doc.save();

But without success... It gives me this error:

getTextDimensions expects text-parameter to be of type String or type
Number or an Array of Strings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2025-02-18 09:42:08

我相信标题和数据的键应匹配。您的标题和内容中有不同的键。这可能是问题。

您还可以在此处查看类似的问题: https://github.com/parallax.com/parallax/jspdf/issues/ 3053

I believe keys of header and data should be matched. You have different keys in header and content. That may be the issue.

You can also check similar issue here: https://github.com/parallax/jsPDF/issues/3053

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文