jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Can jsPDF support CSS of a webpage?

Open ykcyoshida opened this issue 11 years ago • 3 comments

Good day! I am a university student and I intend to use jsPDF for my thesis implementation.

I am developing a software application for the accounting department of a government agency. The document has a lot of borders, columns and rows that needs to be shown. Can jsPDF support that kind of reports from webpage to PDF?

Thank you and more power!

ykcyoshida avatar Mar 20 '15 14:03 ykcyoshida

Hi Yumiko, after having played around with the plugin jspdf.plugin.cell.js, I can tell you that it works, but with limited formatting capabilities. I don't think the result will be good enough, if you simply use the jspdf.plugin.from_html.js plugin with the cell-plugin to convert a webpage with tables to PDF. I would probably use the cell plugin API directly and make some changes to the plugin in order to customize the table styles like padding, row-spacing, background-color... There are also some bugs with the calculation of row-heights and the alignment of headers. I fixed these issues for me and added per column padding settings. If you are interested I can send you the edited file.

JosuaStadelmaier avatar Mar 21 '15 14:03 JosuaStadelmaier

@web-jst : I'm also not getting CSS styles correctly while exporting tables, Can you share a gist link of your modified code?

Thanks.

bhaveshgohel avatar Mar 22 '15 10:03 bhaveshgohel

@ykcyoshida @bhaveshgohel here is the modified code: https://gist.github.com/web-jst/b25bc5e793be1352850c (I commented my changes with "bugfix..." or "added...") It only works with the default unit setting (mm) and with autoSize: false You can test it with this snippet:

var headers = [{
    "name":"column1",
    "prompt":"Header 1",
    "width":35,
    "align":"right",
    "padding":1
}, {
    "name":"column2",
    "prompt":"Header 2",
    "width":65,
    "align":"left",
    "padding":4
}];

var rows = [{
    "column1":"Lorem",
    "column2":"Lorem ipsum dolor sit amet."
}, {
    "column1":"Ipsum",
    "column2":"Etiam malesuada erat."
}, {
    "column1":"Dolor",
    "column2":"Vivamus tempor urna vitae."
}];

var doc = new jsPDF();

doc.table(10, 10, rows, headers, {
    autoSize: false,
    printHeaders: true,
    rowMargin: 0,
    fontSize: 14
});

JosuaStadelmaier avatar Mar 22 '15 15:03 JosuaStadelmaier