如何在 JSPDF 中编辑 TextField() 的字体大小?

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

早上好, 有没有人能够在 JSPDF 中编辑 TextField() 上的字体大小? 我不关心多行是真还是假,我只需要能够设置一个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);

我尝试过的事情:

  1. doc.setFontSize(10);当然是在添加字段之前设置这个。对文本字段字体大小没有影响
  2. textField.fontSize = 10 对文本字段字体大小没有影响
  3. textField.setFontSize(10) 抛出错误

我什至尝试下载库并对其进行修改,但无法正常工作。

我也试过在测试站点上玩: http://raw.githack.com/MrRio/jsPDF/master/

我在 GitHub 上发现了一个类似的问题,但没有很好地提出也没有解决: https://github.com/MrRio/jsPDF/issues/981

我正在使用最新的调试版本:https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js

默认的 jsPDF 行为是增加字体大小以填充 TextField。您可以通过像这样设置 maxFontSize 来防止这种情况:

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