Skip to content

add the option to rename AcroForm field #1748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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