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

Simple code to save pdf using Javascript

kevrizz
Registered: Apr 19 2009
Posts: 2

I have been trying doc.saveAs and this.saveAs to save a pdf that is currently open and for which we have used variables to generate the file name. The code looks like this

var filePath ="/C/Program Files/Adobe/Acrobat 8.0/Acrobat/Javascripts/other Javascripts/";
doc.saveAS(filePath + fileName + ".pdf");

But both options generate error messages. What am I missing here?

Kev
I have since researched this and found it's something to do with privileges but even then my code doesn't work. The code is now

function displaySettings(fileName,stage,industry)
{

var finalsettings = app.alert("Stage: " + stage + "\n" +"Industry: " + industry + "\n"+ "File name: " + fileName + ".pdf\n"+"Do you want to continue?",2,2,"Submit settings");
if(finalsettings==4)
{
app.alert("You said OK");
//var filePath ="/C/Program Files/Adobe/Acrobat 8.0/Acrobat/Javascripts/other Javascripts/";
var filePath ="/C/Test/";
path=filePath

mySaveAs = app.trustPropagatorFunction(function(doc,path)
{
app.beginPriv();
doc.saveAs(path);
app.endPriv();
})
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
{
Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
Privileged and/or non-privileged code below
});

}
else {
app.alert("You said No");
}
}

Any help would be welcome. BTW it's a js file in the applications folder.

Kev

My Product Information:
Acrobat Standard 8.0, Windows
gopi
Registered: May 13 2010
Posts: 4
i am able to view images dynamically in PDF while opening in acrobat viewer through the following manner


/Width 500
/BitsPerComponent 8
/Name /I0
/Height 375
/F

/FS /URL
/F (http://www.nikon.co.in/products/1363/d05571847a/S3000_BL_front34l_lo_i.jpg)

/Subtype /Image
/FFilter /DCTDecode
/Length 0
/Type /XObject
/ColorSpace /DeviceRGB

stream
endstream
endobj


but after saving, images are not embeded perminently.
how can i save images in PDF file after click on saving button.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you read Thom Parker's tutorial [url=http://www.acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript]How to save a PDF with Acrobat JavaScript[/url]

The Acrobat JS API Reference also has the following note about the 'trusted function':

Quote:
[color=#FF0000]Note:[/color] This method is available only during batch, console and application initialization events.
So if you want to use your function in a saved PDF you need to place your function in a location that is processed during the intializaton of Acrobat or Reader. The only locations available to users are the appliction folders used by Acrobat or Reader.

See the following tutorials by Thom Parker:
[url=http://www.acrobatusers.com/tutorials/2006/where_js_goes]So where does JavaScript live in Acrobat?[/url]
[url=http://www.acrobatusers.com/tutorials/file-paths-acrobat-javascript]File paths in Acrobat JavaScript[/url]
[url=http://www.acrobatusers.com/tutorials/2006/folder_level_scripts]Entering Folder Level Scripts[/url]

George Kaiser

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
gopi wrote:
i am able to view images dynamically in PDF while opening in acrobat viewer through the following manner/Width 500
/BitsPerComponent 8
/Name /I0
/Height 375
/F

/FS /URL
/F (http://www.nikon.co.in/products/1363/d05571847a/S3000_BL_front34l_lo_i.jpg)

/Subtype /Image
/FFilter /DCTDecode
/Length 0
/Type /XObject
/ColorSpace /DeviceRGB

stream
endstream
endobj


but after saving, images are not embeded perminently.
how can i save images in PDF file after click on saving button.
This is off topic form the Original Post, OP. Are you trying to start a new post?

Your code looks like PostScirpt code and it should be part of a larger PS file. That PS file should be processed by Acrobat Distiller whic will generate a PDF file.

George Kaiser