Uncaught TypeError: object is not iterable, when loading annotation

Which product are you using?
Express Plus

PDF.js Express Version
8.7

Detailed description of issue
I’m getting an error in the console, but things seem to work fine…

I’m loading an annotations with this code:

const [annotation] = annotationManager.importAnnotCommand(annotationData.xfdf);
annotation.authorId = annotationData.authorId;
annotationManager.redrawAnnotation(annotation);
instance.fireEvent('updateAnnotationPermission', [annotation]);

It seems to be working just fine - the annotations are loaded into the PDF, and appear correctly.

However, in the developer console, I see this message:
Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))

Pointing to this line:
const [annotation] = annotationManager.importAnnotCommand(annotationData.xfdf);

I grabbed this code from this guide #7.3, Client Setup for Collaborating with PDF.js Express | Documentation

What is causing this console error, even though it doesn’t seem like anything is broken?

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Hello elliot,

I suggest using the updated syntax:

const [annotation] = await annotationManager.importAnnotations(annotationData.xfdf);
annotation.authorId = annotationData.authorId;
await annotationManager.redrawAnnotation(annotation);
instance.fireEvent('updateAnnotationPermission', [annotation]);

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here

Hi @tgordon ,

Thanks for getting back to me.

Even though I’m definitely on 8.7:

The code you sent doesn’t work for me, the annotations don’t load, and it fails when I try to set authorId - saying annotation is undefined.

If I add the await statements to my original code, it does get ride of the “object is not iterable” message, but then I get this message:

I should say, I’m loading a custom config, I’m not sure if that makes a difference.

Hi Elliot,

fireEvent is not an available API, however trigger is which would be used like

instance.Core.annotationManager.trigger('updateAnnotationPermission');

The await is necessary as the importAnnotations function is async

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron


Share how you are using PDF.js Express in your organization you could win a $500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free. Learn more here