问题
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:
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.
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