Import freetext annotation Uncaught TypeError: Cannot read property 'index' of undefined

Hello,

when I export a freetext annotation with annotManager.exportAnnotations I have the following xpdf string:

`

<?xml version="1.0" encoding="UTF-8" ?>





Insert text here

Insert text here

0 0 0 rg /Helvetica 32.59492123015469 Tf font: Helvetica 32.59492123015469pt; text-align: left; color: #E44234 `

When I import the saved xpdfstring with annotManager.importAnnotations I have the following error:

CoreControls.js:600 Uncaught TypeError: Cannot read property 'index' of undefined at ba.va.Ov (CoreControls.js:600) ...

Deleting the “apref” tag seems to fix the error.

Can someone tell me what I am doing wrong?

Hi,

Thanks for contacting us regarding WebVewer!

There’s nothing you are doing wrong here.

Can you let me know the WebViewer version you are using? When I try to import your XFDF using annotManager.importAnnotations, I see some warning messages(see the attachment), but I am not able to see the Uncaught TypeError: Cannot read property ‘index’ of undefined error as you mention. Can you provide more detailed steps that I can follow to see this error message?

We will fix the warning messages in the WebViewer.

Best Regards,
Zhijie Zhang
Software Developer
PDFTron Systems Inc.

import-free-text.png

Hi,

thanks for your reply.

I was unable to reproduce the bug and then I disabled my workaround, waiting it to come back.
Today it happened again and I can tell you more: it doesn’t happened with .pdf files but, at least, with .docx files. I also successfully reproduced the bug with a generic .docx file (simple, only text, only one word).

Hi,

Thanks for the information. I’m able to reproduce with a docx file. A PR that contains the fix is being reviewed.
I can provide you with a custom build to try out. Let me know.

Best Regards,
Zhijie Zhang
Software Developer
PDFTron Systems Inc.

In JavaScript almost everything is an object, null and undefined are exceptions. This error occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: Cannot read property of undefined

If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. To avoid getting these types of errors, you need to make sure that the variables you are trying to read do have the correct value. This can be done in various ways. You can do if checks before dealing with objects whose values are bound to change:

if (myVar !== undefined) {
    ...
}

Or

if (typeof(myVar) !== 'undefined') {
    ...
}