If you want to combine spooled file processing with duplex, then you first need to consider which duplex option, that you want to implement. In the scenarios below it is assumed, that you want to process the input spooled file in the usual way: That one input page in the spooled file is to become one output page in the merged result - expect extra optional pages e.g. for the back of one or multiple pages.
Here are examples of how you can print a spooled file in duplex:
1.Print the complete spooled file in duplex and simply print on back and front of the paper.
2.Print the complete spooled file in duplex with forced front page. This is similar to the first duplex, but here it is ensured that if the spooled file contains multiple documents, then a forced front page is ensured i.e. a new document always starts on an odd page number (an empty page might be added to ensure this). In that way we can avoid printing one document on the front of an output page and another document on the back.
3.Print an extra back page (with e.g. Terms and conditions) on all output pages.
4.Print only the first page in duplex and add an extra back page e.g. with terms and conditions. The rest of the spooled file is to be printed in simplex.
5.The initial part of the spooled ilfe is printed in simplex and only the last page is printed in duplex where an extra back page (with e.g. terms and conditions) is added.
The ways to select between simplex and duplex are these:
•You can use the workflow elements, Set printing properties or Set sides for printing. The limitation is however, that this sets duplex/simplex for the complete print out.
•With the design element, Print settings you can dynamically select simplex/duplex per page in the output. You need to insert this element within the page element, which set the printing type for the current page and onwards until another Print settings element is executed.
If you simply want to print the full spooled file in duplex e.g. in order to save paper, then you have these options:
1. With one of the workflow elements
It is possible to define your template as normal and then activate duplex in the workflow before the printing is done with either of these workflow components:
Set printing properties or Set sides for printing.
The workflow can be setup like below:
2. Activate duplex with the Print settings element in the template
Instead of activating the duplex in the workflow you can also activate it in the template with the Print settings element inside the page element like below:
This section handles the scenario, where there are multiple documents within one spooled file and still we want to print as much in duplex as possible - but we need to ensure, that we are not mixing two documents on the same output page i.e. printing one document on the front of a page and another document on the back.
As a reference let us consider a spooled file with this layout:
On each page in line 3 in position 72 ( 1) we see the page number of each document. This number is right aligned, so if we test if position 71-72 is a blank character followed by a 1, then we know that the current page is the first page of a document (we need to include position 71 in the condition as a way to ensure, that the condition is not true for page 11, 21 etc..)
In this case we also have a document number (1004) of the current document, which of course change when a new document is found. This document number is here found in positions 57-60 in line 13.
As a part of the solution we need to find out when the next page to be output is an even number. If the next page number is even, then we might need to insert an extra, empty page to make sure, that the next document start on an odd page number (front of a paper).
In order to calculate if the next page is an even page number we need to consider the xpath function, mod (or modulus). This function returns the reminder of a division. If we e.g. divide any number with 2, then the reminder is 0 if the number is even and the reminder is 1, if the number is odd. So if we test the current number of pages in the output and that is odd, then we know, that the next page is going to be an even page. So the boolean expression (true or false) can be setup as: ng:page-number() mod 2 = 1, where ng:page-number() is a function that returns the number of pages, that we have already generated.
Given the spooled file and options above we can consider these two solutions:
1. Identify the first page of a document by testing the document page number
We already have half of the condition for when to insert the extra page (ng:page-number() mod 2 = 1) and we now just need to combine this with a test on the document page number found in the current input spooled file page. The total condition is then: (ng:page-number() mod 2 = 1) and substring(./line[3], 71, 2)=' 1' as seen below:
The condition substring(./line[3], 71, 2)=' 1', might seem cryptic, but substring(./line[3], 71,2) extracts spooled file information from the current page, line 3, position 71 and 72 and compares that with blank followed by 1. This parameters of the substring is found simply by selecting this area in the spooled file.
2. Compare the document number with the previous one to identify a new document
Instead of referring to the page number inside the document we can also verify if the document number has changed since the last page. If the document number is different, then we need to ensure, that the next output page is odd similar to the test above.
One way to compare the document number with the previous one is to store the document number in a variable and compare this with the current document number.
This can be implemented like below:
For this duplex option we need duplex enabled for the complete output. That means, that we can enable duplex either in the workflow with the workflow components, Set printing properties or Set sides for printing or we can insert the Print settings element in the first page element and here enable duplex. Both of these options are covered above in the section, Print the complete spooled file in duplex.
In this case we choose to enable duplex in the page element with the Print settings. In that way the workflow is unchanged even if we would later change into a dynamic duplex option.
A solution to this is shown below:
On the extra back page (Terms & Conditions) you can still access the spooled file data, so it does not need to be static in any way: You can e.g. save data from the previous page in a variable and use that here or access data from any spooled file page - even the last one.
In this case we want to insert an extra back page on the first page only, print those two pages in duplex, but the rest in simplex.
This can be achieved with a template like the one below:
The condition: "ng:page-number() = 1" is true after the first output has been generated, so now we know it is time to generate page 2, which is the page with Terms & Conditions. On this page you can still access the spooled file data, so it does not need to be static in any way: You can e.g. save data from the previous page in a variable and use that here or access data from any spooled file page - even the last one.
The select in the main page element selects duplex for the first 2 pages and simplex for the rest with the Print settings element.
A more advanced way is to insert the Terms & Conditions as an extra back page whenever there is a new document. The previous section covers how you can either use a trigger, which is found on the first page of a document or a trigger based on a change of the document number.
This can be done with a template like below:
Here two variable are used:
PreviousDocumentNo
This keeps track of the previous document number. If it changes then we know, that the next page is the first of a new document.
TermsTrigger
This is used as a flag to indicate if the page with the terms and conditions is to be inserted. This could have been implemented as a boolean (true() or false()), but instead we here use the values 'Yes' or 'No'. This is also used as a trigger for the duplex/simplex switch in the select element.
Here we imagine the scenario where the complete output is to be printed in simplex, but the last page is printed in duplex with an extra page with Terms and conditions (or similar) on the back.
Instead of adding an extra page on the back of the first page we might instead want to add an extra back page on the very last page of print out. For that we need to trigger duplex when the last page of the spooled file is processed and an extra page element is also to be added.
This can be done with this template:
If you look to the bottom then you can see the extra page element with the terms and conditions, that we want on the back of the last page. Please notice, that this last page element is inserted outside the page repeat loop. On this page you can still access the spooled file data, so it does not need to be static in any way: You can e.g. save data from the previous pages in a variable and use that here or access data from any spooled file page - even the last one.
The remaining challenge is to dynamically change between simplex and duplex and that is done in the select condition. Here the current output page number (found via ng:page-number()) is compared with the total number of spooled file pages as found via the spooled file attribute, endpage.
The example above is the simple one where we assume, that there is only one document in the spooled file, but if we want to insert an extra back page on the last page of each document (for a multi document spooled file), then we need a solution, which is a bit more complicated:
The variable, TermsTrigger is set to 'Yes', if it is time to activate duplex and add the extra back page. On this page you can still access the spooled file data, so it does not need to be static in any way: You can e.g. save data from the previous page in a variable and use that here or access data from any spooled file page - even the last one.
The comparison: substring(following-sibling::page[1]/line[13],57,4) != substring(./line[13], 57, 4) is described below:
The right side of the comparison is: substring(./line[13], 57, 4) this extracts the document number which is found in line 13 position 57 to 60 and that is compared with the document number found on the next page, which is found with this expression: substring(following-sibling::page[1]/line[13],57,4)
The inner part of this expression is: following-sibling::page[1]. This expression extracts the contents of the next spooled file page. With the addition of /line[13] the contents of line 13 of this next page is extracted, so that explains the expression: following-sibling::page[1]/line[13], which is the first parameter of the substring() function, which extracts position 57 to 60 with the other parameters: 57 and 4.