8

I'm new to using jsPDF, am able to generate normal PDF fine, but when am trying to apply external CSS or normal style background color its does not have any effect.

My JSP includes are:

<script  src="Javascript/external/jspdf.js"></script>
<script  src="Javascript/external/jspdf.plugin.standard_fonts_metrics.js"></script> 
<script  src="Javascript/external/jspdf.plugin.split_text_to_size.js"></script>               
<script  src="Javascript/external/jspdf.plugin.from_html.js"></script>
<script src="Javascript/external/jspdf.debug.js"></script>

I am using the script below to generate HTML.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
user2126181
  • 99
  • 1
  • 1
  • 4

1 Answers1

36

Set Font Size

var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

Set Font Type

 doc.setFont("times");
 doc.setFontType("italic");
 doc.text(20, 40, 'This is times italic.');

Set font Color

 doc.setTextColor(255,0,0);
 doc.text(20, 40, 'This is red.');
hari
  • 1,874
  • 1
  • 16
  • 10
  • think of text color in jspdf like a paintbrush. Set color, write that color, then reset color to default after to continue – David Jun 12 '21 at 12:51