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

Save As Function

Community Beginner ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

My goal is to create an automated Save As function (utilizing a button or something on the document) that will save the document to the same location as the original file, as well as rename the file by reading certain fields on the document.

An example of what I would want the save file to look like would be:

LastName.FirstName.IDnumber.ReasonForVisit

The last name, first name, and ID number are text fields that would have those obvious details entered and the reason for visit would be one (or multiple) of various check boxes that would have an export value. I wanted to know if it is possible to do something like this, as well as putting a "." between each of the details to make it easier for sorting/searching purposes.

I know this would include a folder level script, I also wanted to know if there is a file level script needed or if the call script would only be attached to the button created. I would also like it to prompt the user if there is already a file with the same name (to overwrite or not)

I know how to find different paths, etc, I am just a little unsure of how to save to the same path that the document is currently in (as some users may use different locations to save/store these files), I also know that the field names would be used in the script, etc, I just don't know how best to structure the script and so on.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

707

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

correct answers 1 Correct answer

Community Expert , Feb 25, 2019 Feb 25, 2019

Yes, it's exactly the same for a check-box as for a text field. The only difference is that the default value of a check-box (when it's not ticked) is always "Off".

Votes

Translate

Translate
Community Expert ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

- Yes, you can add a period between the values, simply by using the + operator between them and putting the period character in quotes.

- You don't need a doc-level script, if that's what you're asking. The script can be located entirely under the button, which calls the folder-level script with the correct parameters (such as the desired file name and path).

- Finding out if a file with the same name already exists is not simple, nor always possible. To do it you would need to attempt to open the file with that name, and then check the return value. If it's not null then you know that a file with that name exists, but for that to happen the file must be disclosed. Alternatively, you can specify the bPromptToOverwrite parameter as true, and then the user will be prompted if a file with that path exists.

- To save to the same path of the original document you can use something like this:

var newFileName = "Whatever.pdf";

var newFilePath = this.path.replace(this.documentFileName, newFileName);

this.saveAs(newFilePath);

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 ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

This is awesome help. Thank you. The prompt to overwrite is what I was looking for. How would I get the save name to call from the various fields? Is it possible to use an export value for a checked check box as part of the file name too? All of these parameters would go into the folder level script right? How would I get the button to call the script?

I've never dealt with trusted functions.

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 ,
Feb 25, 2019 Feb 25, 2019

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 Beginner ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

Thank you for the links. I had previously read into two of the three, I understand the types of functions I should be using. My primary concern was how to point it at the specific field within the document (last name/first name), I know from reading an article by Thom Parker that it can be done, but I can't find the article currently. And I also don't know how successful using the check boxes would be for contributing to the file name.

Another question I would have is: Is it possible to have two different save as scripts, each that may interact with a different file that has different field requirements. I imagine its probably as simple as creating two separate .js files and then pointing each save button on their respective PDF to the script that it needs for that particular 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 ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

To get the value of a field use this command:

this.getField("first name").valueAsString

If you want to add multiple values to a single string, use this:

this.getField("first name").valueAsString + "." + this.getField("last name").valueAsString

I don't recommend creating a .js file for each file. In the .js file you should only have a generic function that saves the file based on the input parameters it receives. Then in the code in the file itself you put together the file name (and path) you want to use and just pass them on to that generic 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 ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

This is exactly what I was trying to figure out. Thank you. So is it possible then to use the getfield function to use the export value of a checkbox to fill in part of the file name? The various checkboxes would be used to indicate the reason for the person's visit, the save file name would preferably reflect it as well.

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 ,
Feb 25, 2019 Feb 25, 2019

Copy link to clipboard

Copied

LATEST

Yes, it's exactly the same for a check-box as for a text field. The only difference is that the default value of a check-box (when it's not ticked) is always "Off".

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