How to get the label of a field from a pdf

WebViewer Version: 10.9.0

I am wondering how I can read out the label of a field with pdftron/webviewer

const { documentViewer, annotationManager } = webViewerInstance.Core;
webViewerInstance.Core.documentViewer.addEventListener(“documentLoaded”, async () => {
documentViewer.getAnnotationsLoadedPromise().then(() => {
// iterate over fields
const fieldManager = annotationManager.getFieldManager();
fieldManager.forEachField(field => {
console.log(field);
// field.setValue(‘new value’);
});
});
});

when I console.log the field I can see the label appearing (eg “First Name”) but what’s the specific property name to get it. I’ve been trying to find it in the docs but couldn’t

Hello Mark,

To clarify, could you provide an image showing which specific part of the field you are referring to? Please provide a sample file as well.

Best regards,
Darian

i129.pdf (457.2 KB)

for example in this pdf, some of the fields have specific labels, eg page 1:

  • “Family Name (Last Name)”
  • “mail Address (if any)”

etc.

is there a way to get those specific values? I see some of the values in obscure key names.

Hi there,

You could try getting the field’s name like so:

const fieldManager = instance.Core.annotationManager.getFieldManager();
fieldManager.forEachField(field => {
   console.log(field.name);
});

Best Regards,
Darian

not quite, the field.name is per docs the field’s full name, in this case it’s “PREPARER_FIRST_NAME”, not the label. The label is the text string you can see above the field, in this case “First Name”.

I want the label, not the name.

eg when I print out the field and check the keys in there i can see that “First Name” is somehow in there:
looks like it’s under

field.SM.H6

but i’m wondering if there is a more programmatic way to get this?

You have the pdf now, perhaps you could try to recreate the scenario?
(formally is a paying customer btw)
Thanks!

Hello Mark,

I am not able to see the “First Name” value on my end. Could you provide more steps on you are able to view this value?

with the above code, I loop over the fields and then just do console.log(field)

And then I inspect the props. Can you mb show how your code looks like and what gets logged?

my code looks like so:

const { documentViewer, annotationManager } = webViewerInstance.Core;
webViewerInstance.Core.documentViewer.addEventListener(“documentLoaded”, async () => {
documentViewer.getAnnotationsLoadedPromise().then(() => {
const fieldManager = annotationManager.getFieldManager();
fieldManager.forEachField(field => {
console.log(field);
});

and I get above output. Maybe try the same and then post a screenshot of one of your fields?
Thanks

Hello Mark,

Note that it’s possible that this value may not be exposed.

Here is a video of the my console: Video