Omnis Technical Note TNPR0005

The Page Setup when printing in Omnis

For Omnis Studio
By Rudolf Bargholz

The following describes how Omnis handles the page setup when printing.

There are a few page setup properties that can be changed while printing a report:

$scale $copies

The most interesting of these properties is $orientation. What happens if you explicitly wish to print the fifth page of your report in landscape format, the rest in portrait? To understand how this works we have to look at how Omnis can handle so-called page setups. These page setups contain the information above, which includes $orientation.

Page setups can be divided into two groups, those associated with the report class and those associated with the printer chosen. Report page setups can be viewed in the properties of a report, in the 'Page Setup' tab. Printer page setups can be viewed in the Printer Settings under Properties.

Omnis tries to be as flexible as possible in the use of page setups and has a specific logic that allows
one to mix and match these page setups with different reports:

1) When you start Omnis and print a report, the page setup of the default printer will automtically be loaded. So if you have your default printer (using the printer properties) set to print all pages in landscape format, all pages will be printed as landscape.

2) If you use the command 'Select printer', explicitely specifying the parameter 'Discard previous settings',

Select printer (Discard previous settings)
  {HP LaserJet 5000 GN PCL 5e,FILE:}

Omnis will load the page setup of that specific printer, i.e. the settings entered under the properties of that printer. For example, you could define two printers using the same printer driver, one printer would print to Tray1, the second to Tray2. If the first and third pages of the report are to be printed to Tray1, the rest to Tray2, you could print the report twice, once to Printer1, setting $root.$prefs.$pages to "1,3", next to Printer2 setting $pages to "2,4-[#P]". For each report the settings defined for the printer would be used.

3) You can explicitly load the page setup of a report using the command 'load page setup'. As mentioned above, this is set in the properties of the report class. Note that this page setup will be used in the printing
of all following reports, until a new page setup is loaded or the page setup of a printer is loaded as described in 2) above. The code below uses the page setup of the report:

Set report name r1
Load page setup
Send to printer
Select printer {HP LaserJet 5000 GN PCL 5e,FILE:}
Print report

4) You can also dynamically change the orientation of the report pages, WHILE printing the report.
For example, say you have defined a positioning in your report that prints a table of information, that can only be viewed correctly when seen in landscape format. The above method described in 3) would not help here, as one would not necessarily know beforehand which page would have to display the table.
To be able to dynamically react to the printing of the table one would have to overwrite the $print method of one of the sections of the report. The following code could be used in the $print method of the page footer, assuming a flag is set when the printing of the table is to take place

$print method of the page footer:
Switch bTableFlag
  Case kTrue
  Calculate $cinst.$orientation as kOrientLandscape
  Case kFalse
  Calculate $cinst.$orientation as kOrientPortrait
End Switch
Do Default

This will print the first page using your page setup, the second page explicitly in landscape, the following pages in portrait

Note that this will affect the orientation of the next page that is to be printed, which is the reason why the code is placed in the page footer.

The above explanation indicates why some reports are not printed correctly when one uses the context menu in the class browser to test the printing of the report. Many programmers do not take into account current page setup and expect the current report to print using it's own page setup data. This information might not be loaded at all (see 1) above or the page setup of another printer might be loaded. Only an explicit 'Load page setup in the $construct of the report would load and use the settings for that report.

Another point to remember is the 'job setup' with which it is possible to determine the tray to which the
first page is printed as well as the tray to which the other report pages are printed.

On evClick ;; Event Parameters - pRow( Itemreference )
  Set report name r1
  Send to printer
  ; this is no longer necessary from version 2.0 onwards
  Prepare for print (Ask for job setup) {r1}
  End print

As mentioned above, Omnis tries to be as flexible as possible in the use of page setups. If you always
use the settings of your default printer you would not have to worry about using page setups. If you
have printer drivers set up to different trays or different printers, you can handle this situation also.
More flexible solutions are also possible.

Search Omnis Developer Resources


Hit enter to search