Can't make the document readOnly

WebViewer Version: 11.4.0

I’m trying to set the document to readOnly before saving it, based on the condition wether the document was signed or not, but that doesn’t work:

    if (this.signatureAdded) {
      annotationManager.getAnnotationsList().forEach(annot => {
        annot.ReadOnly = true;
      });
    }

When I open the document again, all of the annotations are still editable.

Then I tried doing it like this, based on a thread in this forum:

if (this.signatureAdded) {
annotationManager.getAnnotationsList().forEach(annot => {
annot.setModified();
annot.Author = ‘Guest’;
annot.ReadOnly = true;
});
}

Now, only one signature field gets set to readOnly, all the other annotations are still editable.

I then also tried enabling readOnlyMode to see if that works, but that also has no effect on the document at all:

documentViewer.addEventListener(‘documentLoaded’, () => {
annotationManager.enableReadOnlyMode();
});

Here is a sample PDF with the kind of form fields I’m using in the file I try to make readonly:
Testdokument1.pdf (17.7 KB)

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 trying to set your PDF document to read-only mode in WebViewer but encountering issues. When setting annotations to read-only, it’s essential to ensure that all annotations are correctly marked and the document is properly saved with these changes.

Some things you can try:

  • Ensure that you are correctly iterating over all annotations and setting each to read-only.

  • Use annot.setReadOnly(true) instead of annot.ReadOnly = true; to ensure the property is set correctly.

  • After modifying annotations, make sure to save the changes back to the document using annotationManager.exportAnnotations() and then re-import if necessary.

  • Ensure that enableReadOnlyMode() is called after the document is fully loaded and the annotations are set.

  • Check if any other parts of your code might be overriding these settings.



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,

That approach of setting read-only should work for regular annotations.

For fields, please set them read-only like this:

const { WidgetFlags } = Annotations;

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

Please see this guide for more details:

best regards,
Kevin

2 Likes