Create Custom Commands in Adobe Acrobat DC Pro

Background

In Acrobat XI and older, when you wanted to run e.g. a custom JavaScript, you had to create a folder level script and find the correct directory to install it, or create a custom Action using the Action Wizard, and then deal with the overhead of running an Action. In Acrobat DC Pro, this got a lot easier with the introduction of “Custom Commands”. A custom command is a user defined command that can be used just like the built-in commands. This means it can e.g. be added to the toolbar, or be used in an Action.

Let’s see how we can create and use custom commands.

Creating Custom Commands

Let’s assume we want to create a custom command that counts bookmarks in a document. Not very creative, but I already have a script for that in one of my old blog posts. This also demonstrates how much easier this is compared to using a JavaScript menu item.

In Acrobat DC, we need to switch to the “Tools” view and then access the “Action Wizard” tool:

Once selected, the Action Wizard allows us to create, manage and execute Actions (just like the Action Wizard in Acrobat X Pro or XI Pro), but is also has functionality to create and manage custom commands:

Just like the name implies, the function “New Custom Command” creates a new custom command. When we execute this function, we get a dialog that lets us select what command we want to use as part of our custom command. This can for example be a preflight profile with specific settings, so that the user does not have to configure the preflight tool manually. When executed, the custom command would configure preflight, select the correct profile and run it. We are trying to execute some JavaScript, we therefore select the “Execute JavaScript” option from the “Customizable Commands” list:

On this dialog, we first select which customizable command we want to run (1), then we provide a name and a tooltip for our custom command (2) (3). The custom command gets configured by clicking on the “Command Options…” button (4). As the last step, we need to make sure that the custom command does not prompt the user for information that we’ve already specified as “Command Options” (5). For some custom commands, it may be necessary to display the Command Options dialog, but for what we are going to do with JavaScript, it would just get in the way of a smooth user experience.

When we click on “Command Options”, we get to the JavaScript editor. Here is the code that we are using to count bookmarks:

Now that we’ve created our own custom command, we can execute it from the Action Wizard user interface:

What else can we do with a custom command?

Using Custom Commands

Let’s add the custom command to our Acrobat toolbar. To do that, we right-click on the gray background of the toolbar. This brings up a menu that allows us to select the “Customize Quick Tools” function:

After we select “Customize Quick Tools”, we can then add commands to the Quick Tools area on the toolbar. The tools we can add are built-in tools (e.g. the “Sticky Notes” tool so that it can be used with just one mouse click), but also our custom commands (and all Actions created with the Action Wizard). We need to expand the “Action Wizard” section to get to the custom commands. Once selected, we click on the “move item up” button on the right side to actually move it to the Quick Tools toolbar. Now we just have to select to “Show Quick Tools” in the right-click menu from before. If the menu item is “Hide Quick Tools”, then the Quick Tools are already shown.

Another option to use a custom command is to create a new group of tools called a Custom Tool. We create such a Custom tool by clicking on the “Create Custom Tool” icon in Acrobat’s “Tools” area:

We can now add our tools either to the toolbar via the “Up Arrow”, or to the “Right Hand Panel” (RHP) via the “Right Arrow” button. The following shows how the toolbar and RHP look for a custom tool:

There you have it, a very easy way to create custom commands that can be added to Acrobat’s user interface.

117 Responses to Create Custom Commands in Adobe Acrobat DC Pro

Hello Karl-Heinz,
I have used the ‘splitpages’ script which you provided successfully with Acrobat XI, but I cannot get it to work with DC Pro. I came across this article and tried to follow the instructions but although I have an action ‘Split Pages’ showing nothing happens.
Any advice you can give will be gratefully received!
Kind regards,
Denny Jansen

Without seeing the code in your custom command, it’s impossible to say what’s wrong. Here is what I would do: Check the JavaScript console for error messages. If you find some, they would point you to the source of the problem. If that does not help, add debug output to your script. You can add a line like this:

console.println(“I reached line 5, variable i is set to ” + i);

This will tell you how far in the script you get, and you can also review the values of variables.

Great article! I’m a web developer that works almost exclusively in javascript and my company recently purchased Acrobat Pro DC and (since I use Photoshop and they assume one Adobe product is identical to all others and that since I work on a computer I must know how to do everything) they figured I’d be the perfect guy to do all our form conversions… which has absolutely nothing to do with web development.

I was hoping to add some automation to the forms and this gets me going in the direction I need to go. Thanks for this simple but ground-breakingly useful article. You just saved me a ton of research time. And, unfortunately, made sure that I will now also become the Acrobat ‘expert’ at my company….. damn it.

I am having issues with simple calculations in a pdf doc. I am totalling two fields. Ex: field1*field2. If I make a mistake and delete the filed 2 amount moves into the total field…..any help would be appreciated. Apologies for the less than correct lingo

I’m creating a PDF fillable form and have a drop down menu with 5 options. Depending on what option is chosen, it needs to select/check (automatically) some predetermine options (between 2-6 options). How do I do this?

This assumes that you have a field called “LastOpened” in your document. That field will get updated every time you open the PDF – but you will have to save the file in order to retain that information. If you close without saving, that date will be lost.

I have PDFs with speaker notes imported as a comment or sticky note. This icon appears in the upper left corner of the PDF (16:9 format in ppt/13.33 x 7.50 inches PDF). Is there a way to move it to the right side of the screen on all pages?

Debra, copying and pasting JavaScript you find online without a good understanding of what the script does is usually not a good idea. In this case, the problem is that you are defining a JavaScript function, but you are then never calling this function. You can fix that in two different ways: You can either call the function, or you can remove the function definition and just use the one-line script that executes the print command (which is what I would do in this case):

Dear Karl Heinz
Your article with custom command is really informative and has helped me a lot. I have the following problem that I would like to automate:
I would like to add new pages to a pdf document, update the pagenrs and get the pages place different on even and odd pages (with the page number on the outside of each page). Since the users are medical students needing a defined order of notes I do not want them to mess with pagination. I would also like the notes to look uniform.

Michael, you can certainly do that, but it would require quite a bit of JavaScript programming (and more than what I can provide in the context of this blog). If you need my professional services, feel free to contact me via email. My email address is on the “About” page (http://khkonsulting.com/about)

STP, this is still available. In Acrobat DC, go to the “Tools” page, and then type “Catalog” into the search field. You will then see “Full text Index with Catalog” as one oof the search results. This is what you had back in Acrobat X.

This assumes that you have a field called “LastOpened” in your document. That field will get updated every time you open the PDF – but you will have to save the file in order to retain that information. If you close without saving, that date will be lost”.

Is there any way to autosave the changes without the user knowing?
I am making self-destruct PDF, unfortunately Javascript code “app.execMenuItem(“Save”);” is not working. Any tips?

Ric, no, not without the user knowing – at least not unless you can install software on every computer that this needs to run. You would need a folder level script that defines a save function and then call that function from your document. Having said that, trying to implement any document security using JavaScript is not a good idea: There are always ways around this (e.g. by disabling JavaScript). You need a full blown DRM solution (which is not cheap) to do this reliably.

I work for a civic engagement table, and we are registering 90,000 voters before October 11th. We have to redact all of the scanned versions of the forms for their SS#’s and driver’s license #’s. Both of these are contained in a box with a solid printed perimeter, and the writing cannot be recognized by OCR. Could someone help me figure out how to have Adobe automatically recognize the rectangles as a pattern and then redact them if this is possible? They are the only one’s of their size. It’s also not feasible to just repeat the redaction mark across pages because of titled scans. This would save a tremendous amount of work!

Hi, I feel i have some options to do this but i wanted to get a straight / best practice from you as you really seem to have this covered in your wheelhouse! I want to be able to drop say, Photoshop Tiff Files to Acrobat DC and depending on which Template size it is dropped to (say a 10″ x 12″ template) i would like Acrobat DC to auto size the image to the Template size, create a Footer to have a few constants like: Client, Date, Image Name and also place the specified Color Bar (AI or EPS file) all in the right type face and position. This is all for loose proofing. Again, i have had ways and there are a ton of ways to go about this but i would love to get your stance / ideas on this. Let me know when you can and thanks!

Nicholas, there is no method to run a JavaScript when you open a new document. You can try to determine if a new document is opened by polling every second or so, but that’s potentially unreliable. The only way to do this correctly is by creating a custom Acrobat plug-in. This is also the only way to actually determine that the file was created from a TIFF image. Chances are you don’t want to process all files opened in Acrobat the same way (there is no need to process files that are already in PDF). Developing a custom plug-in is much more complex than writing some JavaScript.

Nicholas, creating Acrobat plug-ins is a complex task, and not something you can learn in an afternoon (I would guess that it’s probably two months of climbing the learning curve to get to a point where you can be productive). If you have programming background (C/C++ in a non-managed environment), then take a look at the Acrobat SDK documentation, and the sample plug-ins to see if this is something you want to get into. If not, feel free to get in touch with me via email (my email address is on the “About” page), I do write custom Acrobat plug-ins as part of my consulting business.

For digital copying, I would like to make a pdf document that duplicates each page so I would have page 1, page 1, page 2, page 2, etc. that I could import into InDesign making a 2-up spread of each page, cutting impression costs by half. Is there a way to set that up in Acrobat?

Great article :0) I am trying to add a new menu item in Acrobat DC with no joy. I want to add a button and use a JavaScript that takes page one of my PDF and then makes a copy of it and places after every page following Page 2 in the original PDF. Basically its a business card cover on page one that I want to replicate for the other pages which are the persons details for the back of the card. The best I can do is to add blank pages but I can find a way to extract and copy page one throughout any guidance would be really appreciated kind regards Jon

I am relatively new to Adobe Pro. I have recently figured out have to add values to radio buttons and have them summed up in a tally box below. I would now like to have these specific radio buttons multiply the score assigned in the value field.

For instance: Question 1: Did the corporation have an examiner available?
Field 1: Yes (Value=1) / Field 2: No (Value=0)

[At bottom of page] Field 40: Total Compliance Score (Value=Sum of all fields)

*How can I multiply the “Yes” field values by (2) for those compliance issues I deem more important?

Percy, that is how I would solved this as well. There are a number of profiles on your computer that you can use for color conversion routines, and among them, you will find some profiles that convert to gray scale.

Hello Karl Heinz
can I make a java script to designate the number of printed copies of an Adobe DC document is allowed?
– What would that be?
– Do I delete the text: * Put script title here* and place the java script inside the / / ?

Dear Karl Heinz,
Thank you for your committed support!
I have a button on my pdf that goes to the next page by action.
Now I would like to have a validation of all fields on the same page before this action. When the validation of the fields fails the script should exit and the next action step (to next page) should not happen.
I am missing a way to exit/abort the execution as rc.event doesn’t seem to be available.
Can you help me out about what I am missing?
Thank you and best regards,
Christian

Christian, as you found out, there is no way to make Action steps conditional. It’s either all or nothing, so rewriting the whole Action in JavaScript (if possible – some Action steps cannot be expressed in JavaScript) is the correct way to handle this.

Now another question came up …
If I have a number field, how can I test with JavaScript if it is 0 or “” (empty).
Does a test on empty field exist?
I can not use the standard number field validation as I need customized alerts …

Hi, I am preparing a simple PDF document, and need to know how to get a date-format value from a field (Date_1) into another field (Date_2), where the new date should be (Date_1 + 180 days).
Anyone who can assist here?

Dear Karl Heinz,
just running into another issue where I do not find a working solution.
I have 2 number fields, one number each and after filling in the first one, the cursor should jump directly into the second field.
I can not find a working solution and did not find the commands to automated move around.
Thank you for your time and always the best,
Christian

Dear Karl Heinz, another annoying question from my side …
in an old post from you I found this code of yours:
event.value = event.value.replace(“,”, “.”);
to change , to .
Even so I am still confused with my current setup.
When I enter a number with 2 decimals I have to enter 2,34 which converts to 2.34 when viewing it in the field.

Dear Karl Heinz,
I am able to set the focus now.
The issue now is, if I enter a Script in Validation like this getField(“KK2”).setFocus();
I have to hit enter to jump to the next field, where it should jump directly to the next one after inserting a single digit for a 16 digit Credit Card number …
If I use the mouse-up action event it doesn’t let me enter anything …
What would you suggest?
Thank you and best regards, Christian

Dear Karl Heinz, concerning format options something is not handled correctly.
If I enter 12,45 it displays 12.45 and I can’t enter a . in the field for decimal points.
I checked all over for some settings to control the situation, but cant find anything usefull.
In Apple System Preferences I changed regional settings to use , for decimal separation, so now I enter 12,45 and it displays as 12,45
Just I need 12.45 for all of it 🙁
Thanx and best regards, Christian

You will have to do this with a custom keystroke script. The following will test for one digit (which if you are limiting the number of characters to one per field should work) and move to the next field if you’ve entered a digit:

Christian, unfortunately, without seeing the form, it’s impossible to say what’s going on. You may need to work with somebody to fix this problem. If you are interested in my professional services, my email address is on the “About” page and at the bottom of each sidebar on the right.

Hello Karl!
I have a collection of pdf fillable forms in which, among other things, a checkbox should have been checked off by the reviewer/filler (but some/many were not checked off by one specific individual). The prospect of opening each form and adding the checkmark is not readily feasible and I’m looking for tech options.

It’s the same box on each form. Is there an approach using an action wizard that would:
1. open the individual forms
2. check the specific box (check box 6)
3. save the updated document(s)

Alternatively, as the dynamic forms are being processed/flattened anyhow, is there a way to apply a stamp (which I would create) to a specific area on the flattened forms, which could then be re-flattened?

Or do you have any other suggestions? FYI: I have both Acrobat X Pro and DC Pro.

Kim, yes, with both Adobe Acrobat X and DC Pro, you can create an Action (using the Action Wizard) that would process multiple files, and open each file, check the box and then save the file again (either using the same filename or a new name). Let’s assume your checkbox is called “CheckMe”, then the JavaScript code you would need to add to your Action is the following:
this.getField("CheckMe").checkThisBox(0, true);

The “Run a JavaScript” action step is in the “More Tools” group. With Acrobat X, you don’t have to add a separate “Save” step, that’s already part of the Action, but with Acrobat DC you will need to add a step to explicitly save the modified document.

I really appreciate your reply. Thanks very much! However, I am not able to make it work on Acrobat X unfortunately. I’ll try it on DC tomorrow, but I’m wondering if there’s a problem with the formatting of my form. I entered the script into the execute JavaScript action wizard, exactly as you indicated (except I changed the name of the box to “Check Box6”).

That’s just the initialization message of the JavaScript system and harmless (it will be displayed every time you start Acrobat). Let’s go back a couple of steps: You created an Action in Acrobat X Pro with the one line code that I provided earlier, is that correct?

Acrobat DC – the “Create Bookmark Report.sequ” file I originally got from the Acrobat users group in 2013 does not execute properly with DC. It was written for earlier versions -or does it matter. Do you know of an updated version? I do not know JS so I can’t check it out. I’m using DC 2015 Release (Classic) Version 2015.006.30172

Johnie, I assume you are referring to the Action from AcrobatUsers.com. What exactly do you mean by “does not execute properly”? You are correct, it was written for an earlier version of Acrobat (I think it was for Acrobat X), but it should work in Acrobat XI and DC. I did not write this Action – and I have not used it in a few years – so your best bet may be to get in touch with the original author.

Answer to the Acrobat DC and “Create Bookmark Report”. It is a security issue. What I did was Acrobat/Edit/Preferences/Security (Enhanced). From here I added my working folder path. This created a “Privileged Location” from which to work. Once I added in my folder path, all worked as before- providing I had previously installed the .sequ file.

Is there a way to save a pdf file directly to a SharePoint Library using javascript? I did create an Action Wizard, but using an Action Wizard requires setup on every PC… and that gets old pretty quickly. I’d rather do a trusted function because we can write a script to get that on all the required PCs in one swoop! Thanks Karl.

Karen, I am not familiar with how one would access documents in a SharePoint library directly. If you have an Action, you can export that Action (on the Action Wizard>Manage dialog), and then import this Action into all other instances of Acrobat that you are maintaining. All you need to do is to double-click on the exported Action and Acrobat will offer to import it.

Thanks for your quick response Karl. I just now figured it out! I love when that happens. It is possible. I created a trusted function and the file will save directly into Sharepoint. Getting the path figured out was a bit of a challenge because SP has a path and a URL. You need to convert the URL to UNC.

I just now figured it out! I created a trusted function and the file will save directly into Sharepoint. Getting the path figured out was a bit of a challenge because SP has a path and a URL. You need to convert the URL to UNC.

I have a form with 100+ text entry boxes for various statistical reporting I need from my employees. But not every employee needs to answer every question. Is there a validation script so that when an employee pulls their name down from the dropdown box, the boxes they do not need to fill in change color or become read only? Leaving only the required boxes available to input data. Thank you so much!

Kessa, you can do this as a validation script, but I would very likely (this depends on the rest of the form) use a custom calculation script that gets triggered from e.g. a hidden/read-only field to perform these actions. The key to setting these fields to read-only is the readonly property of the field object. You can find out more about this in Adobe’s documentation: Field.readonly – at the same time you should also set the required property to false: Field.required

Is there any way to set the hover text of a Quick Tool button based on a custom action? The standard buttons all have hover text and even change color when you move over them. Trying to see a way around differentiating buttons when there are multiple actions on the Quick Tool bar.

John, there are three levels of Adobe PDF viewers with different capabilities: Adobe Acrobat Pro, Adobe Acrobat Standard and the free Adobe Reader. When you check the documentation for a JavaScript API function, it will tell you if it is available for a certain product, and if there are differences in it’s behavior depending on what system you run it on. If you stick to functions that are available in the free Reader, then yes, it will run without problems.

Is there anyway to set a javascript which changes the highlighting color in one click of the command? For example, different scripts which change highlighting to one color each. Quite a lot of people have been asking this question online.

Bill, it does not look like your question has anything to do with the blog post it was posted in. There used to be a way to do this in earlier versions of Acrobat (at least back in version 5, potentially up to version 7 or 8), but no longer in more modern versions. You may want to file an enhancement request with Adobe: http://www.adobe.com/products/wishform.html

Acrobat (unlike other Adobe applications) does not let you assign custom keyboard shortcuts to menu items. So unfortunately, I am not aware of anything you can do to get quick access to the Pencil Tool via the keyboard.

I am very inexperienced when it comes to javascript. Needed to make that notation from the jump.

I have a PDF -Adobe acrobat Pro DC, I work with numbers/formulas and am trying to auto input calculations from excel into my PDF. I want to set up a form with both the excel spreadsheet and PDF included and reflect the formulas from the excel spreadsheet onto the PDF automatically each time.

Would you be able to provide specific direction on this? I got as far as javascript and new command.

Annette, unfortunately, I cannot provide customized content as part of my blogging. You might be interested in my professional services. If this is something you would be considering, get in touch with me via email. My email address is on my “About” page.

Mike, this is not possible. Only Preflight profiles can be used as droplets (or accessed in a script). Depending on what you want to accomplish, the steps of an action may be re-implemented as a script, or if you want to venture outside of Acrobat, you can create a standalone application that can perform the steps necessary when you drop a file on the application. If you are interested in pursuing this standalone application, and need professional help, that’s what I do for a living 🙂 Feel free to contact me via the email on the “About” page.

I am new to JavaScript. I’ve created pdf fillable form for our construction change order requests. On one page, the user is able to list the changes, reason for change and the dollar amount of the change. I have 7 sections for these change. These amounts are then calculated to a Total Field on another page. Question: The users occasionally need to add more changes then the 7 sections of fields – is there a way to add more field groups? OR add another page and have these additional pages and/or fields continue to calculate to the TOTAL field on first page?

Kimberly, look into page templates. A page template allows you to “spawn” a new page (meaning you are adding a new page to the document). The form fields on such a spawned page can be renamed automatically, so that they don’t contain copies of the information that was already added to the form.

Hi Karl,
My project is small and the request I believe should be a simple one to fix however nowhere online can I find a solution.
I have created a form that can be submitted to a predetermined email address.
What I would like to do is place another button on the form so that when selected the email is returned to the originator who has placed his/her email address in a text field called ‘Text31’.
Surely this can’t be that hard?
Thanks in advance….Gary

Karl,
I have a command action button already on my fillable PDF form in Acrobat Pro that enables emailing of the PDF as an attachment. Is there anyway to change the command from email to a meeting invite (appointment) for the same email address?
Thank you, Ashley

I have created a fillable form that has 2 buttons currently, a clear for (reset) button and a email button. The email button sends the email with the form attached as a PDF. Instead of it emailing a address, is it possible to make the button an appointment or meeting invite using the same email address? The action button doesnt need to read the calendar just needs to set up a basic appointment window similar to the window it opens as an email.
Hope that makes sense, thanks in advance.

Ashley, that depends… You would need an API for your calendar system that can be used from within Acrobat’s JavaScript. How that would work depends on what that API would be. Unfortunately, I cannot give you a generic solution for this.

Hi Karl, I am trying to create a solution for my company to minimize the amount of data entry we do. What I have done is create an Excel spreadsheet with all of our customers information, brokers, etc. and I want to put all of that information into a fillable PDF form. The problem is I don’t know how to import the data from the Excel file into the fillable PDF form so that I can type a customers name, for example, and the rest of the information will show up. Is that possible to do? Or is the only way to import multiple data is by creating separate forms for each customer?

Alice, this will be be a simple solution, but it can definitely be done. I can see two different approaches: You can either store all the data in a file attachment inside the PDF document, and then with JavaScript extract the relevant table row from that embedded file, or you can create a connection to a database.

Hi Karl. Can I ask you a question regarding PDF JavaScript.
1. Is there any other way to make signature to be compulsory before saving the PDF file? It will not allow user to save the file unless they have a signature on it.
2. Or can the PDF detect which PDF files that don’t have the signature yet. Like an Error Popups or something. Thank you.

belle, forcing a user to do anything before saving a file is in my opinion not a very user-friendly approach: We are used to saving documents we are working on often, because bad stuff can happen when e.g. the power goes out, or the computer crashes for no good reason. The better approach is to validate the document at the time it is getting saved, and then letting the user know that e.g. questions 1, 6 and 9 still need an answer, and that the signature is missing as well, but still allow them to save the file. You can do that by using the “Document Will Save” document action. In that action, you then just go through all the fields that are required and make a note if the field is still empty.

belle, you need to look at the Acrobat JavaScript API documentation. It will list for every method if it’s supported for Reader or not. A lot of JavaScript is actually supported on Reader, but whenever you modify the PDF file, you will very likely run into problems. There is no simple answer, it requires reading the API spec.

Thank you for your commitment on this matter. I keep coming back as you are a valuable source on Acrobat scripting.

I have created a script and put it in a custom command. It does what I want it to, however, it keeps opening the console and I have to press the OK-button on the console window before the script executes. Is there a way to have it so that when I click the custom command, the script executes WITHOUT showing the console window?

Hello. I am trying to wrap my mind around certain things in Adobe. I want to create a quiz (with radio buttons) and once you click on Finnish button I want it to display a thick mark for the correct answers and an X for the incorrect one and I want an explanation to appear below. (I can eventually let go of the thick mark/X, but I do want it to provide the correct answer with an explanation). Is this possible? Can you point me towards what I should read/investigate in order to set this up in a pdf?
Thank you.

A custom command does not show the console dialog unless you ask it to. But you also would not have to push OK in that console to make it run. Maybe wheat you are seeing is not the console window. What exactly do you see on that dialog? And, what version of Acrobat are you using?

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Tip Jar

If the information you found on my site helped you to solve a problem, please consider to hire me for your next PDF related project. If you just want to say “Thank You” for the tips and tricks I provided, you can leave a tip via PayPal (starting at $1):