[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Printing to a LaserWriter



Sean Carte writes Wed, 28 Apr 99 12:51:14 +0200:

>How would I go about printing to a LaserWriter?
>
>Following the example in _MPPE_, pp108-9, I can print an isosceles
>triangle, but that's it.
>
>Can I only send postscript to the printer using:
>  open(STDOUT, '>Dev:Printer');
>or is there some way I can send ascii text as well?

Yes, LaserWriters will only accept PostScript. By far the simplest means of
sending text from MacPerl to a PS printer is to use MacPerl to write
PostScript.

For example suppose you have the ASCII text in an array '@ascii' in which
each element is a line of text (with no newline character). The following
would print the text in 12pt. Helvetica:

    #!perl

    $x_pos = 72;    # set margin
    $y_pos = 757;   # PS origin is top left corner of page

    open(OUT, ">Dev:Printer");

    print OUT "/Helvetica findfont 12 scalefont setfont\n";  #set a font
    foreach (@ascii) {
        print OUT "$x_pos $y_pos moveto\n";    # move to line start position
        print OUT "\($_\) show\n";             # print the line
        $y_pos -= 14;                          # leading
    }
    print OUT "showpage\n";

By writing the PS you have full control over the page and can for instance
alter font styles, justify lines of text, control paging, put headers and
footers and just about anything else you have a mind to do.

If you need it, the PostScrip Reference Manual is on-line at Adobe's site:

        ftp://ftp.adobe.com/pub/adobe/devrelations/

If you want an example of a more complex MacPerl/PostScript application
have a look at "pod2ps".

Alan Fry



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org