如何在JSPDF中编辑TextField()的字体大小? [英] How to edit Font Size for TextField() in JSPDF?
问题描述
早上好,
有没有人能够在JSPDF中的TextField()
上编辑字体大小?
我不在乎多行是对还是错,我只需要能够设置TextField()
的默认字体大小.
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()
.
这是我的代码,来自 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);
我尝试过的事情:
-
doc.setFontSize(10);
在添加字段之前先进行设置.对文本字段字体大小没有影响 -
textField.fontSize = 10
对文本字段字体大小没有影响 -
textField.setFontSize(10)
引发错误
doc.setFontSize(10);
set this before adding the field of course. no effect on textfield font sizetextField.fontSize = 10
no effect on textfield font sizetextField.setFontSize(10)
throws error
我什至尝试下载该库并对其进行更改,但无法使其正常工作.
I even tried downloading the library and altering it but couldn't get that to work.
我还尝试在测试站点上玩耍: http://raw.githack.com/MrRio/jsPDF/master/
I also tried playing around on the testing site: http://raw.githack.com/MrRio/jsPDF/master/
我在GitHub上发现了一个类似的问题,但并没有很好地询问或解决: https://github.com/MrRio/jsPDF/issues/981
I found a similar question on GitHub but it was not asked well nor addressed: https://github.com/MrRio/jsPDF/issues/981
我正在使用最新的调试版本: https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js
I'm using the latest debug build: https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js
推荐答案
默认jsPDF行为是增加字体大小以填充TextField.您可以通过这样设置maxFontSize来防止这种情况:
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);
希望这会有所帮助.该文档非常稀疏,但是可以在这里找到: http ://raw.githack.com/MrRio/jsPDF/master/docs/module-AcroForm-AcroFormTextField.html
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
这篇关于如何在JSPDF中编辑TextField()的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!