Copy link to clipboard
Copied
Dear Community,
I'm new with JS and Acrobat. I'm looking for a small Code for following Task:
I have an open pdf file and now I need a button to do the following:
Only save the open file in the same directory, but with filename = oldfilename_username.pdf so I can
work with this new file. The old file should be closed. I think I need identity.loginname for username.
Is the best was use an Action with JavaScript Code?
Do you have some Code for me?
Best Regards
Josh
Copy link to clipboard
Copied
This code does not work:
Copy link to clipboard
Copied
Where do you use the function?
Copy link to clipboard
Copied
Hi Bernd,
I have an Action with JavaScript you see in my screen. Perhaps I need something like
app.TrustedFunction() to run successfully the code?
Perhaps you can help me.
BR
Josh
Copy link to clipboard
Copied
Run the script from trusted function.
identity.loginName = The login name as registered by the operating system.
identity.name = The user name that the user entered in the Identity preferences panel.
Copy link to clipboard
Copied
Hi Nesa,
thank you for answer. Ok I understand difference between loginName and name.
But how can I run my script from trusted function? Perhaps you can help me with example.
BR
Josh
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The saveAs function itself also needs to run from a trusted function.
Copy link to clipboard
Copied
Hi Nesa,
I try this, but it doesn't work. I make something wrong.
Perhaps you can help me? My target is a userdefined Button in menu to run the script. Otherwise
an Action with possibility to run script.
BR
Josh
Copy link to clipboard
Copied
You must create the function in a folder-level script file.
Copy link to clipboard
Copied
Here is the link on how to install folder level script: https://www.pdfscripting.com/public/Installing_Automation_Tools.cfm
Copy link to clipboard
Copied
Hi Bernd, hi Nesa,
I put this new directories and put my function in MyDocSave.js
Is this and the function correct?
But now what's the next step to get running the code? How do I have to call MyDocSave.js from
pdf document?
Copy link to clipboard
Copied
Call the function from the field where you want to use it (like a Button field).
Copy link to clipboard
Copied
Hi Nesa, hi Bernd,
the function is correct? Is there a possibility to run this function from Button in menu or about Action?
BR
Josh
Copy link to clipboard
Copied
You can run it from a menu if you use 'app.addMenuItem' or custom tool button using 'app.addToolButton', this is documented in JavaScript APIs https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html?highlight=addme...
Copy link to clipboard
Copied
You can try the function in the Javascript console.
Copy link to clipboard
Copied
Hi Bernd,
I try to run function in console, but it doesn't work.
Here you see my js file with funtion and console running with mistakes.
What can I do?
Copy link to clipboard
Copied
There's a problem with the path you're using. Print it to the console so you could examine it for issues.
Copy link to clipboard
Copied
Here the path of js file with function and the path of the pdf I want save as with loginname.
What's wrong?
BR
Josh
Copy link to clipboard
Copied
I meant the value of the newPath variable.
Copy link to clipboard
Copied
I change to global in console to show you the problem.
newpath there is the error?
Copy link to clipboard
Copied
That doesn't seem right. It's the same as the original path. Just add a console.println command to the code before the saveAs command. You don't need a global variable.
Copy link to clipboard
Copied
I found the error. Now newpath is working correct, but if I run Trusted_MyDocSave(this); I got errors.
Is something wrong with my function in js file?
Copy link to clipboard
Copied
It's very hard to help you when you keep changing things and not giving the full details of the changes you made each time. Also, these screenshots are not helpful. If you want to share code do so as plain-text or as a file attachment. Your function seemed to have worked before so if it doesn't exist now it means you've broken it in some way.
Copy link to clipboard
Copied
The function don't work before.
Here is the small js file Code. In first step I want to run on console, then about Button.
But on console you see error. There is somethin wrong?