add the option to rename AcroForm field #1748
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Why?
This feature is useful for:
How?
The implementation:
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