× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Mon, 24 Oct 2005, Simonse, Arco (CMK) wrote:

James Rich wrote:

Our fax solution is also hylafax on linux, and it works wonderfully.

Yes it's a very good solution. We use it over 2 years now in our PC
network.
And since last month I interfaced our 400 via FTP to Hylafax.

We've been using the gnu.hylafax java interface for communicating with hylafax from our RPG programs. I have to say, I have been very impressed with hylafax and gnu.hylafax.

Because we want to email, print, and fax documents, our
choice has been to use postscript.  We have postscript
printers which are cheaper than IPDS printers.  Postscript
converts easily to pdf.  For email we have an out queue
connected to lp5250d (from the tn5250 project) which converts
postscript to pdf on the fly.  The resulting pdf is placed on
our file server for easy attachment to email.  And of course
hylafax faxes postscript documents with ease, so no troubles there.

I'm very curious how that conversion works! Can you give an example?

Sure, here is part the the .tn5250rc config file that I use with lp5250d to convert postscript to pdf automatically:

pspdf {
        host = ssl:as400.mydomain.com
        env.DEVNAME = PSPDF
        +ssl_verify_server
        ssl_ca_file = /path/to/cert
outputcommand = scs2ascii > /tmp/output.ps ; ps2pdf /tmp/output.ps /home/username/pspdf.pdf
}

The line that begins with "outputcommand" is all one line until the closing }. Then any postscript file sent to the PSPDF out queue will automatically be converted to a pdf and placed in /home/username/pspdf.pdf. The user can then copy the pdf file or rename or attach it or whatever. The potential downside is that if /home/username/pspdf.pdf already exists it will be overwritten. There are way around this, see the TN5250 HOWTO for more examples (http://www.chowhouse.com/~james/tn5250-HOWTO.pdf).

At this moment I have not any experience with PS other than what I
readed about it last night.
So I don't have criteria to decide if it is worth to learn postscript.
I would be very happy if you would be so kind to share some examples.
What you and Rich Duzenbury are telling me sounds as good way to go.

Almost everything I know about postscript I learned from this very simple introductory page:

http://www.cs.indiana.edu/docproject/programming/postscript/postscript.html

For fancy post-processors to work you have to follow certain conventions, but otherwise those conventions aren't necessary. Just in case it is useful, here is an abbreviated example and code from my postscript programming:

First I start with an "overlay". It isn't really an overlay, but rather a text file containing the postscript code to generate what in AFP parlance is called the overlay. Here is a short example:

<begin overlay.ps>
%!PS-Adobe-3.0
%%Creator: PSPRTIR
%%Title: (Invoice)
%%Pages: (atend)
%%EndComments

%%BeginProlog
%% define a function that converts inches to postscript main unit (1/72 of
%% an inch)

/inch {72 mul} def
%% Then I have a bunch more definitions that I'll skip
%%EndProlog

%% do the logo
/Times-Bold findfont
24 scalefont
setfont

newpath
1.675 inch 10.5875 inch moveto
(The Company Name) show

%% do the main header of the page
%% complete the sold to box
newpath
0.25 inch 0.25 inch moveto
0 inch headboxestop rmoveto
2 inch 0 inch rlineto
0 inch 0 largebox sub rlineto
-2 inch 0 inch rlineto
0 inch 0 largebox add rlineto
drawbox
newpath
0.25 inch 0.25 inch moveto
0 inch headboxestop rmoveto
2 inch 0 inch rlineto
0 inch 0 largebox sub rlineto
-2 inch 0 inch rlineto
0 inch 0 largebox add rlineto
stroke

/Times-Bold findfont
14 scalefont
setfont

newpath
0.25 inch 0.25 inch moveto
0 inch headboxestop rmoveto
0 inch 0 largebox sub rmoveto
0.375 inch 0 bottomtextspace add bottomtextspace add rmoveto
(SOLD TO:) show

%% Then I include enough postscript code so that I can view the results
%% with gs (ghostscript) or something similar.  But all of the following
%% code must be deleted before "installing" this "overlay" or else you
%% will get the "overlay" on one page and all your data on another!
%% delete everything after and including this comment
(1) show
showpage

%%Trailer
%%Pages: 1
%%EOF
<end overlay.ps>

I use ftp to put this file somewhere sensible in the iSeries. I like to use /var/lib/overlays. So I use ASCII mode in ftp to put this file in /var/lib/overlays/overlay.ps (I have several "overlays" in /var/lib/overlays).

Then my RPG code is structured to work similarly to a normal externally defined print file that uses USROPN. In place of the OPEN opcode I have a procedure called start_new_page() which opens a new postscript file in /tmp and copies the contents of /var/lib/overlays/overlay.ps into it on the first call. start_new_page() returns a file handle that I use in all the rest of my postscript calls. The PR specs for start_new_page() look like this:

Dstart_new_page   PR            10I 0
D fdoutput                      10I 0
D outputfile                    50A
D pagenumber                     6S 0 VALUE
D overlay                       30A   VALUE

The first time I call start_new_page() looks like this (this is the equivalent of the OPEN opcode and a WRITE to the header record format):

/free
  pagenumber = 1;
  printfile = -1;
  printfile = start_new_page(printfile:
                             tmpfilename:
                             pagenumber:
                             overlay);
/end-free

Setting printfile equal to -1 indicates to start_new_page() that no output file has been opened yet so it should create a new one with the name specified in tmpfilename using the overlay specified in overlay. start_new_page() returns a value less than zero if there is an error, otherwise printfile contains a file handle. Subsequent calls to start_new_page() are identical except that you don't reset printfile and you increase pagenumber by one. Every call to start_new_page() is the equivalent of doing a WRITE to a print file header record format. A key difference is that there is no overflow indicator, so you must track that yourself.

I know I just said that calling start_new_page() is the equivalent of doing a WRITE to a print file header record format, but what it really does is creates a new blank page for you to write on (that includes the "overlay"). So after calling start_new_page() I call another procedure to write the equivalent of the text data that would appear in a print file header record format. That procedure is called (surprise!) print_header(). The PR specs for print_header() look like this:

Dprint_header     PR                  LIKE(ERA_errno)
D printfile                     10I 0

Here ERA_errno is a variable we have defined on our system for use as returning error information. The print_header() procedure usually consists of simply a bunch of calls to other procedures that do the actual placement of the postscript code. Here is an abbreviated example:

Pprint_header     B
Dprint_header     PI                  LIKE(ERA_errno)
D printfile                     10I 0
 /free
   err = print_po_date(printfile:currentdate);
   err = print_po_orddate(printfile:PHORDDATE);
   err = set_font_detail(printfile);
   return SUCCESS;
 /end-free
Pprint_header     E

This prints three things on the page: the current date, the date stored in the purchase order header file, and some postscript code to change to the font we will use for the detail lines. I have similar procedures for each data item I want to print. These procedures though numerous are quite simple. They simply write to the file the appropriate postscript code to place and print the text. An example might look like this:

Pprint_po_date    B                   EXPORT
Dprint_po_date    PI                  LIKE(ERA_errno)
D fd                            10I 0
D date                            D   VALUE
D*
Dbuffer           S            132A
Derror            S                   LIKE(ERA_errno)
 /free
   buffer = 'newpath';
   error = write_to_file(fd:buffer);
   buffer = '0.25 inch 0.25 inch moveto';
   error = write_to_file(fd:buffer);
 /end-free
C     *usa          move      date          chardate         10
 /free
   buffer = '(' + chardate + ') show';
   error = write_to_file(fd:buffer);
   return SUCCESS;
Pprint_po_date    E

In this example, the write_to_file() procedure writes the contents of buffer to the file pointed to by the file handle fd. I've left error checking out of this example for simplicity.

An important thing to keep in mind is that (, ), and \ have special meanings in postscript so you must escape these characters by prepending a \ to them. I wrote a simple procedure to do just that and I use like this:

 /free
   name = escape_char(name:'\');
   name = escape_char(name:'(');
   name = escape_char(name:')');
   buffer = '(' + %trim(name) + ') show';
   // etc.
 /end-free

escape_char() looks in parameter 1 for the character specified in parameter 2 and prepends a backslash.

Once the header is written I use a very similar technique for the detail records. I run a loop to read the detail file and then call a procedure to print a detail line, passing the current line number so the postscript code can place it for me. Once my line counter exceeds the limit for the number of lines that fit on a page, I call finish_page() which puts the postscript code to finish a page, followed by start_new_page() and print_header() again, increment my page counter, and reset my line counter. When I am all done processing my document, I call finish_page() passing a parameter to indicate to close the outputfile.

At this point I have a completed postscript output file. I can pass this file to gnu.hylafax for faxing or copy it to a spooled file for printing. If I want to convert it to pdf I would copy it to a spooled file and send it to one of my ps2pdf lp5250d out queues.

I hope this is useful.

James Rich

It's not the software that's free; it's you.
        - billyskank on Groklaw

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.