How to call a trusted function from acroform - javascript

I have been looking for an example of how to call a trusted function in acroforms and havent found any. I am trying to build a form for my company that will allow users to click a button and automatically have the form save to a folder on our server (eg: //SERVER1/Forms/). I found this code to test with and placed it in C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Javascripts
//SaveAs Function1
var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var dateSigned = String(month) + String(day) + String(year);
var mySaveDoc = app.trustedFunction(function(doc,fileNam­e){
app.beginPriv();
var myPath = "C/test/" + fileName + "Agreement " + dateSigned + ".pdf";
//saveAs is the only privileged code that needs to be enclosed
doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: false});
//doc.close();
app.endPriv();
});
Any help on making this work is greatly appreciated!!

I think the location of the application level script is correct; check whether you have other files in that folder; one of them would be a precompiled one, coming from Adobe.
Now, for calling the trusted function, well…, call it as you would call any other function:
mySaveDoc(this, fileName) ;
and that should do it.
However, there are a few issues I don't like that much in the application-level script:
The dateSigned variable and its bits and pieces will be defined and initialized when the application starts, and then keep their value. In other words, if you keep Reader running all the time, the date will not be updated. To get the current date all the time, you'd have to initialize the dateSigned variable within the function. AND, as you are in Acrobat JavaScript, you can use the util object for assembling the string.
Your script would then look like this:
var mySaveDoc = app.trustedFunction(function(doc, fileName){
app.beginPriv() ;
var dateSigned = util.printd("MMDDYYYY", new Date() ;
var myPath = "/C/test" + filename + "Agreement " + dateSigned + ".pdf" ;
doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: false}) ;
app.endPriv() ;
}) ;
Note that there is als a slash at the beginning of the path (although I may be wrong on that; as I don't have access to a Windows machine, I can not verify it; if someone else would use Acrobat, open any file, and then run this.path() from the Console, then he could confirm the slash (or not)).

Related

Adobe Acrobat Javascript Error: Value is unsupported

I'm trying to troubleshoot an issue with a PDF (Adobe Acrobat) using custom trusted function. It works on my machine (go figure), possibly some permissions issue?
When the user hits a button the PDF it is supposed to save it as a JPEG to a known folder location.
The trusted function exists in the users folder: C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
var CustSaveAsJpeg = app.trustedFunction(
function(d,p,f) //D=Document, p=path, f=filename
{
app.beginPriv();
p= p.replace(/([^/])$/, "$1/");
try{
d.saveAs(p + f, "com.adobe.acrobat.jpeg");
}catch(e){
app.alert("Error During Save:" + e.toString());
}
app.endPriv();
}
);
It is called like so:
var m = this.getField("ID").value;
var d = new Date();
var n = d.getSeconds();
var s = "/nas1/dfs/Shared/Departments/Saves/";
var f = m + "-" + n + ".jpeg";
if(typeof(CustSaveAsJpeg) == "function"){CustSaveAsJpeg(this,s,f);};
When i run it, I'm getting either obsolete function call, or value is unsupported Param: p.
I don't think it is an issue with the folder\file path, it works on my machine
I don't think it is a permissions issue (but it could be); the user can create/delete/modify files in that folder (acrobat executing this function under the local user?)
If it matters, i have adobe acrobat Pro DC, whereas the user has the Acrobat DC (Free version)

how to create input fields for values in Photoshop scripting

I'm working with Photoshop scripting and I have converted action to script which works fine.
I have defined the save as file name with a variables like this:
var path="~/desktop/Images/";
var start ="a";
and the saving path is set like this:
desc1.putPath(cTID('In '), new File(path + start + "001"));
and the next save will be:
desc1.putPath(cTID('In '), new File(path + start + "002"));
how do I make pop up box every time I run the script with the inputs of the path and start values?
ok i found it out. Thought ill put it here so that it might help others.
var Path= Folder.selectDialog("Select folder to save");
var Start =prompt("Layer Name","","Input Layer Name");
desc1.putPath(cTID('In '), new File(Path + "/" + Start + "001"));

javascript can't accept in output rewrite in views

I need to display the node title,node edit and node url.when user hits the node url means its open in popup window so for that i try to rewrite the output of that url field in views.First i create a new js file called popup.js include to via theme.info inside that file i paste the following code
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=1000,height=250,left = 12,top = 259');");
Then i move to output rewrite section add following code
view
But that url not open pop up window.is there any thing i missed.Any one point me my error.
thanks......
Try this in your js file
function popUp(URL) {
var day = new Date();
var id = day.getTime();
window.open(URL);
}
if it doesn't work then try to put the same code in you page.tpl.php file. Also try with chang the name of your callback form popUp() to other name. It may be conflicting with other callback.

Is there a way to automatically detect the excel version from a html file or active x?

I have a workflow process that runs in weird combination of html and excel, this was already done when I came to work here so I'm no able to restart the process, well here is the deal:
After a certain step on the flow, a html file is sent through email, this file contains an active x that will automatically open excel with some given parameters, however even though everything seems to build with parameters the path for excel is hardcoded, we never had an issue with this as everyone was using Excel 2003 and pretty much everyone had the same image so the path was the same, but now some users (top management) will be migrating to office 2010. Therefore I need a way to automatically detect the excel version through the active x so the html file will open the correct excel version.
Any ideas?
Thanks!
EDIT
this is what I use:
<script language="JavaScript">
function LoadVendor()
{
var vendor = document.getElementById("vendor").value;
document.getElementById("vend").innerHTML=vendor;
var BIDnum = document.getElementById("BIDnumber").value;
document.getElementById("BIDnum").innerHTML=BIDnum;
}
function openExcelDocPath()
{
var shell = new ActiveXObject("WScript.Shell");
var excelexe = document.getElementById("excelexe").value;
var excelprg = document.getElementById("excelprg").value;
var vendor = document.getElementById("vendor").value;
document.getElementById("vend").innerHTML=vendor;
shell.run( "\"" + excelexe + "\"" + excelprg , 1, false );
try{objExcel.comaddins("SAS.OIBootStrap.Connect").connect = "False"; }
catch(err)
{ }
}
</script>
I'm not 100% on what your after but you could drop the physical path entirely;
var Excel = new ActiveXObject("excel.application");
Excel.Visible = true;
Excel.Workbooks.Add(); //to keep resident if you want interactivity
//can open something here ...
//or just get the path/version
alert( Excel.version );
alert( Excel.path );
//to kill
//Excel.Quit();
//Excel = null;

WIX: Where and how should my CustomAction create and read a temporary file?

I have a script CustomAction (Yes, I know all about the opinions that say don't use script CustomActions. I have a different opinion.)
I'd like to run a command, and capture the output. I can do this using the WScript.Shell COM object, then invoking shell.Exec(). But, this flashes a visible console window for the executed command.
To avoid that, I understand I can use the shell.Run() call, and specify "hidden" for the window appearance. But .Run() doesn't give me access to the StdOut of the executed process, so that means I'd need to create a temporary file and redirect the exe output to the temp file, then later read that temp file in script.
Some questions:
is this gonna work?
How do I generate a name for the temporary file? In .NET I could use a static method in the System.IO namespace, but I am using script here. I need to insure that the use has RW access, and also that no anti-virus program is going to puke on this.
Better ideas? I am trying very hard to avoid C/C++.
I could avoid all this if there were a way to query websites in IIS7 from script, without resorting to the IIS6 Compatibility pack, without using .NET (Microsoft.Web.Administration.ServerManager), and without execing a process (appcmd list sites).
I already asked a separate question on that topic; any suggestions on that would also be appreciated.
Answering my own question...
yes, this is going to work.
Use the Scripting.FileSystemObject thing within Javascript. There's a GetTempName() method that produces a file name suitable for temporary use, and a GetSpecialFolder() method that gets the location of the temp folder. There's even a BuildPath() method to combine them.
so far I don't have any better ideas.
Here's the code I used:
function GetWebSites_IIS7_B()
{
var ParseOneLine = function(oneLine) {
...regex parsing of output...
};
LogMessage("GetWebSites_IIS7_B() ENTER");
var shell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder);
var tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName());
var windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder);
var appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " list sites";
// use cmd.exe to redirect the output
var rc = shell.Run("%comspec% /c " + appcmd + "> " + tmpFileName, WindowStyle.Hidden, true);
// WindowStyle.Hidden == 0
var ts = fso.OpenTextFile(tmpFileName, OpenMode.ForReading);
var sites = [];
// Read from the file and parse the results.
while (!ts.AtEndOfStream) {
var oneLine = ts.ReadLine();
var line = ParseOneLine(oneLine);
LogMessage(" site: " + line.name);
sites.push(line);
}
ts.Close();
fso.DeleteFile(tmpFileName);
return sites;
}

Categories

Resources