Readonly formfields/signature fields in pdf viewer

Hello,

iam trying to create a read only pdf viewer and the basic stuff is pretty easy (hide toolbar items and so on).

But now iam trying to set all form fields to readonly.

Cause we are loading out document over an ajax service not all form fields are present if i only load first page (please correct me if iam wrong). Ive subscribe to the ajaxRequestSuccess event and tried to set all form fields to isReadonly = true.


    this.pdfViewer.enableFormFields = !this.readOnly;
    this.pdfViewer.formFieldCollection.forEach((f) => {
      f.isReadonly = this.readOnly;
      f.properties.isReadonly = this.readOnly;
    });
    this.pdfViewer.dataBind();
    this.pdfViewer.refresh();


But i can still add a signature to the signature field. If i scroll now few pages down and back up the field is now readonly.

Is there a better way?


2 Replies 1 reply marked as answer

CK Chinnamunia Karthik Chinna Thambi Syncfusion Team February 5, 2024 10:37 AM UTC

Hi Marc,


We have the `updateFormField` method, by utilizing this method you can make the form fields as read-only. We've provided a code snippet and a sample to demonstrate this functionality.


Code snippet:


 

var viewer = (<any>document.getElementById('pdfViewer')).ej2_instances[0];

var formFields = viewer.retrieveFormFields();

formFields.map((formField) => {

  var isReadOnly = { isReadOnly: true };

  viewer.formDesignerModule.updateFormField(formField, isReadOnly);

});


Sample:  https://stackblitz.com/edit/angular-vsw1nt?file=src%2Fapp.component.html,src%2Fapp.component.ts


In the provided sample, the `documentLoad` event is triggered when loading the document. Within this event, we make the form fields read-only using the `updateFormField` method.


Marked as answer

MS Marc Schwöbel February 19, 2024 11:34 PM UTC

Thanks it is working


Loader.
Up arrow icon