面对有关jsPDF的一些设计问题 [英] Facing some design issue about jsPDF

查看:103
本文介绍了面对有关jsPDF的一些设计问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jsPDF,它工作正常.它以"PDF"格式下载文档,但问题是我的设计错误,我希望表格显示在网站上.

I am using jsPDF it works fine. It downloads the document as "PDF" but the thing is I am getting wrong design for the same, I want the table as displayed on the site.

如何在jsPDF中设置表格的列高和宽度?

How to set the column height and width for table in jsPDF?

这是我的剧本

function exportPdf()
{
    var pdf = new jsPDF('p', 'pt', 'letter');
    // source can be HTML-formatted string, or a reference
    // to an actual DOM element from which the text will be scraped.
    source = $('#infobox')[0];

    // we support special element handlers. Register them with jQuery-style 
    // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
    // There is no support for any other type of selectors 
    // (class, of compound) at this time.
    specialElementHandlers = {
        // element with id of "bypass" - jQuery style selector
        '#infobox': function (element, renderer) {
            // true = "handled elsewhere, bypass text extraction"
            return true
        }
    };
    margins = {
        top: 10,
        bottom: 10,
        left: 10,
        width: "100%"
    };
    // all coords and widths are in jsPDF instance's declared units
    // 'inches' in this case
    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) {
        // dispose: object with X, Y of the last line add to the PDF 
        // this allow the insertion of new lines after html
        pdf.save('musterData.pdf');
    }, margins);
    return false;
} 

推荐答案

我在与您的问题相关的内容上张贴了示例代码.该代码将使用jsPDF工具将html表导出为PDF格式

I have posted a sample code on something related to your question.. That code will export html table to PDF format using jsPDF tool

寻找以下几行

doc.cellInitialize();

doc.cellInitialize();

. .

doc.cell(leftMargin,topMargin,cellWidth,rowWidth,cellContent,i)

doc.cell(leftMargin, topMargin, cellWidth, rowWidth, cellContent, i)

以下是查找我所讨论的示例代码的链接

Following is the link to find the sample code I was talking about

如何设置列宽使用jsPDF生成pdf

如果您这样做,将获得PDF格式的表格格式.如果您有任何问题,请告诉我..如果发现有帮助,别忘了投票

If you do this way you will get the tabular format in PDF. Let me know if you have any questions.. Don't forget to vote if you find it helpful

这篇关于面对有关jsPDF的一些设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆