These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

I need to saveAs from batch file

HSnyder
Registered: Nov 25 2008
Posts: 9

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");

}

My Product Information:
Acrobat Pro 9.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Try to define your report as global variable...

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

HSnyder
Registered: Nov 25 2008
Posts: 9
Try67 Thankyou for your pointer on the global.

This is my current status (unable to saveAs .doc)

I reread the many sections that apply in the adobe 8 manuals
js_api_reference acrobat 8.pdf
AcroJSGuide adobe 8.pdf
batch_sequences adobe 8.pdf

based on that I have done the following

global. Was added to the doc

I moved the JS with the trusted functions from the user to app location (api page 146 note)
the trusted function (api page 143) now calls a trustPropagatorFunction (api page 146)

I tried to keep the extention matching the desired output type (api page 333)

I think my path should be safe
/D/My Documents/2009 Acrobat Javascript/documents/Log Search Results.doc

But am unsure what “a path is also subject to other unspecified tests” might require (JavaScript for Acrobat API reverence page 31)
My computer has the system on drive C, the Data (My Documents) on drive D and the temp & page files on drive E, which is not the simplest configuration.So one question is if my output path might have a problem?

I started with Acrobat JavaScript a few days ago under the false assumption that there was backward compatibility.
I could not find/get to any information on JavaScript/batch files directly from the Acrobat 9 help and used google to fine Acrobat 8 manuals, So.

A second question is I found Acrobat 8 manuals in pdf on line, where are the Acrobat 9 pdf version of the manuals so I can search for answers?

I am still stuck with no idea what to consider

The SaveAs pdf format works
The SaveAs doc format does not

Try 67 thanks for your response, As for your question I got the batch file begin/process files/end Job idea from a document batch_sequences adobe 8.pdf and the number of files/end does not have a very clean option to end on a unknown number of files. For me I can hardwire in the number of files as they are always the same.
http://www.adobe.com/devnet/acrobat/pdfs/batch_sequences.pdf

John



Console output:
Begin Job Code
Processing File #1
Processing File #2
try to close doc1
Exception in line 23 of function anonymous, script Folder-Level:App:TrustFNsaveAs 09 0328.js

Break location
docvalue.saveAs({cPath: saveFilename, cConvID: "com.adobe.Acrobat.doc"}); // line 23 of errorClose in pdf format creates a file called Log Search Results.pdf:

Data extracted from: /D/My Documents/2009 Acrobat Javascript/documents/Log Search Results.pdf
document number:1
document number:2




/* JavaScript saveAs test */

if ( typeof global.counter == "undefined" ) // Beging 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);
}



if ( global.counter == 2 ) // End Job processing
{
global.docRep = global.ReportDoc.open("Log Search Results.doc"); // open report & save (tried .doc, "" and .pdf
global.docRep.info.Title = "Log Search Result" ;
global.docRep.info.Subject = "Summary of text around search result of "+ global.reSearch;

console.println("try to close doc1");
// this is a not working attempt to get privlage to saveAs
FNsaveAsdoc(global.docRep,"/D/My Documents/2009 Acrobat Javascript/documents/Log Search Results.doc");
// this exit works but is not the right format
// FNsaveAs(global.docRep,"/D/My Documents/2009 Acrobat Javascript/documents/Log Search Results.pdf");

// this exit works but requires manual input
// global.docRep.closeDoc(false);
// this is a not working attempt to use saveAs
// global.docRep.saveAs({
// cPath: "/D/My Documents/2009 Acrobat Javascript/documents/Log Search Results.rtf",
// cConvID: "com.adobe.Acrobat.rtf",
// bPromptToOverwrite: true,
// });

console.println("good dog - doc saved");
}
// end of batch file



JavaScript in folder: C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts

/*FNsaveAs, FNsaveAsdoc*/
// should allow priviledged calls to saveAs method
// located at C:\Documents and Settings\John\Application Data\Adobe\Acrobat\9.0\JavaScripts

TrustFNsaveAs = app.trustPropagatorFunction(function(docvalue,saveFilename)
{
app.beginPriv();
docvalue.saveAs({cPath: saveFilename});
app.endPriv();
})
FNsaveAs = app.trustedFunction(function(docvalue,saveFilename)
{
// privileged and/or non-privileged code above
app.beginPriv();
TrustFNsaveAs(docvalue,saveFilename);
app.endPriv();
// privileged and/or non-privileged code below
});TrustFNsaveAsdoc = app.trustPropagatorFunction(function(docvalue,saveFilename)
{
app.beginPriv();
docvalue.saveAs({cPath: saveFilename, cConvID: "com.adobe.Acrobat.doc"}); // line 23 of error
app.endPriv();
})
FNsaveAsdoc = app.trustedFunction(function(docvalue,saveFilename)
{
// privileged and/or non-privileged code above
app.beginPriv();
TrustFNsaveAsdoc(docvalue,saveFilename);
app.endPriv();
// privileged and/or non-privileged code below
});
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Hi HSnyder, thanks for the link to the batch sequences PDF. I guess I missed it before and I learned some new things from it. Cheers!

About your problem... it is very odd.
Can you save the report from a folder-level script? I use this method when I process an unknown amount of files and it works fine. After the batch is finished you close the batch window and manually run a folder-level script that uses the global variable you used (global.ReportDoc in this case) for further processing and saving.
It requires another manual step, but you only do it once per batch so it's not that bad.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

HSnyder
Registered: Nov 25 2008
Posts: 9
Working with Acrobat JavaScript Day 7 my simple task has become more complex.

Using "Report writeText" results in what appears to be missing text below the bottom of the first page that can not be seen, with the second page starting on with data from the next batch file proccessed.

I now note that Report methods are deprecated.

What is the common replacement to collect information from the text in an acrobat.pdf and output a text or doc type file?

I there an example useage of the replacement?

John
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Which version of Acrobat are you using? If 9 then there's a bug in the Report object.
You need to keep a counter on the number of lines printed and create a new page when you arrive to the end.
I've also noticed several other bugs in it, such as punctuation marks that should be at the end of a line being moved to the beginning of it... It seems quite broken, and I'm afraid it doesn't look like Adobe are going to fix it.
You can always create a simple text file and then import that into Acrobat.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com