Copy link to clipboard
Copied
I can't for the life of me figure out how to get my custom icon on the addToolButton function. This is running from the following folder:
C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
I am running Acrobat Pro DC. I can get the button to work if I don't have anything about a custom icon in the code. Everything functions fine. But with the code I have below the button doesn't show up and I get an error message:
TypeError: this.getIcon is not a function
3:Folder-Level:App:calloutSchem.js
Any help would be greatly appreciated!
this.getIcon("myIcon", "\\\\arwdfsp.com\\shares\\schematic_tools\\Resources\\Icons\\Leaf-icon.jpg", 0);
var oIcon = util.iconStreamFromIcon(this.getIcon("myIcon"));
app.addToolButton({
cName: "NEW SCRIPT", // A name for your button
oIcon: oIcon,
cExec: "addCalloutLinks();", //Function to Call
cLabel: "Callouts - Schem", //The Text on the Button
cTooltext: "Make me some buttons please" //The Help Text
});
function addCalloutLinks() {
var linksCounter = 0;
var page = this.pageNum;
var numWords = this.getPageNumWords(page);
//var numWords = 1000;
loop1:
for (var i = 0; i < numWords; i++) {
var ckWord = this.getPageNthWord(page, i);
var stringInt = parseInt(ckWord);
loop2:
for (var counter = 0; counter < numWords; counter++) {
if (stringInt == counter) {
//console.println("Adding callout link: " + ckWord);
var r = convertWordQuadsToRect(this, page, i-1);
if ((i+1)<numWords) {
loop3:
for (var j=i+1; j<numWords; j++) {
if (/[\r\n]/.test(this.getPageNthWord(page, j, false))) {
var r2 = convertWordQuadsToRect(this, page, j);
if (r2[2]>r[2])
r[2] = r2[2];
if ((j+1)<numWords) {
var r3 = convertWordQuadsToRect(this, page, j+1);
if (r3[0]==r[0] && ((r[1]-r3[1])<20) && ((r[1]-r3[1])>0)) {
r[3]=r3[3];
loop4:
for (var k=j+1; k<numWords; k++) {
if (/[\r\n]/.test(this.getPageNthWord(page, k, false))) {
var r4 = convertWordQuadsToRect(this, page, k);
if (r4[2]>r[2])
r[2] = r4[2];
break loop4;
}
}
}
}
break loop3;
}
}
}
var f = this.addField(('000' + ckWord).substr(-3) + "_callout", "button", page, r);
f.setAction("MouseUp", "this.callout" + ('000' + ckWord).substr(-3) + "();");
f.userName = "Machine Location";
linksCounter++;
}
}
}
}
function convertWordQuadsToRect(doc, p, i) {
return convertQuadsToRect(doc, p, doc.getPageNthWordQuads(p, i));
}
function convertQuadsToRect(doc, p, q) {
var m = (new Matrix2D).fromRotated(doc,p);
var mInv = m.invert()
var r = mInv.transform(q)
r = r.toString()
r = r.split(",");
return [+r[4], +r[3], +r[2], +r[5]];
}
Copy link to clipboard
Copied
A folder-level script is executed when the application is first opened, before any files are opened, so your reference to "this" in the first line will not work. You can create a temporary file, use it to read the icon and then close it, though.
Copy link to clipboard
Copied
Oh ok. That makes sense. How would I just refer to the open document or make the temp document?