Skip to main content
Participant
January 30, 2023
Question

Cannot read properties of undefined (reading 'length')' Error on adding annotation on pdf

  • January 30, 2023
  • 1 reply
  • 2168 views

Hi,

I'm getting the following errors :

'Uncaught TypeError: Cannot read properties of undefined (reading 'length')'

 

Steps to reprodue :

- on the embedded pdf viewer open the pdf and select a portion of text

- click Save

- on mouse hover over the selected text, console prints the above message

 

On further investigating, this is happening when _validateMinLength(propertyName, obj, minLength) in AnnotationValidatoeUtil.js file is trying to valide the minimum lenght of the object.source which is comming as undefined

 

Any suggestion, how to solve this ?

 

This happens when we save the annotations. We are using Adobe Embed API to embed the pdf reader in our application.
Using the SAVE_API, we save the annotations of the pdf to our database.
Inside that we use getAnnotations to fetch the current annotations to be saved(this is where the error is coming)
 

Below is the code:
this.adobeDCView.registerCallback(
      window.AdobeDC.View.Enum.CallbackType.SAVE_API,
      async function (metaData, content, options) {
        console.log("inside register callback")
        try {
          await previewFilePromise.then(adobeViewer => {
            adobeViewer.getAnnotationManager().then(annotationManager => {
              annotationManager.getAnnotations()
                .then(result => {
                  setNewAnnotations(result)
                  console.log('annotation:', result)
                }
                )
                .catch(error => console.log(error));
            });
          });
        } catch (e) {
          console.log(e)
        }
        return new Promise((resolve, reject) => {
          resolve({
            code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
            data: {
              metaData: { fileName: url.slice(42) }
            }
          });
        });
      },
      {
        autoSaveFrequency: 0,
        enableFocusPolling: false,
        showSaveButton: true
      }
    );

 

Documentation we followed : https://developer.adobe.com/document-services/docs/overview/pdf-embed-api/howtos_ui/#save-callback

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 24, 2023

    https://community.adobe.com/t5/acrobat-services-api-discussions/urgent-text-selection-does-not-work/m-p/14256339#M7499

     

    Related issue above ^ 

    OP, Did you ever solve this? Did anybody from Adobe help you on this?