Expand my Community achievements bar.

Need to specify default filename for SaveAs

Avatar

Former Community Member
I am using the command app.execMenuItem("SaveAs"); in the click event of a button. Is there anyway that I can specify a default filename for the user? I do want the user to get the Save As window and the ability to change the name if possible.



The form is generated by the RenderForm Java script, and the name being generated as a default for the SaveAs window is RenderForm.pdf



Thanks,

Velvet
9 Replies

Avatar

Former Community Member
See my post here on the content-disposition HTTP header:
Chris Trubiani, "Name of rendered PDF from servlet." #1, 16 Feb 2006 2:54 pm



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Chris, I think you missed this one.

I think you want to change the name when calling app.SaveAs via javascript from the client not on the server. Since app.executeMenuItem("saveAs") will not take any parameters to suggest a file name. I think you will have to use doc.saveAs which will allow the name to be specified. This would require a trustedFunction which may or will not work unless you have known users. You will also need to prompt for the file name before making the call.



Here is some untested code to get you started...



You will need to create a trustedFunction (see AcroJS.pdf for details) ..



saveFunc = app.trustedFunction(function (filename) {

app.beginPriv();

try {

event.target.saveAs({cPath: filename});

} catch (err) {

app.alert("Error: " + err);

}

app.endPriv();

});



Code for your event...



var suggestedName = "MyPDFName.pdf";

// Note This will only work if you know where they will be saving it

var cPathToSaveTo = "/c/temp/";



var cResponse = app.response({

cQuestion: "What name would you like to use for this PDF?",

cTitle: "File Name",

cDefault: suggestedName,

cLabel: "File Name:" })

if(cResponse != null)

saveFunc(cPathToSaveTo + cResponse );



Hope this helps.



Rich Ruiz

Novanis

Avatar

Former Community Member
Yep, all you say is true Rich. What I was referring to was using the content-disposition header to specify the filename of the PDF rendered by Forms. Since save as will use the current filename automatically in the save as dialog the name specified will be there as default, then the user could choose where to save it and whether to rename it.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thanks for the input, I do not have known users. If I could change the name in the HTTP header I think that would meet the requirement. I want the user to have the option of changing the name, and I do not know where they will same the file.



I did a google search for HTTP Header content-disposition and did not find anything useful. Anything more you have on this would be greatly appreciated.



Thanks,

Velvet

Avatar

Former Community Member
http://www.faqs.org/rfcs/rfc1806.html

http://www.faqs.org/rfcs/rfc2183.html



In particular you are interested in the filename parameter. In Java you'd use a line of code like:



response.setHeader("Content-disposition", "inline;filename=someName.pdf");



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thanks, but instead of hardcoding a file name can this be dynamic? My renderForm script handles multiple forms, and I would like to give the requested form as the default saveAs name.



Thanks,

Velvet

Avatar

Former Community Member
Sure, just use a variable instead of hardcoding it:



response.setHeader("Content-disposition", "inline;filename=" + nameInAVar);



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Sorry this took so long to test, but when I added the code to my response there was no change to the header. Below is what I added.



//write the new PDF to the browser

resp.setContentType(IOC.getContentType());

resp.setContentLength(finalPDF.length);

// Added following line to change response header from render form to filename

// so that when save as in invoked the default will be the fileName

resp.setHeader("Content-disposition", "inline;filename=" + "TPAStopLoss Form");

resp.getOutputStream().write(finalPDF);



thanks,

Velvet

Avatar

Former Community Member
response.setHeader("Content-disposition", "inline;filename=" + nameInAVar);



I have seen the solution on many forums to set the Content-disposition header with inline and filename, however this does NOT work for reader 5.x, 6.x, or 7.x. I've tried in both IE and Firefox with no luck.



Is there a timeframe where reader will be corrected to use the Content-disposition header? Is it the browser's fault for not passing that information along?



Thanks,

Peter