How to edit Font Size for TextField() in JSPDF?

无人久伴 提交于 2019-12-13 02:55:39

问题


Good morning, Has anyone been able to edit the font size on a TextField() in JSPDF? I don't care if multi-line is true or false, I just need to be able to set the default font size of a TextField().

Here's my code, which comes from https://github.com/MrRio/jsPDF/blob/master/examples/js/acroforms.js:

doc.text('TextField:', 10, 145);
var textField = new TextField();
textField.Rect = [50, 140, 30, 10];
textField.multiline = true;
textField.value = "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse";//
textField.fieldName = "TestTextBox";
doc.addField(textField);

things I've tried:

  1. doc.setFontSize(10); set this before adding the field of course. no effect on textfield font size
  2. textField.fontSize = 10 no effect on textfield font size
  3. textField.setFontSize(10) throws error

I even tried downloading the library and altering it but couldn't get that to work.

I also tried playing around on the testing site: http://raw.githack.com/MrRio/jsPDF/master/

I found a similar question on GitHub but it was not asked well nor addressed: https://github.com/MrRio/jsPDF/issues/981

I'm using the latest debug build: https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js


回答1:


The default jsPDF behavior is to increase the font size to fill the TextField. You can prevent this by setting a maxFontSize like this:

doc.text('TextField:', 10, 145);
var textField = new TextField();
textField.Rect = [50, 140, 30, 10];
textField.multiline = true;
textField.value = "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse";//
textField.fieldName = "TestTextBox";

//SET FONT SIZE
textField.maxFontSize = 9;

doc.addField(textField);

Hope this helps. The documentation is pretty sparse but can be found here: http://raw.githack.com/MrRio/jsPDF/master/docs/module-AcroForm-AcroFormTextField.html



来源:https://stackoverflow.com/questions/58594041/how-to-edit-font-size-for-textfield-in-jspdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!