Skip to content

add the option to rename AcroForm field#1748

Open
itayarielytailormed wants to merge 1 commit intoHopding:masterfrom
itayarielytailormed:add_option_to_rename_AcroForm_field
Open

add the option to rename AcroForm field#1748
itayarielytailormed wants to merge 1 commit intoHopding:masterfrom
itayarielytailormed:add_option_to_rename_AcroForm_field

Conversation

@itayarielytailormed
Copy link

What?

Added a new rename() method to the PDFField class that allows renaming form fields while maintaining their properties and values. The method includes validation to prevent duplicate field names and invalid characters. Also fixed a TypeScript spread operator issue by replacing it with concat().
Example usage:

const textField = form.createTextField('OldFieldName');
textField.setText('Test Value');
textField.rename('NewFieldName');

Why?

This feature is useful for:

  1. Programmatically updating field names in PDF forms
  2. Maintaining data integrity when field names need to be changed
  3. Providing a safe way to rename fields with proper validation
  4. Preserving field properties and values during renaming

How?

The implementation:

  1. Adds a rename() method to PDFField class that:
    • Validates the new name doesn't contain periods
    • Checks for duplicate sibling field names
    • Updates the field's partial name
  2. Adds a static fromDict method to PDFAcroField to support field lookup
  3. Includes comprehensive test coverage for various rename scenarios
  4. Fixes a TypeScript spread operator issue by using concat()

Testing?

Added extensive test coverage in PDFForm.spec.ts including:
- Basic field renaming
- Value preservation after rename
- Error handling for invalid names
- Special character handling
- Property preservation
- Duplicate name prevention
All tests pass and verify the functionality works as expected.

New Dependencies?

No new dependencies were added.

Screenshots

N/A - This is a programmatic API change that doesn't affect visual appearance.

Suggested Reading?

Yes - I've reviewed the PDF specification sections regarding form fields and field naming conventions.

Anything Else?

The implementation follows PDF specification guidelines for field naming and maintains backward compatibility with existing PDF files. The code includes proper error handling and validation to ensure robust field renaming.

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node, Deno, and the browser.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

folknor added a commit to folknor/pdf-lib that referenced this pull request Jan 29, 2026
Adds ability to rename form fields by changing their partial name.
The method validates that:
- New name is not empty
- New name doesn't contain periods (which are hierarchy separators)
- No sibling field (terminal or non-terminal) has the same name

Includes comprehensive tests for various rename scenarios.

Hopding/pdf-lib#1748

Coded by an LLM.
Maxwbh pushed a commit to Maxwbh/pdf-lib that referenced this pull request Jan 31, 2026
Analyzed popular forks and pending PRs to identify potential improvements:
- SVG support (from cantoo-scribe/pdf-lib fork)
- PDF encryption/decryption (from pdf-lib-plus-encrypt fork)
- Incremental save for digital signatures (from pdf-lib-incremental-save)
- Rounded rectangles (from pdfme/pdf-lib fork)
- Hyperlinks support (PR Hopding#1691)
- Form field improvements (PRs Hopding#1748, Hopding#1758)

https://claude.ai/code/session_01T85UagjFeYdf4vUW9pzeyn
Maxwbh added a commit to Maxwbh/pdf-lib that referenced this pull request Mar 2, 2026
Analyzed popular forks and pending PRs to identify potential improvements:
- SVG support (from cantoo-scribe/pdf-lib fork)
- PDF encryption/decryption (from pdf-lib-plus-encrypt fork)
- Incremental save for digital signatures (from pdf-lib-incremental-save)
- Rounded rectangles (from pdfme/pdf-lib fork)
- Hyperlinks support (PR Hopding#1691)
- Form field improvements (PRs Hopding#1748, Hopding#1758)

https://claude.ai/code/session_01T85UagjFeYdf4vUW9pzeyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant