admin管理员组

文章数量:1394198

I have a requirement Where I need to generate a PDF file which consists of table. I am able to generate PDF. But, I want to apply styles to border. Currently the border is showing black in color. I want to change the color to white. Ho do I do that??

Here is my js function which is called when "Export to PDF" link is clicked.

For tableId I am passing my table name.

My table is as shown:

My PDF Generated is as shown:

I want to change the border color of my generate PDF to "grey". How am I supposed to do that? Can anyone please help me with this?

I have a requirement Where I need to generate a PDF file which consists of table. I am able to generate PDF. But, I want to apply styles to border. Currently the border is showing black in color. I want to change the color to white. Ho do I do that??

Here is my js function which is called when "Export to PDF" link is clicked.

For tableId I am passing my table name.

My table is as shown:

My PDF Generated is as shown:

I want to change the border color of my generate PDF to "grey". How am I supposed to do that? Can anyone please help me with this?

Share Improve this question edited Jul 1, 2019 at 5:57 Shruthi Sathyanarayana asked Mar 8, 2017 at 7:16 Shruthi SathyanarayanaShruthi Sathyanarayana 2112 gold badges4 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Before calling cell() method you have to set drawColor property.

To set draw color use setDrawColor method

setDrawColor(R,G,B);

More details about this method are here in the API documentation. http://rawgit./MrRio/jsPDF/master/docs/global.html#setDrawColor

The draw color can be reset to black by setting the RGB value to setDrawColor(0);

Example:

  //Set text color
  doc.setTextColor(0);
  doc.text(10, 10, 'This is a test');

  //Change text color
  doc.setTextColor("#42d254");
  //Set draw color
  doc.setDrawColor(150,150,150);
  doc.cell(40, 40, 50, 20, "cell"); //cell(x,y,w,h,text,i)

Check this fiddle for reference: https://jsfiddle/Purushoth/x4xo4owj/

Please checkout jsPDF-Autotable plugin which has lot of built-in features for custom styling https://simonbengtsson.github.io/jsPDF-AutoTable/#header-footer.

本文标签: javascriptHow to apply css for pdfcell in JSPDFStack Overflow