Signature / Text field still editable even after putting ReadOnly flag as true

WebViewer Version: 11.10.0

Do you have an issue with a specific file(s)? No, this happens with any PDF that has form fields (text fields and signature fields created via WebViewer’s form field creation tools).

Can you reproduce using one of our samples or online demos? Not directly, as it requires multi-party field assignment via custom data, but the core issue — field.flags.ReadOnly = true and annot.ReadOnly = true / annot.setReadOnly(true) not preventing user interaction with WidgetAnnotation (text input and signature widgets)

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? Next.js 14 (React), but the issue is with the WebViewer Core API, not the framework.

Is your issue related to annotations? Yes — specifically WidgetAnnotation (form field widgets, including TextWidgetAnnotation and SignatureWidgetAnnotation).

Please give a brief summary of your issue:
field.flags.ReadOnly = true and annot.setReadOnly(true) On WidgetAnnotations, do not prevent the user from typing in text fields or clicking signature fields in WebViewer 11.10.0

Please describe your issue and provide steps to reproduce it:
I am working on a feature in which I want certain fields to be read-only when the document is opened.
After the document loads and XFDF annotations are imported, we iterate through all WidgetAnnotation instances and apply read-only restrictions to non-editable fields using the following approach:

// For each widget annotation that should be read-only:
const field = annot.getField();

// Method 1: Field flag
if (field?.flags) {
    field.flags.ReadOnly = true;
}

// Method 2: Annotation ReadOnly property
annot.ReadOnly = true;

// Method 3: setReadOnly API (if available)
if (typeof annot.setReadOnly === 'function') {
    annot.setReadOnly(true);
}

// Method 4: Lock flags
annot.NoMove = true;
annot.NoResize = true;
annot.NoDelete = true;

Please provide a link to a minimal sample where the issue is reproducible: NA (Internal code)

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 you’re having trouble setting fields to read-only in WebViewer 11.10.0, specifically for WidgetAnnotations like text and signature fields. Even though you’ve set the ReadOnly flag, users can still interact with these fields. This could be due to how the flags are being applied or the order in which operations are executed.

Some things you can try:

  • Ensure that the document has completely loaded before applying read-only flags. This can be done by listening to the document load event.

  • Verify that you’re iterating over the correct annotations and that the fields are being properly retrieved from these annotations.

  • Check if the XFDF import is overriding the read-only settings. Try applying the read-only flag after all XFDF data has been imported.

  • Consider using the fieldManager to enforce read-only status, which might provide more consistent results across different types of annotations.



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.

Hello Pushpam,

Thank you for contacting WebViewer Forums.

To access the field and change the ReadOnly field flag, you will first need to get the annotation associated with the field. Please see the following code that will set the flag to ReadOnly for all fields:

const fieldManager = annotationManager.getFieldManager();
const fields = fieldManager.getFields()
fields.forEach(field => {
      field.widgets.forEach(annot => {
        annot.fieldFlags.set(instance.Core.Annotations.WidgetFlags.READ_ONLY, true);
      });
    });

More information on change field properties can be found here: Modify PDF Form Fields using JavaScript | Apryse documentation

Regards,
Luke

1 Like