Output the spooled file pages in reverse order

Output the spooled file pages in reverse order

It is possible to output the pages of a spooled file in reverse order. This section describes how you can setup a template in InterFormNG2 to achieve that.

 

That is possible, if you setup a template like below:

 

NG2SplfReverseOrder0001

 

Each of the steps are explained below:

 

1. Variable PageCounter is set to the attribute, endPage. This is the last page of the spooled file. We intend to use the variable PageCounter to count backwards, so that is what the initial value is the last page number. We refer to the attribute, endPage as a way to only process the pages within the pagerange of the spooled file. We will use this as an index to the current page number.

 

2. A repeat is defined. This is the number of pages, that we will go through. Again this respects the pagerange so we refer to the first page of the original spooled file via the attribute, //startPage. So the number of page is the last page number minus the first page number plus 1.

 

3. A current page repeat is defined as "/spool/page[number($PageCounter)]". This is used as a way to set a current page of the spooled file. Any reference to the spooled file contents as a reference to the current page (Auto) will automatically refer to the current page in this reverse loop. The path /spool/page refers to the page nodes in the internal XML file, that actually contains the spooled file. The [] enables us to set a specific page number as index and select the current page. We need to refer to the PageCounter as a number, so we use the number() function to force/cast the PageCounter into a number.

 

4. A page element is the container in which we can setup the actual design of the output pages.

 

5. A text element. Inside the page element we here insert a text element, that maps spooled file data from the current page in the normal way.

 

6. Decrease the PageCounter variable. We decrease the PageCounter with 1 with the expression: $PageCounter - 1. Please note, that you need to insert a space prior to the minus sign in order to separate it from the previous variable name.

 

 

Combining reverse order with new page breaks

It is also possible combine this reverse order with the option to change page breaks of an input spooled file. In such a case you will probably want to divide the output in a headerfooter and body section, to reuse the same header in the output. Below is an example which shows how that can be done:

 

NG2SplfReverseOrder0002

 

There are a few changes compared to the previous example:

 

The header and footer elements has been added as a way to reuse the same header/footers on all the pages.

A remap of the spooled file data from page 1 is added in the header.

A footer is added with a container to ensure that detail lines are not getting too close to the edge.

A line repeat is added (subsequence(./line, 30, 13) to iterate over the detail lines of each page.This repeats over 13 lines starting in line 30.

Inside the line repeat the data of the current line is output in the text element: ng:spoolMapRel(., 1, 75, 0, 1). This remaps position 1 to 75 of the current detail line of the repeat loop.

 

With the settings above the output below is created for a demo spooled file. The bold text is the header data and the detail lines are output in reverse order - last page first:

 

NG2SplfReverseOrder0003

    • Related Articles

    • Spooled file support

      InterFormNG2 is able to process spooled files, if you install InterFormNG2 on the IBM i platform. Please notice, that spooled file support, as well as Spool2XML, are modules for InterFormNG2, that are purchased separately. You can also use the ...
    • Spooled file split

      You might want to split up spooled files during InterFormNG2 processing. The reason might be, that the input spooled file may contain multiple documents (e.g. invoices), and that you want to create one PDF file (or email) for each invoice. There are ...
    • Print output

      You can print to on most printers in InterFormNG2. The printing can be done with these workflow components, if the printer is registered in InterFormNG2: 1.With the Print workflow component. This is the normal print component, that does a merge with ...
    • Restore a spooled file

      With InterFormNG2 you restore a spooled file in two manners: 1.You can download a loaded spooled file from the InterFormNG2 library, and upload it into the library (same procedure as an XML file) of another InterFormNG2 installation e.g. on a windows ...
    • Spooled file into Excel

      This section shows how a spooled file can be converted into Excel. The example relates to a spooled file, that has a format like below: The spooled file is a multi-page spooled file with a header, some details lines (in the middle blue frame), which ...