Printing data
You
can use a DataStore to print data on a remote server if the server
is running on Windows or Solaris.
Platform note The following example
would not work on HP-UX or AIX. On these platforms, EAServer uses a windows-free version
of the PowerBuilder runtime environment that does not provide support
for graphical operations such as printing. Printing using DataStore
print functions is currently supported only on Solaris. However,
DataStore objects can be printed on all UNIX platforms using the SaveAs function
with the PDF SaveAsType.
For more information, see “Printing to PDF”.
In this example, the server component uo_employees has
a function called print_employees. print_employees generates
an instance of the DataStore ds_datastore,
and then prints the contents of this DataStore.
Here is the signature of the print_employees function:
1 |
print_employees( ) returns integer |
Here is the script for the print_employees function:
1 |
datastore ds_datastore<br />int li_rc<br />ds_datastore = create datastore<br />ds_datastore.dataobject = "d_empdata"<br />ds_datastore.SetTransObject (SQLCA)<br />ds_datastore.Retrieve()<br />li_rc = ds_datastore.Print()<br />return li_rc |
Printing on the Solaris operating system
On Solaris, you
can print directly to a PostScript or PCL5 file. You do not need to
make any code changes to print reports on Solaris instead of Windows—you can
use the same properties, functions, and events as in Windows.
To print DataStores, use the DataStore Print method
or PrintDataWindow(PrintJobName, DataStoreName).
If you link a DataStore to a DataWindow and print the DataWindow
object on Solaris, the printed output has the fonts and layouts
defined in the DataWindow object.
Blank spaces A blank space is not supported in a print job on Solaris,
so the PBVM substitutes a hyphen for each blank space in a print
job name before sending it to a printer.
Using fonts
The fonts used in printing are those provided in the dwprinter/fontmetrics directory.
AFM and TFM files are ASCII formatted files that contain information
about specific PostScript (AFM) and PCL (TFM) fonts. Each PostScript
and PCL font has a corresponding font metric file.
The print mechanism reads AFM and TFM files to acquire font
metric information. This includes such things as character widths,
baseline location, ascender size, descender size, underline stroke
width, and underline position. It then translates this metric information
into the formats expected by Xlib APIs such as XTextWidth.
The best approach is to select fonts that are available on
both Windows and Solaris when you design the DataWindow. However,
each platform has its own font-rendering engine, so you might notice
differences in the sizes of fonts between Windows to Solaris. You
should test the printed output on Solaris early in the development
process.
Limitations
Support for printing DataWindow objects is based on the Wind/U
product from Bristol Technology. The Wind/U GDI library
and Xprinter library have the following limitations:
- No support for multibyte character sets (MBCS) or Unicode
- Xprinter is not thread safe, therefore print jobs
are serialized
Setting up a printer
To set up a printer to
print DataWindow objects, you must add access to the printer, set
up the dwprint.ini configuration file, and
create an XPPATH environment variable.
Adding access to the printer
As the root user, add access to the printer on Solaris using
the Solaris admintool utility. For more information,
see the Solaris documentation.
Setting up dwprint.ini
The dwprint.ini file in the $EAServer/bin directory
is the configuration file for DataWindow printing. It closely follows
the Microsoft Windows approach to printer configuration. As a result,
it includes [windows], [devices],
and [ports] sections where you must provide appropriate
entries for your printers.
You usually do not need to modify other sections in this file.
However, some problems can be resolved by adding or changing other
sections. For example, you can try adding an entry like the following
to the [intl] section to change a date format:
1 |
[intl]<br />sShortDate=m/d/yyyy //Set the year to 4 digit. |
The entries in dwprint.ini are based
on entries in the .WindU file. For more information
about setting up this file, see the Wind/U User’s Guide
Specifying ports
Each line in the [ports] section of dwprint.ini contains
a user-defined port name and an associated command that is used
to spool the output file. For example, the command to send a print
job to a printer called myprinter connected
directly to your system is:
1 |
lp -s -d myprinter -t$XPDOCNAME |
$XPDOCNAME represents the name of the output file
sent to the printer. The -s option suppresses
the display of messages sent from lp in the EAServer Server console.
The following is an example of the [ports] section
of the dwprint.ini file with two ports defined
for remote printers called prnt1 and prnt2,
one for a local printer, and an entry for printing to a file. The
name of the output file is enclosed in quotes. This enables file
names with multiple words to be used. The quotes must be escaped
for remote servers because rsh strips them out:
1 |
[ports]<br />colorpr1=rsh prntsvr lp -s -d prnt1 -t"$XPDOCNAME"<br />colorpr2=rsh prntsvr lp -s -d prnt2 -t"$XPDOCNAME"<br />LOCAL=lp -d myprinter -t"$XPDOCNAME"<br />FILE: = |
Matching a printer type to a defined port
The [devices] section contains a list of
all currently configured printers. Each line contains a user-defined
alias for the printer and three arguments: the printer model, the
printer mode (PCL4, PCL5, or PostScript), and one or more ports to
which the printer is connected.
The printer model is the name of the printer description file
(PPD) used by the printer. PPD files are installed in the dwprinter/ppds directory
in your PBVM installation. The text file filename_map.txt in
that directory maps the name of the file that contains the printer
description to the type of printer. For example, these are the mappings
for the color_lj model used in the
rest of the examples:
1 |
color_lj.pcl:"HP Color LaserJet PCL Cartridge"<br />color_lj.ps:"HP Color LaserJet PS" |
The printer model and mode are separated
by a space. The mode and port are separated by a comma. For example,
for the first device specified in the following [devices] section,
the alias is HP Color LaserJet PS, the model
is color_lj, the mode is PostScript,
and two ports are specified: FILE: and colorpr1.
1 |
[devices]<br />HP Color LaserJet PS=color_lj PostScript,FILE:,colorpr1<br />HP Color LaserJet PS=color_lj PCL5,colorpr2<br />HP Color LaserJet PS=color_lj PostScript,LOCAL<br />HP LaserJet PS=NULL PostScript,FILE:<br />HP LaserJet PCL=NULL PCL,FILE: |
Specifying a default printer
The [windows] section contains default printer
information. Like the ports specification, each device line has
three arguments: the name of the PPD file, the driver, and the port,
but in the [windows] section they are all separated
by commas.
The following example shows a default entry for printing to
a file (when the printer file description is set to NULL)
as well as two other entries. The semicolon at the beginning of
two of the lines is a comment character, so the current default
printer is the HP Color LaserJet printer on the port colorpr1.
1 |
[windows]<br />device=color_lj,PostScript,colorpr1<br />;device=color_lj,PostScript,colorpr2<br />;device=NULL,PostScript,FILE: |
Setting printer options
The dwprint.ini file must contain a configuration
section for each model you have defined in the [windows], [devices],
and [ports] sections. The configuration section
provides default setup information for the printer, including the
number of copies, orientation, page size, and DPI.
For example, for the color_lj printer
used in the preceding examples, add configuration sections like
this:
1 |
[color_lj,PostScript]<br />Filename=jaguar.ps<br />Scale=1.00<br />Copies=1<br />Orientation=Portrait<br />PageSize=Letter<br />DPI=300<br /> <br />[color_lj,PCL5]<br />Filename=jaguar.pcl<br />Scale=1.00<br />Copies=1<br />Orientation=Portrait<br />PageSize=Letter<br />DPI=300 |
Setting the XPPATH environment variable
Before you start a print job, set the XPPATH environment variable.
The XPPATH variable must contain the path to a directory that includes
printer description files and printer-specific font mapping files.
This information is installed in the dwprinter directory in your
PBVM installation.
For a C shell, set the path as follows:
1 |
setenv XPPATH $EAServer/dwprinter |
For a Korn shell or a Bourne shell, set the path as follows:
1 |
XPPATH = $EAServer/dwprinter;export XPPATH |
Printing to PDF
You can use two techniques to save the data in a DataStore
to PDF: Using the GNU Ghostscript distiller, and using the ability
to process data using XSL Formatting Objects (XSL-FO). You can save
the DataWindow object’s data to XSL-FO or PDF, and print
using Java printing.
Using the GNU Ghostscript distiller
To use the GNU Ghostscript distiller, you must make sure that
Ghostscript files and the default PostScript printer driver and
related files are installed on the server in the same directory
as the PowerBuilder runtime files. The Ghostscript method is not
supported on UNIX.
Using XSL-FO
To use XSL-FO, the Apache XSL Formatting Objects processor
(FOP) must be installed on the server in the same directory as the
PowerBuilder runtime files, and the following JAR files must be
in the classpath:
- fop-0.20.4uildfop.jar
- fop-0.20.4libatik.jar
- fop-0.20.4libxalan-2.3.1.jar
- fop-0.20.4libxercesImpl-2.1.0.jar
- fop-0.20.4libxml-apis.jar
- fop-0.20.4libavalon-framework-cvs-20020315.jar
You can add these files to the CLASSPATH environment variable
or to User_setenv.bat or Serverstart.bat.
When you use XSL-FO with EAServer to produce a PDF file, detailed informational
and warning messages are written to the Jaguar log. To suppress all
these messages, set the PB_FOP_SUPPRESSLOG environment
variable to 1.
For more information, see the chapter on enhancing DataWindow
objects in the PowerBuilder User’s Guide
.