* Create a new text field. * * Creates a text field with an empty /Kids array. Use `page.drawField()` to * add widgets that place the field on pages. * * @param name - Field name (must be unique) * @param options - Text field options * @returns The created text field * @throw
(name: string, options: TextFieldOptions = {})
| 527 | * ``` |
| 528 | */ |
| 529 | createTextField(name: string, options: TextFieldOptions = {}): TextField { |
| 530 | this.validateUniqueName(name); |
| 531 | |
| 532 | // Build field flags |
| 533 | let flags = 0; |
| 534 | |
| 535 | if (options.multiline) { |
| 536 | flags |= FieldFlags.MULTILINE; |
| 537 | } |
| 538 | |
| 539 | if (options.password) { |
| 540 | flags |= FieldFlags.PASSWORD; |
| 541 | } |
| 542 | |
| 543 | if (options.comb && options.maxLength && options.maxLength > 0) { |
| 544 | flags |= FieldFlags.COMB; |
| 545 | } |
| 546 | |
| 547 | // Build default appearance string |
| 548 | const da = this.buildDefaultAppearance(options.font, options.fontSize, options.color); |
| 549 | |
| 550 | // Create field dictionary with /Kids array (separate widget model) |
| 551 | const fieldDict = PdfDict.of({ |
| 552 | FT: PdfName.of("Tx"), |
| 553 | T: PdfString.fromString(name), |
| 554 | Kids: new PdfArray([]), |
| 555 | }); |
| 556 | |
| 557 | if (flags !== 0) { |
| 558 | fieldDict.set("Ff", PdfNumber.of(flags)); |
| 559 | } |
| 560 | |
| 561 | if (da) { |
| 562 | fieldDict.set("DA", PdfString.fromString(da)); |
| 563 | } |
| 564 | |
| 565 | if (options.alignment !== undefined) { |
| 566 | fieldDict.set("Q", PdfNumber.of(alignmentToQuadding(options.alignment))); |
| 567 | } |
| 568 | |
| 569 | if (options.maxLength !== undefined && options.maxLength > 0) { |
| 570 | fieldDict.set("MaxLen", PdfNumber.of(options.maxLength)); |
| 571 | } |
| 572 | |
| 573 | if (options.defaultValue !== undefined) { |
| 574 | fieldDict.set("V", PdfString.fromString(options.defaultValue)); |
| 575 | fieldDict.set("DV", PdfString.fromString(options.defaultValue)); |
| 576 | } |
| 577 | |
| 578 | // Register font in form resources if embedded font provided |
| 579 | if (options.font) { |
| 580 | this.registerFontInFormResources(options.font); |
| 581 | } |
| 582 | |
| 583 | // Register and add to form |
| 584 | const fieldRef = this._ctx.registry.register(fieldDict); |
| 585 | this._acroForm.addField(fieldRef); |
| 586 |
no test coverage detected