I am attempting to process a number of pdf files, on a local drive, using a batch sequence JavaScript in adobe acrobat pro 9.1, collect data and then output a report in a doc or rtf format. The process is working well until I try to save the results as a rtf or doc file format automatically.
It works “manually” with docRep.closeDoc(false);
I have tried saveAs many ways and don’t seem to be able to output the file.
Question: It seems I need to give my self permission, but how? I can’t seem to get it right. Can anyone see where might I be going wrong and give me a few pointers?
The following test code has a few options commented out but the current try with a JavaScript in the user file gives me the following error.
Exception in line 4 of function anonymous, script Folder-Level:User:TrustFNsaveAs.js
Thanks for any help
John
/* JavaScript saveAs test */
if ( typeof global.counter == "undefined" ) // Beginning Job processing
{
console.println("Begin Job Code");
global.counter = 0; // selected file count
global.ReportDoc = new Report(); // create a new report
global.ReportDoc.writeText("Data extracted from: " + this.path);
}
try // Main Code to processing of each selected files
{
global.counter++ // update selected file count
console.println("Processing File #" + global.counter);
global.ReportDoc.writeText(" "); // output extra blank line
global.ReportDoc.writeText("document number:" + global.counter);
}catch(e) { // try end and catch
app.alert("Processing error: "+e);
}
// tried to use function here directly and in JavaScript file
// placed in C:\Documents and Settings\John\Application Data\Adobe\Acrobat\9.0\JavaScripts\TrustFNsaveAs.js
// TrustFNsaveAs = app.trustPropagatorFunction(function(docvalue,saveFilename)
// {
// app.beginPriv();
// docvalue.saveAs(saveFilename);
// app.endPriv();
// })
if ( global.counter == 2 ) // End Job processing
{
var docRep = global.ReportDoc.open("Log Search Results"); // open report and save as rtf with title
docRep.info.Title = "Log Search Result" ;
docRep.info.Subject = "Summary of text around search result of "+ global.reSearch;
console.println("try to close doc");
// not working attempt to get privilege to saveAs
TrustFNsaveAs(docRep,"/D/My Documents/2009 Acrobat Javascript/documents/Search Results.pdf");
// not working attempt to use saveAs
// docRep.saveAs({
// cPath: "/D/My Documents/2009 Acrobat Javascript/documents/Search Results.rtf",
// cConvID: "com.adobe.Acrobat.rtf",
// bPromptToOverwrite: true,
// });
// this exit works but requires manual input
// docRep.closeDoc(false);
console.println("good dog - doc saved");
}
But I have a question to you: I'm trying to figure out how you used the global.counter variable to find out when the processing is done. Are you only processing 2 files, or am I missing something?
I'm trying to implement something similar to a batch process that will work on an variable number of files and it would be great to know when it's finished. Thanks in advance...
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com