JavaScript imposition - getting started
To get started with the JavaScript imposition, the first step is to set everything up. This article documents how to create a JavaScript configuration setup, start editing the JavaScript runlist and put the basic JavaScript framework in place. The next article then shows how to build a simple but complete JavaScript configuration.
Setting up the environment
First of all, bring up the Switchboard, and locate the "Impose" action in there. You can do this either in an existing library, or in a new library.
The "Impose" action can be found on the "Arrange" pane of the Switchboard.
Creating a sheet configuration file
Every JavaScript imposition configuration must have a sheet configuration file. In many cases this file will be empty, but it must still exist. If you want to, you can create one empty sheet configuration file and use it for many different runlist files.
To create a sheet configuration file, click on the gear icon next to the "Sheet configuration" menu. In the menu that appears, select "New". This opens the sheet configuration editor.
The editor has no name yet and is empty. For the name, fill in: "Impose movie tickets". Leave the editor part empty as we're not going to use the sheet configuration file in this example.
The editor may look different in your case as it supports different color schemes. The name of the theme shown is "Solarized Light", but you can click on it to change it to other light or dark themes.
After you have given the sheet configuration its proper name, click on "OK".
The "Impose movie tickets" sheet configuration is added to the library and is automatically selected in the sheet configuration menu in the Switchboard.
Creating a runlist file
Every JavaScript imposition configuration must have a runlist file. This is where the imposition logic is defined, but for JavaScript imposition configurations also often where sheets and slots are defined. In other words, for most JavaScript imposition configurations, everything can be found in this one file.
To create a runlist file, click on the gear icon next to the "Imposition scheme" menu. In the menu that appears, select "New". This opens the runlist editor.
The editor has no name yet and is empty. For the name, fill in: "Impose movie tickets". Make sure that the "Language" radiobutton is set to "JavaScript" (it should, as this is the default in pdfToolbox).
From pdfToolbox 16, the editor looks slightly different and has more capabilities. The "Language" text referred to above is now called "Type".
Leave the editor part empty for now; we'll come back to editing it soon. The editor may look different in your case as it supports different color schemes. The name of the theme shown is "Solarized Light", but you can click on it to change it to other light or dark themes.
After you have given the runlist its proper name, click on "OK".
The "Impose movie tickets" runlist is added to the library and is automatically selected in the imposition scheme menu in the Switchboard.
The JavaScript runlist concept
Now that we have both configuration files needed for our JavaScript configuration, let's add some boilerplate code to our JavaScript runlist. This code will typically be the same (or very similar) for every JavaScript runlist you write. Click on the menu next to our runlist, and this time choose "Edit" to open up the runlist editor again.
Add the following code to the editor:
// Create an imposition object
const imposition = new Impose({
unit: "mm",
});
// Imposition logic missing...
// return the imposition object to pdfToolbox
imposition;
This code:
- Creates a new JavaScript object of type "
Impose
" and assign it to a local variable ('imposition
'). - Creates this object with a default value for the units used by the imposition, in this case millimeter.
- As the last line, 'returns' this local "
imposition
" variable to pdfToolbox so it has all information to perform the imposition.
Once you have entered this code, click "OK" to save it to the imposition runlist.
Do not attempt to run the imposition configuration on a PDF file at this time. Our code is not complete. If you would do so, pdfToolbox will return an error that says it can't find any sheets as a result of your imposition code.