[Feature Request] API to access coordinates and dimensions of form fields
See original GitHub issueLooking at the low level acroform spec, we should be able to get dimensions / positions of fields.
A good use case for this is knowing where and what size to stamp an image. We can leave a blank readOnly field in our form, and effectively “fill” it with an image.
const form = doc.getForm();
const field = doc.getField('somefield');
// This would be useful
const fieldDimensions = field.getDimensions(); // {x: number, y: number, width: number, height: number}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to use the Form_Fields_Per_Document parameter
The form_fields_per_document parameter allows you to place fields on a document using a coordinate system. You can set the x and y coordinates...
Read more >Query (Feature Service/Layer)—ArcGIS REST APIs
The feature service layer Query operation supports querying the count of distinct features within a field using the returnDistinctValues and returnCountOnly ...
Read more >Coordinates | Maps JavaScript API - Google Developers
Returns a string of the form "lat,lng" for this LatLng. We round the lat/lng values to 6 decimal places by default. LatLngLiteral interface....
Read more >jQuery API Documentation
jQuery API. jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, ...
Read more >Web Services APIs - Mapbox docs
The Mapbox web services APIs allow you to programmatically access Mapbox tools and ... API, Default coordinates per request, Default requests per minute ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hello @jamesmfriedman!
Happy to accept PRs for this. The information is certainly accessible. The main thing to be aware of when designing such an API is that form fields do not necessarily have just one single location on a page. The same field can actually be rendered in multiple locations on different pages. So, effectively, a single field can have multiple coordinates and dimensions. See https://pdf-lib.js.org/docs/api/classes/pdffield for a bit more detail about this.
Here’s an example of how you can access the information with the current APIs:
Note also that if you’re specifically looking to stamp images on fields,
pdf-libprovides aPDFButton.setImagemethod that does exactly this. Though it currently only exists for button fields.I’m not sure it makes sense to mix the page with the coordinates. Once #695 gets merged, you would be able to find the page or page number of a widget:
element.getCoordinates()is trivial to implement, if we just want the coordinates. @Hopding is the plan to keepacroFieldprivate? We could document it, along withwidget. Otherwise, we could implement agetCoordinates()on the element.