首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jspdf中另存为pdf后格式化表格

在jspdf中另存为pdf后格式化表格
EN

Stack Overflow用户
提问于 2015-04-10 17:53:45
回答 1查看 757关注 0票数 0

我正在尝试将谷歌图表的表格保存为pdf。我正在使用下面的代码。

代码语言:javascript
复制
function demoFromHTML() {
    var pdf = new jsPDF('p', 'pt', 'letter');
    source = $('#customers')[0];
    specialElementHandlers = {
        '#bypassme': function (element, renderer) {
            return true
        }
    };
    margins = {
        top: 80,
        bottom: 60,
        left: 40,
        width: 522
    };
    pdf.fromHTML(
    source, // HTML string or DOM elem ref.
    margins.left, // x coord
    margins.top, { // y coord
        'width': margins.width, // max width of content on PDF
        'elementHandlers': specialElementHandlers
    },

    function (dispose) {
        pdf.save('Test.pdf');
    },
    margins);
 pdf.save('Test.pdf');
}

它工作得很好,并将表保存为pdf。我的问题是如何将其转换为表格格式。pdf中的表格数据是以文本的形式逐行出现的。我使用的是以下链接的代码:

代码语言:javascript
复制
http://jsfiddle.net/xzZ7n/1/

我正在获取pdf格式的数据,如下所示:

代码语言:javascript
复制
Country
Population
Date
Age
Chinna
1,363,480,000
March 24, 2014
19.1
India
1,241,900,000
March 24, 2014
17.4
United States
317,746,000
March 24, 2014
4.44
Indonesia
249,866,000
July 1, 2013
3.49
Brazil
201,032,714
July 1, 2013
2.81

我需要一个表格格式。

EN

回答 1

Stack Overflow用户

发布于 2015-04-14 21:14:17

确保已包含以下所有脚本文件

代码语言:javascript
复制
<script src="/Scripts/plugin/jsPdf/jspdf.js"></script>
<script src="/Scripts/plugin/jsPdf/jspdf.plugin.standard_fonts_metrics.js">   </script>
<script src="/Scripts/plugin/jsPdf/jspdf.plugin.split_text_to_size.js"></script>
<script src="/Scripts/plugin/jsPdf/jspdf.plugin.from_html.js"></script>
<script src="/Scripts/plugin/jsPdf/jspdf.plugin.addimage.js"></script>
<script src="/Scripts/plugin/jsPdf/FileSaver.min.js"></script>
<script src="/Scripts/plugin/jsPdf/jspdf.debug.js"></script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29558409

复制
相关文章

相似问题

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