JavaScript imposition - step by step examples
The rest of this chapter contains detailed documentation on the JavaScript objects and convenience functions available to create JavaScript configurations. Sometimes though, it is easier to learn from code examples, so this article lists specific examples to help you grasp different concepts.
The article comes with a downloadable pdfToolbox library. Import it into pdfToolbox Desktop by dragging it on top of the main pdfToolbox Desktop window. Then go to the Switchboard > Arrange > Impose, to see the JavaScript configurations in it. The library also contains an example Impose action so you can see how to include the imposition configurations into a process plan when necessary.
The rest of this article provides a summary of what each example shows, and any special remarks you should keep in mind about it.
01 - creating a single empty A4 sheet
This example shows how to setup a basic imposition configuration that uses millimeter as it's default measurement. It also creates a single A4 imposed sheet. As no slots are created for the sheet, it is a blank sheet.
02 - creating one blank A4 for each input page
The JavaScript imposition engine also gives you access to the JavaScript "app
" object that pdfToolbox provides. This gives you access to simple variables, information about the current document and more. This example shows how to use app.doc.numPages
to know how many pages the input PDF contains. The output of this imposition configuration consists of a PDF with blank A4 pages; as many of them as the number of pages in the input PDF file.
03 - placing each input page on a separate A4
In this example a "slot" is introduced. It is setup with a size that is the A4 output sheet minus a 10 mm border. It also uses some other properties to get specific behavior:
- crop marks all around the slot,
- scaling so that the placed PDF pages are scaled (up or down) to fit in the dimensions of the slot,
- placement in the center of the slot.
04 - asking for imposed sheet dimensions
As we have access to the app
object, this example asks for two pieces of information from the user: the width and height of the imposed sheets that are going to be created.
To keep things neat, it's using app.context.dialog.order
to make sure the information is asked in the correct order (width than height).
05 - demonstrating place text
This example shows how to add text to the imposed sheets. Different fonts, text sizes, and colors are illustrated.
06 - Rotating slots
Content can be rotated in slots as it is placed; as demonstrated in this example. It shows the four different rotations supported. Because the slot used always has the same size, and the scaling is set to "fit slot proportionally", this configuration affects the size of the PDF pages placed in the slot if the placed pages are rectangular.