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:
function CountBookmarks(bkm, nLevel) { var count = 0; if (bkm.children != null) { count = bkm.children.length; for (var i = 0; i < bkm.children.length; i++) { count += CountBookmarks(bkm.children[i], nLevel + 1); } } return count; } (function() { console.clear(); console.show(); var n = CountBookmarks(this.bookmarkRoot, 0); console.println("Number of bookmarks found: " + n); })();
If you are confused by the anonymous, self-executing function, take a look here for more information: http://esbueno.noahstokes.com/post/77292606977/self-executing-anonymous-functions-or-how-to-write. I am using such an anonymous function so that any variables that get declared are local to that function, and don’t interfere with any other JavaScript in Acrobat.
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.
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.
Thanks again.
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
Al, unfortunately, I don’t know what you mean by “moves into the total field”. Can you please describe in more detail what exactly is happening.
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?
Greatly appreciate it any help.
Thanks!
How to I add a time/date every time the pdf is opened?
I know it’s a javascript but not sure where to place it.
Susan, you can create a document level JavaScript that gets executed every time you open the file:
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?
Anne, I just answered your question on AcrobatUsers: https://answers.acrobatusers.com/How-move-sticky-note-icons-multiple-pages-q295004.aspx?tc=16584420041012201540462
I’m trying to create a toolbar button to print the current page to the default printer. I’ve created my function as:
/* Put script title here */
function PrintCurrentPage() {
this.print (false, this.pageNum, this.pageNum);
}
and assigned it to a toolbar button, but nothing prints.
Any help is appreciated.
Debra, are you getting any errors in the Javascript console (Ctrl-J or Cmd-J)? How exactly are you calling the function from the toolbar button?
I’ve created a custom command and entered the JavaScript I found elsewhere. I’m not getting any error messages. I customised the quick toolbar to put it on the toolbar. Please see screenshot below.
https://app.box.com/s/f3t03j3xy1fh5ogpgrw7zvdl8dl1uu7u
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):
this.print (false, this.pageNum, this.pageNum);
I am trying to use this javascript (http://stackoverflow.com/questions/12689154/adobe-acrobat-reader-tabs-saving-and-autoloading) in Acrobat DC to save (and be able to reopen) opened tabs (for various reasons the recent open files in the acrobat DC menu does not do what I need). I followed your explanation but alas, I think I am missing something crucial as this script doesn’t work.
Any tips?
Thank you!
Hi!
I have a PDF with CMYK color space. Is there a way to convert all objects using RGB JavaSript?
Thanks Mark
Mark, yes, this can be done with JavaScript, using the Doc.colorConvertPage() method. There is an example in the SDK documentation that shows how to convert everything to RGB: http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_getColorConvertActionbc-41&rhtocid=_6_1_8_23_1_40
Roman, I am not familiar with this script, so would not even know where to start to debug this problem. You may want to as your question on StackOverflow, where you found the script.
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.
Thanks Michael
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)
Thanks Karl Heinz. I will be in touch
Michael
It’s not possible any more to index files in folders – is that correct?
It was in Acrobat Pro X …
:o(
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.
Hi Karl Heinz Kremer ,
I wondered if it is possible to create a custom action using indices (e.g.: go to folder xyz, embedd index in all files, finish), as it was possible with Acrobat X
Thanks!
STP, now I understand: You want to process a folder of PDF files and embed an index in each file. This is done via the “Save” action:
Thank you!
Hi Karl,
Susan Brandt ask How to I add a time/date every time the pdf is opened?
Your answer is:
-“create a document level JavaScript that gets executed every time you open the file
this.getField(“LastOpened”).value = util.printd(“mm/dd/yyyy”, new Date());
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?
Thanks,
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!
Matthew, I replied to you in an email.
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.
Hi Karl,
Thanks for your reply, i really appreciate it! I have looked into making some Adobe Plugins. Do you have any suggestions as i am always up for other ideas!
Thanks!
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?
Laurie, yes, this can be done. Take a look at this script here: https://www.evermap.com/javascript.asp#Title:%20Duplicate%20every%20page%20in%20the%20document%20(carbon%20copy)
Hi Karl,
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
Jonathan, take a look at the Doc.insertPages() command: http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_insertPagesbc-73&rhtocid=_6_1_8_23_1_72
You will need to insert pages from your own document, so you need to use the ‘this.path’ property for the cPath parameter.
Where is the Acrobat DC javascript folder? Does anyone know?
Take a look here for more information about where folder level JavaScripts need to be stored: http://khkonsulting.com/2010/12/acrobat-javascripts-where-do-they-go/
Good day,
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?
Thanks!
Karl,
Read with interest your answer on how to convert a CMYK PDF to RGB with an example in the Acrobat DC SDK.
Trying to do the same for CMYK PDF to grayscale using Acrobat DC…how different would the javascript code be, or is that possible?
Thank you for sharing all your great insights into creating custom commands!
Percy
Karl,
Believe I solved it through some trial and error (a Mac solution not sure if it applies to Windows as well)
Basically the exact same script can be used by simply changing
toRGB.convertProfile = “Apple RGB”;
to
toRGB.convertProfile = “Generic Gray Profile”;
I’m not concerned with the resulting image quality, but only for file size when creating archives of 1000s of document with accompanying PDF indexes.
Of course all instances of “toRGB” could be changed to “toGray” and it still works
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.
Bruce, one option would be to use a different value for your “Yes” field – if you use the value of 2 for all the options that are more important, you don’t have to change your calculation routine.
According your experience, it’s possible to make a Java script to start an action to compare by Acrobat DC two PDF?
Erbmanno – no, this is not possible.
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 / / ?
Cheryl, You cannot limit the number of prints that are allowed via JavaScript. To control things like that, you will need a DRM (Digital Rights Management) solution.
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
Dear Karl Heinz, sorry the problem above is solved. I got rid of the action steps, writing it all in JavaScript
this.pageNum++ in an if statement did the job for me …
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.
Dear Karl Heinz,
thank you for your reply.
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 …
Regards,
Christian
Christian, use the Field.valueAsString() method to get the raw string (before it gets converted to a number). You can then compare agains “” and find out if the string is empty: http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_properties.htm%23TOC_valueAsStringbc-51&rhsearch=loadXML&rhsyns=%20&rhtocid=_6_1_8_31_1_50
Hi Karl Heinz,
great stuff! Saved my day :-!
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?
/Christian
Chrille, date calculations are part of the core JavaScript language, so you use the “normal” JavaScript way of doing this as the calculation script for your second date:
var theDateString = this.getField("Date1").valueAsString;
if (theDateString != "") {
var theDate = util.scand("mm/dd/yyyy", theDateString);
theDate.setDate(theDate.getDate() + 180);
event.value = util.printd("mm/dd/yyyy", theDate);
}
else {
event.value = "";
}
You may also want to look into a new Date library from Joel Geraci, which makes these types of calculations a bit easier: http://practicalpdf.com/introducing-the-practicalpdf-date-library-for-adobe-acrobat/
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.
I need to enter 2.34 and it should stay like this.
Thank you,
Christian
Christian, you can do this by using the Field.setFocus() method once the criteria for moving to the next field is met. See here for more information: http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField_methods.htm%23TOC_setFocusbc-18&rhtocid=_6_1_8_31_2_17
Christian, you should not have to change a decimal comma to a decimal point – this should all be handled automatically when you use the correct format options for our fields.
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:
var re = /\d/;
if (re.test(event.change))
this.getField("Test.1").setFocus();
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.
Thanks for any help you can offer 🙂
Kim
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.
Hi Karl,
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”).
Hi Kim, are you getting any errors in the JavaScript console?
Hi Karl,
I’m getting the following ctrl-J message:
Acrobat EScript Built-in Functions Version 10.0
Acrobat SOAP 10.0
Does that mean anything to you?
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?
Thanks for your behind-the-scenes assistance Karl – everything is working perfectly 🙂
Will definitely recommend your services in the future!
Kim
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.
Thank you for your quick reply. I now believe it to be a security issue with JS and my company security policy.
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.
Your commitment to answering questions is much appreciated!
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 a way to open an existing excel workbook from Adobe reader through javascript?
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.
Vale, I am not aware of any action that would accomplish this.
ShivaKhumar, Reader cannot open Excel documents. You need Microsoft Excel for that.
Just wanted to verify that once you use Adobe Acrobat DC Pro to add script to a PDF, that I can send copies of it to general users who only have Adobe Acrobat DC, it will execute the scripts properly.
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
Hi, Karl —
I want to be able to assign keyboard shortcuts for specific Comment tools that don’t have one. If I can add them to a menu, though, I can do it (through an independent program).
If I use the Create Custom Command, it adds a submenu to View > Tools, but it only opens the pane, it doesn’t run the command.
Is there a way either to get *run* on the submenu — or barring that, a simpler way to assign a keyboard shortcut to e.g. the Pencil Tool?
Many thanks in advance!
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.
Any scripts to Auto Expand Text Form Fields in Adobe Acrobat Pro DC?
Abraham, this is not possible. You will have to use a LiveCycle Designer (or XFA) form for that.
Hi Karl,
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.
How does one add a name to the button in the Quick Tools.
Right now I have only 4 buttons and the icons are all the same.
I’d like to label these in some way
Chris, unfortunately, I don’t think you can do that.
Hi Karl,
Is it possible to add a droplet to an action or access an action using a script?
Thanks,
Mike
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
Gary, you would have to create a button that reads the email address from this field (Text31) and then sends out the email. Take a look at the JavaScript API documentation for Doc.mailDoc(): https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FDoc_methods.htm%23TOC_mailDocbc-74&rhtocid=_6_1_8_23_1_73
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?
Thank you,
Alice
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.
The first solution is illustrated here:
https://acrobatusers.com/tutorials/getting-external-data-into-acrobat-x-javascript
And you can find more information about the second one here:
http://khkonsulting.com/2017/08/connect-database-pdf-form-time-without-soap/
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.
I have added the debugger.js in Adobe Reader DC but the debugger seems different like any other tutorials on google. Especially in References – JavaScript.
I have tried to save the debugger that you gave in other link but it failed.
1.Does the Adobe Reader DC really did not support javascript debugging or it is just need to be paid to use the functions?
Thank you.
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.
Hi Karl,
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.
Ramona, I would use a button field with the check mark or the X as the button image and then show or hide the button based on the correct answer.
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?
Hi Karl,
I’m trying to get acrobat to open signature draw field on click on a designated box within a document (say it’s position is – left: 1.45 in, right: 2.47 in, bottom: 2.28 in, top: 2.55 in, width: 3in, height: 2 in)
And after the signature is drawn and Save is clicked within the signature box, have it placed within the designated box within the document.
Can you please provide javascript for it? I’ve tried researching on internet, but couldn’t find anything that would work. Any help would be much appreciated.
P.S. no need for digital signature, just ability to draw a signature or initials.
Aliaksandra, I am sorry, but I don’t provide code for something completely unrelated to the blog post you commented on – at least not for free, I do run a consulting business 🙂
We run a wizard in order to OCR a batch of multipage PDF documents and this works well however we only need page 2 and 3 OCR’ed and although you can select page 2 – 3 when you OCR a document individually you are unable to select this option when you run a batch wizard, it does however mention that you can write a java script to run.?
Nina, I am sorry, but I don’t have a solution for you. The action does behave differently than the user interface. You could split your document into three parts: The pages before the OCRed section, the pages that need to be OCRed, and the pages after the section and then just OCR those pages that need it and then assemble the document again.
Thank you Karl I will try the splitting solution for now and keep investigating.
I am trying to calculate the number of times N/A is selected from a drop down menu on each page to a total field on a form in Adobe Acrobat Pro DC. The current drop down options are 0, 1 and N/A. On one page, there is 1 column of down downs and I have the selection appearing in the total column to tally. The next page is 3 columns of 7 rows which total from left to write to a column to total the selection.
Tosha, you need to loop over all fields and then just get the field value, compare to N/A and run a counter. Looping over the fields can be done in multiple ways. One option is to create an array of strings that contains all the field names you are interested in, and then just use standard JavaScript methods to iterate over that array. Or, you can name your fields in a certain way: Let’s say you are interested in something you call “TheResponse” and you have 20 different variations of that. When you name these “TheResponse_1”, “TheResponse_2”, … “TheResponse_20”, you can create a JavaScript for loop that goes from 1 to 20 and you can create these field names on the fly. The original layout of the form (what you call columns and rows) has no bearing on how you access the fields – every field needs it’s own unique name, and ideally, you use names that are descriptive.
I’m trying to insert a one page pdf before every page of another pdf and I’v seen online that its possible but im not wrapping my head around it in my mind it should be
open multi page pdf
customizable commands
insert pages
choose 1 pg pdf
location: Before
page: 1-__last pg #__
but it only inserts the one before the last page and i can’t figure put what to do
Sam, for something like this, you need to write a JavaScript. That’s the only way to get this done in a loop that processes all pages of your document.
Hi Karl,
Apologies if you have already answered this in a different thread but I am a non-developer attempting to automate a Fillable PDF we currently use for our technicians to manage their daily Jobs.
They all complete the Fillable PDF and then our team here manually copies the data and pastes into an XLSX document.
Trying to find a possible solution for this backend manual copy and paste within the Adobe Suite.
Hoping you can steer me in the right direction.
Mark, if you have somebody who can write VBA programs for Excel, you can access the data from the form directly and add it to a spreadsheet. See here for some information about how to do that: http://khkonsulting.com/2010/09/reading-pdf-form-fields-with-vba/
Is there any way to deploy this to many users – say 100? I would like to have a button on every users Acrobat DC Pro tool bar that would allow them to rename any PDF they have open and save it to a specific folder. Or maybe another way to achieve this?
Thanks for all your work.