Copy link to clipboard
Copied
Hello Guys i tried my level best to add my code to add in tool bar. I cant succeed. I am beginner so i unable to grasp some complicated technical terms. Anyone please add the folder scripting code to run my existing code. Below code is i am using in Acrobat 11 but now i want to do it in acrobat 9 tool bar. Please help.
// pages on which that string is found to a new file.
var pageArray = [];
var stringToSearchFor = "SHEET";
for (var p = 0; p < this.numPages; p++) {
// iterate over all words
for (var n = 0; n < this.getPageNumWords(p); n++) {
if (this.getPageNthWord(p, n) == stringToSearchFor) {
pageArray.push(p);
break;
}
}
}
if (pageArray.length > 0) {
// extract all pages that contain the string into a new document
var d = app.newDoc();
// this will add a blank page - we need to remove that once we are done
for (var n = 0; n < pageArray.length; n++) {
d.insertPages( {
nPage: d.numPages-1,
cPath: this.path,
nStart: pageArray
, nEnd: pageArray
, } );
}
// remove the first page
d.deletePages(0);
var annots=d.getAnnots();
for (i in annots) annots.destroy();
// Save the new document:
var myDocPath = this.path;
var aPathComps = myDocPath.split("/");
var myFilename = aPathComps[aPathComps.length-2]; // Last element
d.saveAs("/c/QC Tool/Art Pages/"+ myFilename+".xlsx", "com.adobe.acrobat.xlsx");
d.closeDoc(true);
}
You put your code in a function and then call that function using the cExec method of addToolButton, like this:
app.addToolButton({ cName: "MyScript1", cLabel: "Extract SHEET Pages", cTooltext: "Extract SHEET Pages",
cExec: "extractSheetPages()", cEnable: "event.rc = (event.target != null);"});
function extractSheetPages() {
// put the rest of your code here
}
Copy link to clipboard
Copied
Hello try check the link below
https://drive.google.com/file/d/0B9W0v6zccItxMzJTa3UzRUhnWUl6VnFvTUtwbkJjUlgtR0o0/view?usp=drivesdk
Copy link to clipboard
Copied
This is not a public link.
Copy link to clipboard
Copied
Try this Test.txt - Google Drive
Copy link to clipboard
Copied
I downloaded the file, renamed it to "Test.js", placed it in the JavaScripts folder and it worked just fine.
Copy link to clipboard
Copied
What is this error
GeneralError: Operation failed.
App.addToolButton:6:Folder-Level:User:test.js
The name for the toolbutton must be unique
NotAllowedError: Security settings prevent access to this property or method.
App.newDoc:9:App MyScript1:Exec
Copy link to clipboard
Copied
The first one means you have tried to add multiple tool-buttons with the same cName value.
The second one means you're trying to use a function from a normal context, while it requires a privileged one.
Copy link to clipboard
Copied
First error solved. Second one how to solve?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hello Try, Since it shows error for newdoc i added privileged code, but now it is showing error for trusted function.
NotAllowedError: Security settings prevent access to this property or method.
App.trustedFunction:28:App MyScript1:Exec
myTrustedNewDoc = app.trustedFunction( function (nPage, cPath, nStart, nEnd)
{
app.beginPriv();
var myTrustedRetn = app.newDoc();
app.endPriv();
return myTrustedRetn;
});
// extract all pages that contain the string into a new document
var d = app.newDoc();
// this will add a blank page - we need to remove that once we are done
for (var n = 0; n < pageArray.length; n++) {
d.insertPages( {
nPage: d.numPages-1,
cPath: this.path,
nStart: pageArray
, nEnd: pageArray
, } );
}
Copy link to clipboard
Copied
Convert the whole function extractSheetPages in a trusted function.
Copy link to clipboard
Copied
You created a trusted function but you're not using it... Instead of this:
var d = app.newDoc();
Use:
var d = myTrustedNewDoc();
And remove the input parameters for it. You're not using them, anyway.
Copy link to clipboard
Copied
Hello Try i am giving up. i cant make it happen. Could you please add those few line of codes in my codes.
Copy link to clipboard
Copied
If you'd like me to write your code for you you can contact me at try6767 at gmail.com to discuss it further, including the price.
Copy link to clipboard
Copied
Hello Try, I finally made it. Thanks for your guidance and support.
Copy link to clipboard
Copied
Do you use addToolButton in another JavaScript file?
Copy link to clipboard
Copied
try67 wrote
I take it back, you're correct. That worked. However, it seems like a real hassle when one can simply use the pre-existing app folder...
This is possible when you can create files in this folder.
Copy link to clipboard
Copied
Bernd is correct, this error shows up when you don't have a user level folder. Are you sure you are creating it in the correct location? Starting with Acrobat 10, you need to add the "Privileged" folder to the path.
Copy link to clipboard
Copied
Hello Try, I did exactly what you instructed. I got the Toolbar but the code is not running.
Copy link to clipboard
Copied
Ok Try, thank you very much.