Progress and Postscript Printing

This document describes the steps to follow to produce nicely formatted reports from within your Progress application. Although the examples given are using Progress, there is nothing here that is particular to that language. The key to the process is the use of postscript. Mayura Draw produces files that are easily edited, perl provides a scripting language with the necessary capabilities and Progress is the driving application.

There is no dependency on Unix, although that is all we have used. With minor changes to pdx2ps it would probably work on any platform on which perl is available.

Contents

Overview
Postscript Form Generation
Conversion
Application Requirements
Document Conversion
Forms Printing
Document Previewing
Limitations
Links
Download
Contact Us

Overview

The basic process is to create the form in Mayura Draw, convert it to generic postscript using the perl script pdx2ps and then write the Progress procedure to use it. Every step is simple and no knowledge of postscript is required other than what is presented here. The level of Progress knowledge needed is minimal.

The method is almost identical to the definition of a form in postscript that can be stored in the memory of a printer and called by your postscript code when needed. However, we print lots of different documents and so this was not the best option.

We have used the term variable in connection with postscript in this document since that will be familiar to Progress programmers. Technically the correct term is definition, since what we are doing is adding a definition to the interpreter’s dictionary (nothing to do with Progress’ dictionary).

Postscript Form Generation

Using Mayura Draw, create the required form. For the places where you want to put data from your application, enter a text string in the required font beginning with the characters “pdx-”. pdx2ps looks for this sequence of characters, strips them off and replaces the string with a postscript definition, or variable, named the same as the remainder of the initial text string. The following image shows an example from a form.

Mayura Draw Sample

In the above example, the form would allow data to be placed in variables named requested-by, req-addr1, req-addr2, req-addr3, req-addr4, req-phone, req-fax and valid-date.

All variables must be entered as a separate text string and they must be the first item in the string. They cannot be part of a sentence, although groups of them can appear together. In the example, the req-addr group was entered as a text object with each line separated by a new line. This is because pdx2ps looks for the sequence (pdx- at the start of a line, which is the case for text entered by itself, but not if it is part of a larger string. The format of the pdx files forces this and is the key to the method’s operation.

If you entered “Item pdx-item cannot shipped” in a form, you would not be able to insert data into a variable called item.

It is important to remember that any positioning of text applies to the text typed on the form at the time of creation. This means you cannot have justification of a variable length string if you have selected a proportional font, since the position is based on the text entered on the form. The workaround is to use a fixed pitch font and justify it yourself in your application.

Conversion

Before you can print the form you must convert it using pdx2ps. The usage of pdx2ps is:
pdx2ps -i input-file -o output-file
This script creates an output file with the Mayura Draw font names changed to normal postscript names, all identified variables stripped of their leading pdx- characters and two postscript procedures defined. It also adds some code to print a message across the bottom of the page.

The first procedure created by pdx2ps is called reset-names and simply sets all the variable values to blank. Having this allows the Progress procedure to only produce the required name/value pairs rather than the complete list.

The second procedure is called display-page and this needs to be called for each printed page required. This procedure draws all the elements on the page and prints the data stored in any defined variables.

The message on the bottom of the page is useful in a development or test environment where it is important that the resultant files should not be confused with documents from the production system. The default is to print the word VOID in 200 point outline, but the text can be overridden by redefining the postscript variable message in the output file as follows:

/message (Test) def
In a production environment the message definition should be set to blank to prevent the text being displayed on each page. Do this as shown below:
/message () def

Application Requirements

This section will describe the format of the application generated data file.

The basic format is as follows:

% Comments
%%Page: page-name sequence-num
reset-names
/token-name (value) def % any number, including none, of defined names
display-page showpage
%%PageTrailer
Let's look at this file line by line.

I suggest that the first line in each generated file be a comment line containing some text saying how it was generated,  what it is for, whatever, but this is only if you need to do any sort of debugging of your application. A % sign introduces postscript comments. You must comment each line if more than one is used.

The second line shown is an attempt at supporting Adobe's Document Structure Convention (DSC). This is a convention used to allow structure information to be gleaned from a file. This is not relevant for a printed file, only for displaying it using something like gsview. Page-name is the name of the page and sequence-num is a number indicating the order in which to display the pages. Normally these two numbers would be the same.

The next line calls reset-names, one of the functions defined when pdx2ps is run. Failure to call reset-names will leave the last definition of your variables on the interpreter’s stack. This may be what you want in some situations, especially if a lot of data is being reproduced on each page without change.

Next, each of the required variable definitions should appear, one per line, with a leading /. token-name is the variable name you want to use. These strings are case sensitive. If in doubt as to what the forms designer used look in the main postscript file for the reset-names procedure and all defined variables will be listed there. The value to display appears between parentheses followed by def. If your application does not print properly, this is the first place to start looking for the cause of the problem. Escape sequences for certain special characters are shown in the following table.
 
 

Sequence
Meaning
\\ Backslash
\( Left parenthesis
\) Right parenthesis
\ before a newline Allows you to break a string across two lines without inserting a newline into the string. That is, the string:

(This is a\
string \
that has no \
newlines)

is equivalent to the string:

(This is a string that has no newlines)

WARNING: you cannot use array syntax in your variable names. This means that variable[n] where n is an integer is not allowed.

After all the variables have been defined you must then call the second function added by pdx2ps, display-page. You must then call showpage, which is the postscript operator that causes output to be viewed on the output device, in this case a printer.

The last line is %%PageTrailer which is part of the DSC.

The following is a sample from one of our reports.

%%Page: 1 1
reset-names
/order-num (W274173) def
/your-ref (Quote 22/2/99) def
/date-raised (27 Feb 1999) def
/date-due (ASAP) def
/contact-name (Peter Bisset) def
/contact-phone (61-7-3247 8553) def
/contact-fax (61-7-3247 8560) def
display-page showpage
%%PageTrailer
Be aware that this technique prints the same form on each page. To produce multiple pages using the same form, just repeat the above sequence with the new variable values, making sure you increment the page number and sequence number values.

Concatenating the converted file with the application generated data file and the small trailer file called pdxtail.ps makes a complete postscript document. In Unix this is simply:

cat pdx2ps-output generated-output pdxtail.ps > final-file
The file final-file is a postscript file that can be printed or viewed.

If the first page is different to subsequent pages then you simply need to follow the same process with one small change. Mayura Draw doesn’t handle multiple pages so simply make each page as a separate document.

Convert each of the forms for the different pages. Now simply concatenate them with the relevant data file. Finally, append the pdxtail.ps file. For example,

cat file1 data1 file2 data2 data3 data4 pdxtail.ps > final-file
This will produce a four-page document with a single copy of page one (file1) and the data from data1 placed on it and three pages using the form contained in file2 with data from data2, data3 and data4 placed on each page.

Document Conversion

This section describes what to do to allow printing on printers that don't have a postscript interpreter. Basically you need to convert your postscript output to the format supported by your printers. One way of doing this that works very well is to use ghostscript. At present we have only tested HP LaserJet printers, all with level 2 interpreters and PCL. I will describe what we do and it may help you design your own solution.

Our application looks at the database record that contains details of the printer at a destination to see if it allows printing of forms. There is a logical field in the record that indicates whether this is a destination that can print forms. If it is we then look at another logical field to see if this printer supports postscript. If it doesn't then we use a character field in the same record as a value to pass to a script called psconv. This script simply calls ghostscript to convert the postscript file to another format with the contents of this character field used to specify the -sDEVICE argument for ghostscript. The syntax for psconv is:

psconv gs-device input-file output-file

Forms Printing

We also have the facility to print blank forms on demand. This removes the need to send Word documents to people who request different documents that must be completed by hand. The form needs to be in postscript format. If it is designed using Mayura Draw, then running fixpdx on the file will convert it to vanilla postscript. If the destination does not support postscript it can be converted as described above.

If you have documents done in something like Word or Excel, then the best way is to use the Adobe Postscript driver for Windows and direct the output to a file. This file can then be printed directly to a postscript printer without any preprocessing. If you can't get the Adobe driver then the Apple Laser Writer driver provided with Windows produces good postscript. Look at the output from a Windows driver to see why Mayura Draw makes the job easier.

Document Previewing

It is useful to be able to preview documents rather than printing them. This is possible using ghostscript and its associated viewer, gsview. This software is available for a large number of machines including Win32.

Limitations

The scripts pdx2ps and fixpdx do not include lines to convert all of the Mayura Draw fonts to standard postscript names. If you need to support different fonts it is a simple matter of adding the substitution command to the scripts. I have included a simple little postscript program fontlist.ps to print out the list of available fonts in a printer. This was written by Michael Luxton, who does not claim to be a postscript guru.

We only print to A4, however it is simple to change the scripts to support different page sizes. Simply select the relevant paper size from the table below and alter the setpagedevice call in the conversion scripts. This table includes the more common paper sizes.
 

Point Size Paper Size
[522 756] Executive
[612 792] Letter
[612 1008] Legal
[595 842] A4
[842 1191] A3
[297 684] Com 10 Envelope
[312 624] DL Envelope

Links

Mayura Draw 
Ghostscript & GSview
Progress Software

Download

psconv shell script that calls ghostscript to convert postscript files
pdx2ps perl script to convert a Mayura Draw file to one that can take data
fixpdx perl script to convert a Mayura Draw file to generic postscript
pdxtail.ps postscript file to add to the end of a form
dummy.ps dummy placeholder file to use for testing. Simply cat output file, dummy and pdxtail.ps.
sample.pdx a sample Mayura form showing how to specify places for data
ransom.ps this is as close to fun as you can come with postscript :-)
fontlist.ps some postscript code to list the fonts available in a printer (even works on an HP 4MV and gsview)
thelot.zip everything above, including this page.

Contact

Let me know of any problems in the scripts or if you have any questions or suggestions for improvement .

Peter Bisset: pbisset@emergency.qld.gov.au

Page Last Updated: 17 November 1999