• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

JavaScript SaveAs with renaming filename

Community Beginner ,
Jan 27, 2024 Jan 27, 2024

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

TOPICS
JavaScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 27, 2024 Jan 27, 2024

Copy link to clipboard

Copied

This code does not work:

 

josuam70602286_0-1706398641902.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2024 Jan 27, 2024

Copy link to clipboard

Copied

Where do you use the function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 28, 2024 Jan 28, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2024 Jan 27, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 28, 2024 Jan 28, 2024

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2024 Jan 28, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2024 Jan 28, 2024

Copy link to clipboard

Copied

The saveAs function itself also needs to run from a trusted function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 28, 2024 Jan 28, 2024

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

 

josuam70602286_0-1706470920170.jpeg

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2024 Jan 28, 2024

Copy link to clipboard

Copied

 

You must create the function in a folder-level script file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2024 Jan 28, 2024

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 28, 2024 Jan 28, 2024

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? 

 

josuam70602286_0-1706480808094.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2024 Jan 28, 2024

Copy link to clipboard

Copied

Call the function from the field where you want to use it (like a Button field).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

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... 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

You can try the function in the Javascript console.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

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?

 

josuam70602286_0-1706646705357.png

 

 

 

 

josuam70602286_1-1706646705358.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2024 Jan 30, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

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

josuam70602286_0-1706650700192.jpeg

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

I meant the value of the newPath variable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

I change to global in console to show you the problem.

newpath there is the error?

 

josuam70602286_0-1706652579198.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2024 Jan 30, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

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?

 

josuam70602286_0-1706654880686.png

 

josuam70602286_1-1706654880687.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2024 Jan 30, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

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?

 

josuam70602286_0-1706655967711.png

 

josuam70602286_1-1706656117165.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines