That's not a good way of creating new bookmarks using a script.
Use the createChild or insertChild method of the Bookmark object, instead.
Thank you for your response.
But I don't want to display this.pageNum=I,2,3, etc in properties page. Any solutions is there? I need to send this to client
No, there's no solution within Acrobat to this issue, unless you create the bookmarks using a plugin.
I've created many tools that use the "NewBookmark" menu item to create bookmarks. It is the only way from JS to create bookmarks with destinations. But it is tricky because of timing issues. The bookmark is not created synchronously when "app.execMenuItem" is called. The menu item execution happens asynchronously. So the newly created menu item may not be available to JS code for an unknown amount of time. So it's best not to look for then new item right after creating it. The technique described below handles this issue by creating and manipulating the bookmarks in different loops. Not perfect but it usually works.
The code should work as follows:
1. Loop on array to create a flat set of unnamed bookmarks
this.pageNum = BKData[i];
2. Loop on bookmarks to set names
var bkMarks = this.bookmarkRoot.children;
bkMarks[i].name = BKData[i];
The "NewBookmark" menu item creates the new bookmark at the bookmark with the current focus. The assumption in this code is that there are no bookmarks initially, so the new bookmarks are created from the top in order in which they appear in the "BKData" array. And they are the only bookmarks in the document.
You can make this much fancier by putting hierarchy data, such as a level number, into the "BKData", Then adding a 3rd loop to sort the bookmarks into the correct hierarchy.
Yes, I actually thought about it and realized after posting that it's probably possible to do it by creating the bookmark using NewBookmark and then renaming and moving them around to create a hierarchy... It's sounds like a bit of a mess to write such a code, though.
.. It's sounds like a bit of a mess to write such a code, though.
Compared to what? writing a plug-in? If you can get away with a funky JS solution, then it is a better solution than creating a plug-in for the simple reason that it's fast, easy, and will work across platforms, and even in many 3rd party tools (except when menu items are used). That is not to say that I don't create a lot of single purpose plug-ins for filling in the holes in the JS model. But you have to be very careful for exactly the same reasons I've mentioned above, i.e. Plug-ins activated from JS operate asynchronously.
Thank you for your answers.
I got it.
I have created bookmark and inserted it in the appropriate place.