Renaming duplicate AcroForm fields in WebViewer 11.6

WebViewer Version:

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? Yes

Hello,

I’m using Apryse WebViewer 11.6 and need assistance solving an issue with duplicate AcroForm fields.

Problem: I have a PDF with fields that share the same name (e.g., “Check Box3” appears twice as separate widgets but associated with the same logical field). This causes conflicts in my application.

Goal: I would like to automatically add an incremental suffix (_1, _2, _3, etc.) to all fields that have the same AcroField name, making them unique.

Event Issue: I’ve noticed that:

  1. The documentLoaded event is triggered before annotations are loaded
  2. The annotationsLoaded event is never triggered in my code:
this.instance.Core.annotationManager.addEventListener('annotationsLoaded', async () => {
    console.log('annotationsLoaded');
});

Questions:

  1. Why isn’t the annotationsLoaded event being triggered? Is there an issue with my implementation?
  2. Could you provide a working code example that allows me to:
  • Detect AcroForm fields with duplicate names
  • Rename them by adding incremental suffixes (_1, _2, _3)
  • Do this at the right moment when annotations are actually loaded?
  • Important: I’m looking for a clean solution that directly renames the existing widgets, not recreating them with different methods

10-pg-CHECKBOX.pdf (12.9 KB)

Thank you for your assistance.

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems like you’re encountering an issue with duplicate AcroForm field names in a PDF document using Apryse WebViewer. The task is to ensure that fields with the same name are renamed with unique identifiers. This involves handling events correctly and using the appropriate methods to detect and rename these fields.

Some things you can try:

  • Ensure that your event listener for annotationsLoaded is correctly set up. This event should be triggered once all annotations are fully loaded into memory.

  • Use the FieldManager to iterate over form fields once the annotations are loaded. This will allow you to identify fields with duplicate names.

  • Rename the fields by appending an incremental suffix. Ensure that you update both the field name and its associated widget annotations.

  • Check if the annotationsLoadedPromise resolves correctly to ensure fields are accessible when you attempt to modify them.




Here are some resources that might help you:



Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hi there,

  1. Why isn’t the annotationsLoaded event being triggered? Is there an issue with my implementation?

The annotationsLoaded event is under the documentViewer class, it should looks like this:

        documentViewer.addEventListener('annotationsLoaded', async () => {

        })
  • Detect AcroForm fields with duplicate names

You can get the IDs of the widgets in your document via the Id attribute of the annotation:

const widgetAnnotations = annotationManager.getAnnotationsList().filter(annotation => annotation instanceof Annotations.WidgetAnnotation)

widgetAnnotations.forEach(widget => {
    console.log(widget.Id)
})

Note that annotations must have unique IDs per page (as per PDF specification) and the 4 widgets in your document have unique IDs.

  • Rename them by adding incremental suffixes (_1, _2, _3)

The widgets are unique, but if you want to change the name of the field, you can use the setField API:

  • Do this at the right moment when annotations are actually loaded?

You can do this in the annotationsLoaded event

Best regards,
Kevin

1 Like