Everything is better with JavaScript

There is a meme on the Internet that says: "Everything is better with Bluetooth", or otherwise said, to improve anything, "Just add Bluetooth". You can find t-shirts about it, and the Big Bang Theory episode introducing it goes back to 2009. That’s how JavaScript somehow feels to me as well.

It was developed in 1995 and was, for a long time, the exclusive playground of connoisseurs of the newly invented Internet (raise your hand if you remember Mosaic and the rotating world logo…). And then, someone decided that everything would be better with JavaScript, and it started to pop up in all kinds of places it was originally not conceived for.

In graphic arts, JavaScript first appeared in the Adobe toolset, where it can be used in Acrobat, InDesign, Illustrator… to enable more flexible automation. It was also integrated, as far back as 2005, into what was then called Gradual PowerSwitch (now known as Enfocus Switch) as a cross-platform scripting language to write custom tools. And it is now one of the key components of callas pdfToolbox.

But why?

First, why JavaScript?

JavaScript’s goal was to create a "programming language for the masses," as Brendan Eich, inventor of the language, said. It was rather limited compared to other languages such as C, C++, or Turbo Pascal (my first love as a developer!), but that simplicity made it easier to understand. It didn’t need fancy tools such as compilers or IDEs (Integrated Development Environments); a simple text editor did the job just fine, thank you. It also avoided many of the really hard concepts, such as memory management, that plagued other languages (well, mainly the developers who had to use those languages).

That being said, JavaScript still contained (and contains) everything one needs in a programming language. All of the essential concepts with regards to branching (if… then… else type of scenarios), looping (repeatedly running a piece of code), and code reuse (the ability to write code that can be flexibly re-used in many different places) … were available.

And, perhaps most importantly, JavaScript was a weakly typed language. That gets a bit technical, but it means that it’s not too strict about what type of data you’re declaring or are working with. It automatically converts between numbers and text and generally tries to be lenient.

That last bit isn’t necessarily good, as many "serious" developers will tell you. But it does make JavaScript more easily accessible and less threatening to non-programmers.

So, why in pdfToolbox?

It became clear very quickly that pdfToolbox would need the concept of variables. After all, if you print 300 different sizes of products, you don’t want to create 300 individual preflight Profiles. Variables allow you to provide specific information from the outside and use it in pdfToolbox. This variable type was added in pdfToolbox 4, now ancient technology.

Adding variables like that (called "simple variables" today) was a great addition to pdfToolbox and quickly became widely used. However, it didn’t cover all that was needed. What if an MIS system could give you the dimensions of the job in feet, but you needed it in points to run a preflight check, for example? What if you want to impose the cover of a book, but you need to be able to calculate how wide it would be given a variable spine width? You really want to be able to calculate things and implement some simple logic in a powerful product such as pdfToolbox.

Macros? Functions?

So how do you allow this? Is there a way to allow what calculations are needed, yet keep it simple? There are examples of this, and a good one is Microsoft Excel. In Excel, you have a wide array of built-in functions. No development knowledge is necessary; pick the function you want to use and provide it with input. What could be simpler?

Anyone who has used Excel to do non-trivial tasks understands the problem with this approach. First, Excel functions are still difficult to use (even as a developer, I have lost many hours of my life reading their documentation and perusing online forums). Second, and much more critical, this approach is still severely limited. Microsoft understands this too, as they provide an additional macro layer where you can use Visual Basic.


While developing pdfToolbox 9, callas internally discussed the best way to extend the "simple variable" concept. As any "function" or "macro" approach would always be limited and require users to learn yet another language or set of functions, the decision was made to go all out and implement the Google V8 JavaScript engine instead.

Yes, this required users to understand and write JavaScript, which is not trivial for non-developers. However, users didn’t have to learn another proprietary language, and JavaScript documentation and forums were plentiful. Having access to the full JavaScript language meant that even very complex calculations and logic could easily be integrated into pdfToolbox.

Variables in pdfToolbox

Many years later…

The integration of JavaScript variables happened in 2016; in hindsight, was it a good idea? Well, this is a complex capability of pdfToolbox, and it is certainly not used by all users. That said, the percentage of users who – in some way – use JavaScript in their preflight Profiles or Process Plans is surprisingly high for such an advanced feature. The seamless integration of JavaScript functionality in Process Plans, specifically, allows for use cases that were previously unheard of.

Twice a year, callas organizes a pdfCamp, hackathon-style, event. The agenda of those events is entirely attendee-driven, and JavaScript almost always plays an important role. Isn’t that the true measure of any software functionality: how extensively it is used in real life?

Or in the words of the late Steve Jobs during his many fantastic Apple keynotes: "We built this for you, and we can’t wait to see what you will use it for".

If you're curious about using JavaScript in pdfToolbox, be sure to check out our online documentation - there's a whole chapter dedicated to variables and JavaScript. Or join us at our upcoming pdfCamp on October 10th and 11th in Berlin, where you can dive deep into the JavaScript functionality of pdfToolbox and explore a wide range of its features. This hackathon-style event is the perfect opportunity to learn more about pdfToolbox and connect with the callas team and other users. Seats are limited, so don't miss out and register today!

Back to overview

Subscribe to our blog newsletter for access to regular updates

No strings attached. Unsubscribe anytime. For further details, review our Privacy Policy.