crazyinsomniac has asked for the wisdom of the Perl Monks concerning the following question:

'sup y'all,

I just got a Dot Matrix printer from a friend, because i wanted to make .matrix music :), and thought let's give it a shot in perl(printing that is).

So i look at some docs, talk to somebody, and bam:

open(PRINTER,">LPT1:") or die "Can't write to LPT1: $!\n"; print PRINTER " HOLY SCHNIKES, I'M A PRINTIN'\!\n"; close(PRINTER);
So i say to myself, "That's cool, now how do i print an image?" Well i thought maybe:
open(PRINTER,">LPT1:") or die "Can't write to LPT1: $!\n"; print PRINTER " HOLY SCHNIKES, I'M A PRINTIN'\!\n"; print PRINTER "Content-Length: $gifsize\n"; print PRINTER "Content-type: image/gif\n\n"; open(GIFIMAGE, "$gif"); while (<GIFIMAGE>){print PRINTER; }; close(GIFIMAGE); close(PRINTER);
That didn't work, so i took of the header, still not what i wanted. So i get on the pm chatterbox, and Macphisot says try binmode FILEHANDLE, didn't work(w or w/o the header). Tye also had some suggestions, but i'll let him post an example here;)

So my questions for you guys are:
    How can i print an image directly to my printer?
    How about 'printing to a file'(*.prn)?
    How can i access/interface the printer(printing device driver)?
    And last, but not least,
    what is the pagebreak character in perl('U @' or in hex '1B 55 00 0C 1B 40' worked for my panasonic .matrix)?

"cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                      - crazyinsomniac

Replies are listed 'Best First'.
Re: PRINT AN IMAGE TO LPT1
by AgentM (Curate) on Nov 18, 2000 at 04:21 UTC
    Instead of hacking this yourself and getting it wrong, you might try setting up an lpd daemon to interact with the printer in between. Then you can use Net::Printer or LinePrinter without problems. Dot Matrix printers (as far as I know) never accepted HTML headers or PostScript (I found it amusing that you actually tried that :o). Depending on its age, it will use some obscure code that you won't find anywhere or on some Russian guy's web page who spent two years of his life reverse-engineering his printer (?). The only solution is to be happy with text or interact with the printer drivers in some manner. Also, you might even get to make an "older form of anti-aliased" text simply by using the drivers instead. lpd is the only thing that would make sense.... have fun.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      Wouldn't it be kind of nifty to have a printer that spoke HTTP though? I've seen some that did FTP (you'd FTP your job to the printer, and off it'd go) and lpd natively. HTTP should be quite capable of accepting a POST or a PUT request...
        This reminds me. Most people don't know it, but PostScript is actually a full-fledged programming language, and a PostScript document is actually a program that causes the printer to print the desired document.

        Just to demonstrate this, a PostScript printer is a computer with an operating system written in PostScript. If you send it the right document, you can actually reprogram the printer. This will only work if you know how to program in PostScript (there are books) and if you know the correct password (there are well-known defaults).

        So you could write your own http server if you wanted!

        BTW have you secured your PostScript printer lately?

        I'd imagine that keeping the printer drivers up to speed on the HTML "standards" would be more difficult than converting the whole shebang into PostScript in the first place:o) i.e. it might be nifty but entirely undpendable. lpd is reliable and easy to use- I see no excuse not to use it. While I agree it might be amusing, it wouldn't be much more than that.... Update: Oh. sorry, I read it too quickly. But I still disagree. Implementing a full-blown HTTP server wouldn't be too slick either- it's better to go through drivers. Such a server would completely complication any user authentication...
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      Watch out for that condescending thing... I find it amusing that you suggest lpd could print to a dot-matrix. lpd only deals in postscript. I had to toss my dot matrix when I went Linux, but I haven't looked back.

      ____________________
      Jeremy

        Now I know that's not true at all. lpd handles any printer considering that a driver is available for it. I know this because I have used several OLD printers which I know never supported PS. lpd interacts with the drivers and does nothing else except to block on printer requests which then interacts with the driver appropriately.
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      You thought that was funny, so did i, but it can't hurt to try. Anyway all i am running is ActiveState's ActivePerl on a win98 machine. I am not running any kind server much less a print one.

      The two modules you mentioned look like the same thing, and they also say "Please note that this module only talks to print servers that speak BSD." if that's of any significance to you. Like i said what i'm interested in more is interfacing to the printer(pdd) so i can make api calls 'n such.

      "cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                            - crazyinsomniac

Re: PRINT AN IMAGE TO LPT1
by jepri (Parson) on Nov 18, 2000 at 19:47 UTC
    Oh boy, you guys are really making me feel old now. We used to screw around with this stuff some..

    Basically it takes bitmap images of some form. IIRC correctly, you send it bytes, and it puts a dot if it gets a '1', and leaves a space if it gets a '0'. That's why the heads come in multiples of 8... You'd send it a byte at a time and it could fire up to eight heads at the ribbon. They have buffers big enough for one line, but the later ones could stop the print head halfway across a line and come back.

    Contrary to what the youngbloods here say, the codes for it should be quite easy to find. The manuals usually have very detailed descriptions of how to put the printer into different printing modes (you have to switch to graphics mode, otherwise it interprets each byte as an ASCII character), and often how the printer accepts bytes. I realise you won't have a manual, but check the nostalgia sites on the web.

    This is why postscript printers are soooo worth the money.

    ____________________
    Jeremy

      Yep, we old-timers often wrote bitmaps to dot-matrix printers. Fortunately most dot-matrix machines had a pseudo-standard interface usually called Epson compatibility (does Epson even exist now? - they were the KINGS of printers for a long time...). One could as jepri says print a bitmap with a little effort. Naturally you must decode the graphic file format first, then map the colour info to B&W, but that's old hat. If you can't find manuals on dot-matrix printers on the net, I'm sure to have a few exmples in my, uh, collection.

      I should also mention that the later 24-pin printers had quite a decent resolution, and IIRC early Ghostscript could do decent postscript on them too. Of course if you want the output the same day, that's where a real postscript printer comes in!