how to set font size of exported table in jspdf.js?
pdf.setFont("helvetica");pdf.setFontType("bold");pdf.setFontSize(9);
it seems that pdf.fromHTML on tables ignores styling, or even jsPdf settings, such as pdf.setFont("helvetica");
etc.
so you can make changes to the original jspdf.debug.js file:
a) default autoSize
is false
, so you may change it.
b) default fontSize
is 12 - you should senthe d smaller value (add your value to the last argument).
/*** TABLE RENDERING ***/} else if (cn.nodeName === "TABLE") { table2json = tableToJson(cn, renderer); renderer.y += 10; renderer.pdf.table(renderer.x, renderer.y, table2json.rows, table2json.headers, { autoSize : true, printHeaders : true, margins : renderer.pdf.margins_doc, fontSize : 9 });}
I give you an example that works for me:
function imprimirPdf() { var pdf = new jsPDF('p', 'pt', 'letter'); pdf.setFont("arial", "bold"); pdf.setFontSize(14); pdf.text(20, 20, 'Consulta'); $("#idTablaDatos").css("font-size", "10px");// change property value $("#idTablaDetalle").css("font-size", "10px");// change property value source = $('#div_pdf').html();//div_pdf contains idTablaDatos and idTablaDetalle $("#idTablaDatos").css("font-size","14px");// original value $("#idTablaDetalle").css("font-size","14px");// original value specialElementHandlers = { '#bypassme': function (element, renderer) { return true } }; margins = { top: 80, bottom: 60, left: 40, width: 522 }; // 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('Test.pdf'); }, margins);}