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

Saving the Adobe Form automatically on HardDrive

ashagraw
Registered: Jan 13 2009
Posts: 23

Hi,

I am designing an interactive adobe form, on which I have a field for selecting a file from users hard drive.
My requirement is to save the adobe form on user computer automatically.

Currently, I am writing the below code in the click event of BROWSE button. In order to save the form automatically I am placing a javascript file on C:\Program Files\Adobe\Reader 9.0\Reader\Javascripts with the below code.

Code in JS file:
*************************************************************
trustedSaveAs = app.trustedFunction( function (pFileName)
{
app.beginPriv();
try {
var myDoc = event.target;
myDoc.saveAs(pFileName);
} catch (e) {}
app.endPriv();
});
*************************************************************

Code in Click event of BROWSE button:
*************************************************************
var sFile = "File1";
event.target.importDataObject(sFile);

var oFile;
oFile = event.target.getDataObject(sFile);
this.parent.parent.Sub_Form_Fields_Mass.ZPATH1.rawValue = oFile.path;

trustedSaveAs("/c/Program Files/Mass.pdf");
*************************************************************

This trustedSaveAs function is basically responsible to save the form on C drive.

I have two limitations in this:

1. I am creating the JS file automatically if it is not present on the user's machine. Since this file needs to be placed in JavaScript folder only, I am not able to determine its path at run time because it could vary on user's machine depending on the Adobe Reader's version installed on the machine. (e.g. Reader 8.0, Reader 9.0 and so on...). Please help me if I could place this file somewhere else, or how determine the Adobe Reader's version installed on user's machine.

2. If I try to save the form on C:/ (on the root node), it does not happen. I always have to save this form in some folder inside the C drive. I am not able to create a folder at run time where I can store this form. Currently, I am saving it in the Program Files folder assuming that this is available on all the computers running on Windows. Please help me with providing me the solution to save the form automatically.

First problem is very critical, if it is not solved there i no point in going ahead. Request you all to please give it a chance and provide me with the right catch.

Thanks in Advance,
Ashish

My Product Information:
Acrobat Standard 9.0, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi ashagraw,

Do you have access to the computers of all the intended users of your form? I ask because you cannot automatically install a JS trusted function onto someone elses computer automatically- that is a security restriction.


Hope this helps,

Dimitri
WindJack Solututions
www.windjack.com
www.pdfscripting.com
ashagraw
Registered: Jan 13 2009
Posts: 23
Hi,

No, I dont have access to the computers of all the members. i have developed this application in SAP ABAP where I have set the authorization to a particular group. Only authorized people can run this program, this program will automatically create this JS file on their PC if it is un availalble there.
Can you please help me with raised post?

Thanks,
Ashish
ashagraw
Registered: Jan 13 2009
Posts: 23
Hi Thom,

I am looking forward to hear something from you.

Thanks,
Ashish
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I don't know what the capabilities of an SP ABAP program are, but I assume that if you are able to write to the users hard drive then you are also able to read the user's Registry.

To find the location of the Reader JavaScript folder it's not good enough to know the version of Reader, since reader could be installed anywhere. The best way to get the install location is to look at this location in the Registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe\Path

This will give you the exact location of the Reader Install, and therefore the JavaScript folder path.

Once you install the folder level JavaScript you'll be able to do all kinds of stuff that cannot normally be done from inside a document script. For example, there's a function called "app.getPath" that returns all kinds of Acrobat related directory paths. So you can find a path for saving the file.

BTW: the root of a drive is protected. You cannot, under any circumstances save something from JavaScript to an un-Safe path. What a Safe Path is, is defined in the Acrobat JavaScript reference.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ashagraw
Registered: Jan 13 2009
Posts: 23
Hi Thom,

It was excellent, I have somehow achieved the result. Since I am into ABAP, not very much handy with JavaScript.
Below is the code (I will explain you):

var path;
path = this.parent.parent.Sub_Form_Fields_Mass.ZPATH.rawValue;

trustedSaveAs(path);

Field ZPATH containes the path which i determined using the Registry (C:\Program Files\Adobe...) and here I am passing its rawValue to variable PATH.

I want to use the value of this variable PATH with function "trustedSaveAs".
Previously I was using the function as below:

trustedSaveAs("C\Program Files\Mass.pdf");

It was working fine, but I dont want to put a hardcoded path here, that's why I want to use the path which I determined using the history (The path which is now in variable PATH).

Please give me the syntax to use the value of PATH variable with this function. I am trying to use it as below but its not working and throwing me an error.

trustedSaveAs(path);

I know you can provide me with the best solution!!!

Thanks a lot,
Ashish.
ashagraw
Registered: Jan 13 2009
Posts: 23
Hi Thom,

I have cracked it!!!
Thanks for your inputs and suggestions.

Thanks,
Ashish
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Excellent news, you're very close.

Naming you used above is a bit confusing, by capatalizing "PATH" it seems that you want to use an environment variable. But your variable is all lower case, "path".

Anyway, the reason you get an error is because "path" is in the wrong format. It needs to be in Acrobats device independant path format. Look this up in the Acrobat JavaScript reference, you'll need to replace both the back slashes and the colon.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script