For example, I've pasted a test script below that gets all the bookmarks in a pdf, and outputs to the console which row is selected. This is a screen capture of the bookmarks pane itself: Running the script, I get a dialog listing the elements, but if I click on the row "Getting Started with Acrobat JavaScript", I can't find any way to know that row was selected:
Code: Select all
// using hierarchical list
function showBookmarks(doc) {
const bkmDia = {
// pointer for bookmarks
bkm: [],
initialize (dialog) {
dialog.load({ sub1: this.loadHier( this.bkm )});
},
commit () {
},
sub1(dialog) {
const ix = this.getIndex(dialog.store().sub1);
console.println('Selected item: ' + ix);
if (undefined === ix) console.println('Parent item selected, so no row information');
},
// returns the index number of the first item with positive number value
getIndex (elements) {
for (let v of Object.values(elements)) {
let ix;
if ( 'object' === typeof v) {
ix = this.getIndex(v);
} else if ( v > 0 ) {
ix = v-1; //i ; the index is the text of the dropdown
}
if (undefined !== ix) {
return ix;
}
}
},
loadHier ( vals, sel=0) {
let ix = 0;
return getLB( vals );
function getLB (vals) {
const sub = {};
for (let val of vals) {
// need to get unique key
let uk = val.name;
if ( sub[uk] ) {
let i=1;
while (sub[uk + '_' + i]) i++;
uk += '_' + i;
}
if (val.children) {
sub[ uk ] = getLB(val.children);
} else {
sub[ uk ] = (sel === ix ? 1 : -1) * (++ix);
}
}
return sub;
}
},
description: {
name: 'Test of Hierarchical list box',
elements: [
{ type: 'static_text', name: "Doesn't provide any means to know which row is selected if it's a parent", char_width: 30},
{ type:"hier_list_box", item_id: "sub1", char_width: 30, height: 200},
{type: "ok"}
]
}
};
// assign bookmarks
bkmDia.bkm = doc.bookmarkRoot.children;
app.execDialog(bkmDia);
}
showBookmarks(this);