React-Native: How to tell which signature file to use?

I’m working on a proof-of-concept for signing documents within a ReactNative app and I hit a snag that I’m hoping for some help with.

I have things wired up to the point where the PDF is loaded, the annotations are displayed and the user can provide a signature. Where I’m stuck at right now, is trying to figure out which .pdf file containing the signatures to use for the field.

The code below shows a slimmed down version of what I’m currently testing.

import { AnnotOptions, DocumentView, RNPdftron } from "@pdftron/react-native-pdf";
import React, { Component } from "react";

const licenseKey = "<redacted>";
const path = "<redacted>";

type Props = {};
type FormFieldValueChangedEvent = { fields: Array<AnnotOptions.Field> };

export default class App extends Component<Props> {
  static documentViewer: DocumentView | null;

  constructor(props: Props) {
    super(props);

    RNPdftron.initialize(licenseKey);
    RNPdftron.enableJavaScript(true);
  }

  render() {
    return (
      <DocumentView
        document={path}
        ref={(instance) => {
          App.documentViewer = instance;
        }}
        onFormFieldValueChanged={async (event: FormFieldValueChangedEvent) => {
          for (const i of event.fields) {
            if (i.fieldType === "signature") {
              const signatures = await App.documentViewer?.getSavedSignatures();
              if (!signatures) {
                return;
              }

              for (const pdfPath of signatures) {
                console.log("Is this the correct one to use?", pdfPath);
              }
            }
          }
        }}
      />
    );
  }
}

If the user created a new signature, it’s pretty easy to identify which one to use (most recently created), but if there are three signature annotations in a document and they chose to draw new signatures for the first two, but choose an existing one for the third, how will I know which one they chose? Is there a lookup table that I can reference? Is there a better place to handle these events that includes the field name and path to the signature the user chose?

Thanks in advanced,
Ben

Hello ben,

Thank you for contacting forum support,

We have a few questions to clarify your request:

  1. You mentioned if there are three signature ‘annotations’ in the a document, do you mean the signature form field or the signature annotation?
  2. Do you need a UUID or some unique ID to identify the annotation?
  3. Can you clarify what you are trying to accomplish? Is there a reason why you require a signature PDF?

Thank you in advance.

​Best Regards,
Kevin Kim
Developer Support

Hello Kevin,

Thanks for the reply. I’m sorry for the delay. I set this ticket down for a little bit, but I’m returning to it now.

I’ll number my responses to match the numbers in your questions.

  1. I’m sorry about not being specific. I’m using signature annotations
  2. I’m currently using the name value of the signature annotation to identify which annotation was selected
  3. In the app that I’m working with, I want to be able to sync the annotation values with a backend server without sending the whole PDF to be processed. To do that, I’m hoping to find a way to know which signature the user selected. If they’re generating a new one, it’s easy to identify which signature (in the generated PDF file) was created after the user signed. If they choose to reuse an existing signature, but there are multiple signatures to choose from, I’m looking for the best way to know which signature PDF file to reference. Is there an API I can call to see what the last used signature file was?

Thanks,
Ben

Hello Ben,

We suggest this flow:

  1. Having a UUID server-side for each signature, basically associating an ID to a specific signature image.
  2. Then on the annotation you can use setCustomData to apply that UUID and keep track of which signature was applied when a signature is selected.

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron

Hey Tyler,

Thanks for the idea! I’ll give that a try to see if it solves this particular issue.

Ben