Swap page order of a PDF using dynamic imposition

Using dynamic imposition, various aspects of the PDF to be imposed can be determined and used to control the imposition process.
In this example, the task is to reverse the page order of the document. As the input document may have different page sizes, the size of each output page have to be adjusted accordingly. Also existing TrimBoxes will become restored in the resulting document

Introducing 2 variables to work with

During normal impositioning, the processing ends as soon as the value of "FirstPage" becomes bigger than the value of the "LastPage". But as the last page as to be positioned as the first page, working with these tokens could become difficult. Therefore 2 new counters/variables are introduced at the beginning and set to the value of the "LastPage" which will be positioned as the first page:

# Set current page:
Set Counter1 var('LastPage')
Set i var('LastPage')

Defining Sheets for every page to be positioned

As the possibilities to analyse the input file during runtime are limited while impositioning, we will just create a new, unique sheet for every page. So we start the "Loop" already at this point:


These created sheets will always have the dimension of the CropBox of the current page. We already set the variable "i" to "LastPage", so we can use the values of this page to define the MediaBox of the Sheet (which is actually the visible dimension after processing):

Set SHEET_DEF_MEDIABOX_L cropboxleft(var('i'))
Set SHEET_DEF_MEDIABOX_B cropboxbottom(var('i'))
Set SHEET_DEF_MEDIABOX_W cropboxwidth(var('i'))
Set SHEET_DEF_MEDIABOX_H cropboxheight(var('i'))

 As the pages may contain a TrimBox, we should take care that this Box as well as existing bleed are maintained. To achieve this, we first set the TrimBox of the Sheet to the values of the current page:

Set SHEET_DEF_TRIMBOX_L trimboxleft(var('i'))
Set SHEET_DEF_TRIMBOX_B trimboxbottom(var('i'))
Set SHEET_DEF_TRIMBOX_W trimboxwidth(var('i'))
Set SHEET_DEF_TRIMBOX_H trimboxheight(var('i'))

and afterwards we also set the Slot (so the place where the page shall be positioned) to the TrimBox of the current page:

Set SLOT_DEF_TRIMBOX_L trimboxleft(var('i'))
Set SLOT_DEF_TRIMBOX_B trimboxbottom(var('i'))
Set SLOT_DEF_TRIMBOX_W trimboxwidth(var('i'))
Set SLOT_DEF_TRIMBOX_H trimboxheight(var('i'))

and to maintain existing bleed, we set the bleed for the Slot to the distance between CropBox and TrimBox for all 4 edges:

Set SLOT_DEF_BLEED_L trimboxleft(var('i')) - cropboxleft(var('i'))
Set SLOT_DEF_BLEED_B trimboxbottom(var('i')) - cropboxbottom(var('i'))
Set SLOT_DEF_BLEED_R cropboxright(var('i')) - trimboxright(var('i'))
Set SLOT_DEF_BLEED_T cropboxtop(var('i')) - trimboxtop(var('i'))

Now we are almost done with the definition of the Sheet and the Slot for the page to be positioned. We just have to take care the page will be placed unrotated, centered and that no additional marks are added to the positioned content:

Set SLOT_DEF_BindingMargin 'N'
Set SLOT_DEF_CropMarkStyleLB 'N'
Set SLOT_DEF_CropMarkStyleLT 'N'
Set SLOT_DEF_CropMarkStyleRT 'N'
Set SLOT_DEF_CropMarkStyleRB 'N'

The impositioning process

We have not defined the correct Sheet for the last page.
We now have to:

  1. "write" this data as an available Sheet definition
  2. create a new Sheet based on this Sheet definition
  3. create a Slot on this page (named "1")

SetSheet var('i')
NewSheet var('i')
MakeSlot var('i') 1

We already set the Variable "i" and the Token "Counter1" to the Value of "LastPage".
Now we are ready to place the page, which will be done with the page number stored in "Counter 1" (Variables can not be used to place a page):

PositionPage Counter1 Slot_1

Now the last page is positioned and we have to prepare the used Variables and Tokens for the next Loop. Therefore we set the values for "i" and "Counter1" to the secont last page (last page - 1):

Decrement Counter1
Set i var('i') - 1

To ensure the processing is terminated after the first page as the last page in the new document, we also increase the Token for "FirstPage" by 1. As already mentioned: the processing will stop as soon as the "FirstPage" becomes bigger than "LastPage" (which remains to the real number of the last page during the whole imposition process).

Increment FirstPage

The RunList ends here and will automatically start again after "Loop".
There a new Sheet definition will become created which will then be used for the positioning of the second last page and so on...

0 Kommentare

Geben SIe Ihren Kommentar ein

E-Mail senden, wenn jemand auf diesen Kommentar antwortet