Disabling modifying signature fields

Product: pdftron webviewer

Product Version: 10.3.0

Please give a brief summary of your issue:
Hello @Apryse,
Our Organisation using pdftron for our react-app. We are using pdftron for two pages in the app. one of the page is to add the signature fields and text fields to the document and second page (sign page) is to show that pdf (to which the signature fields and text fields are added) to user. Now, in the second page (sign page) user should only be able to sign those fields he shouldn’t be able to modify those signature fields (like moving those fields or deleting those signature fields ) i have tried to disable modifying those signature fields by adding those fields Listable to true but when i do that the user cannot add signature to the signature fields is there any other way to make the user just sign those fields and not to move or delete those signature fields in the second page (sign page). and one thing to mention for development we are using trial keys and for the prod we are using actual license key of pdftron. Thank you.

Please describe your issue and provide steps to reproduce it:

Please provide a link to a minimal sample where the issue is reproducible:
documentViewer
.getAnnotationsLoadedPromise()
.then(async () => {
const signatureWidgetAnnots = annotationManager
.getAnnotationsList()
.filter(
(annot) =>
annot instanceof Annotations.SignatureWidgetAnnotation,
);

          signatureWidgetAnnots.map((each) => {
            each.ReadOnly = true;
            each.Listable = false;
            each.LockedContents = true;
          });

              let allFieldsHasSignature = false;
              for (let i = 0; i < signatureWidgetAnnots.length; i++) {
                const widgetAnnot = signatureWidgetAnnots[i] as any;
                const isSigned =
                  (await widgetAnnot.isSignedDigitally()) as boolean;

                if (!isSigned) {
                  allFieldsHasSignature = false;
                  break;
                } else {
                  allFieldsHasSignature = true;
                }
              }

              if (allFieldsHasSignature) {
                instance.UI.disableElements([
                  "CustomSave",
                  "toolbarGroup-FillAndSign",
                  "annotationClearSignatureButton",
                ]);



              }
              }
            })

Thank you for contacting Apryse support.

We are reviewing your request and will get back to you shortly.

I will get this over to the appropriate team. They should be in contact shortly.

Hi there,

Thank you for contacting WebViewer forums,

The listable property is used to show them in the notesPanel:
https://docs.apryse.com/api/web/Core.Annotations.WidgetAnnotation.html#Listable__anchor

When the signature widget is signed, a signature annotation is created on top of the widget, and I believe what you are trying to do is to make that signature read-only.

You can do something like this:

instance.Core.documentViewer.getTool(instance.Core.Tools.ToolNames.SIGNATURE).addEventListener('signatureReady', (signature) => {
    signature.ReadOnly = true;
});

Best regards,
Kevin Kim

Hello Kevin Kim,

No, Here we are trying to achieve a sign page in which signature fields are already present on pdf. The thing we aretrying to achieve is user opens that page and sign the document. So in that page user should only be able to add signatures to the signature field he shouldn’t be able to modify those signature fields ( like move those signature fields or modify (delete) those signature fields but he should be able to add the signatures to signature fields. This is what i am trying to achieve. I tried different ways using the apryse documentation but i couldn’t achieve exact result for that page. So could you please help me find a solution or atleast point me a documentation of apryse webviewer which could helpful for me to make that work.

The problem with your suggested code this makes the user can only sign the signature field just one time. the user will not able to modify his signature once he signs the signature field but he can still delete the signature field. but i am not asking about the signature i am asking for the signature fields. Hoping that the code of our page would help the cause so i am pasting the code we are using in our sign page.

    WebViewer(
          {
            path: "/webviewer/lib",
            initialDoc: initialDocument,
            fullAPI: true,
            licenseKey,
            disabledElements: [
              "dropdown-item-toolbarGroup-Annotate",
              "dropdown-item-toolbarGroup-Shapes",
              "dropdown-item-toolbarGroup-Insert",
              "dropdown-item-toolbarGroup-Edit",
              "dropdown-item-toolbarGroup-Forms",
              "dropdown-item-toolbarGroup-Drop",
              "toolbarGroup-Annotate",
              "toolbarGroup-Shapes",
              "toolbarGroup-Insert",
              "toolbarGroup-Edit",
              "toolbarGroup-Forms",
              "toolbarGroup-Drop",
              "contextMenuPopup",
              "textPopup",
              "rubberStampToolGroupButton",
              "freeTextToolGroupButton",
              "crossStampToolButton",
              "checkStampToolButton",
              "dotStampToolButton",
              "dateFreeTextToolButton",
              "variables",
              "freeHandToolGroupButton",
              "menuButton",
            ],
          },
          viewer.current,
        )
          .then((instance) => {
            wvInstance.current = instance;
            const { UI, Core } = instance;
            const {
              documentViewer,
              annotationManager,
              Annotations,
              Tools,
              PDFNet,
            } = Core;
            setAnnotationManager(annotationManager);
            UI.setToolMode("selectToolButton");
            const signatureTool: any = documentViewer.getTool(
              "AnnotationCreateSignature",
            );

            

            const handleSaveFile = async () => {
              const doc = documentViewer.getDocument();
              const xfdfString = await annotationManager.exportAnnotations({
                widgets: true,
                fields: true,
              });
              const data = await doc.getFileData({ xfdfString});
              const arr = new Uint8Array(data);
              const blob = new Blob([arr], { type: "application/pdf" });
              instance.UI.loadDocument(blob);
              const base64Data: any = await blobToBase64(blob);
              localStorage.setItem(
                `contract_pdf_${contract.FilePath}`,
                base64Data,
              );
              toast.success("Signatures saved successfully!");
            };

            UI.setHeaderItems((header) => {
              header.push({
                type: "actionButton",
                img:
                  theme === "dark"
                    ? "/icons/wvsave_dark.svg"
                    : "/icons/wvsave_light.svg",
                dataElement: "CustomSave",
                onClick: handleSaveFile,
              });
            });

            const checkDocumentHasSignature = async () => {
             
              documentViewer
                .getAnnotationsLoadedPromise()
                .then(async () => {
                  const signatureWidgetAnnots = annotationManager
                    .getAnnotationsList()
                    .filter(
                      (annot) =>
                        annot instanceof Annotations.SignatureWidgetAnnotation,
                    );

                    
             

                  let allFieldsHasSignature = false;
                  for (let i = 0; i < signatureWidgetAnnots.length; i++) {
                    const widgetAnnot = signatureWidgetAnnots[i] as any;
                    const isSigned =
                      (await widgetAnnot.isSignedDigitally()) as boolean;

                    if (!isSigned) {
                      allFieldsHasSignature = false;
                      break;
                    } else {
                      allFieldsHasSignature = true;
                    }
                  }

                  if (allFieldsHasSignature) {
                    instance.UI.disableElements([
                      "CustomSave",
                      "toolbarGroup-FillAndSign",
                      "annotationClearSignatureButton",
                    ]);



                  }
                })
              
            };

            const convertTemplatesToAnnotationString = async () => {
              let xfdfString = await annotationManager.exportAnnotations({
                links: false,
                widgets: true,
                fields: true,
              });
              await annotationManager.importAnnotations(xfdfString);
              const annotationList = annotationManager.getAnnotationsList();
              const signAnnots: Array<number> = [];
              annotationList.map(async (annot, index) => {
                if (annot instanceof Annotations.SignatureWidgetAnnotation) {
                  signAnnots.push(index);
                   annot.NoMove = true ;
                  annot.NoDelete= true;
               
               
                }
              });
              setSignatureList([...signAnnots]);

              

           

          



        
            };

            documentViewer.addEventListener("documentLoaded", async () => {
              checkDocumentHasSignature();
              convertTemplatesToAnnotationString();
            });

            instance.UI.NotesPanel.disableAutoExpandCommentThread();

            signatureTool.setSigningMode(
              instance.Core.Tools.SignatureCreateTool.SigningModes.APPEARANCE,
            );

            const normalStyles = (widget: any) => {
              if (widget instanceof Annotations.SignatureWidgetAnnotation) {
                return {
                  border: "1px solid #000000",
                };
              }
            };

            const widgetAnnot: any = Annotations.WidgetAnnotation;
            annotationManager.addEventListener(
              "annotationChanged",
              (annotations, action, { imported }) => {
                if (imported && action === "add") {
                  annotations.forEach(function (annot: any) {
                    if (annot instanceof Annotations.WidgetAnnotation) {
                      widgetAnnot.getCustomStyles = normalStyles;
                    }
                  });
                }
              },
            );

            wvInstance.current = instance;
            setIsInitialized(true);
          })
          .catch((error) => {
            console.error("Error initializing WebViewer:", error);
          });
      }
    };

    void initWebViewer();
  }, [contract, isInitialized, theme]);

Thank you.

Hi there,

Can you share a video of what you mean by modifying the signature fields(widget)? How is a user able to interact with the signature field after signing?

Here is a video of where I create a signature field widget on document load using this sample and then sign the field. From then on, the only thing I can interact with is the signature annotation that I drew:
65630.mov

If you wish to set the field as readOnly, you can do the following:

    // find the associated signature widget
    const associatedSignatureWidget = annotationManager.getAnnotationsList()[0];
    associatedSignatureWidget.fieldFlags.set('ReadOnly', true);

However this will also prevent the user from being able to sign on the signature field.

Best regards,
Kevin Kim