Does net::lpr work with win32::printer?

ralphs1961
ralphs1961 used Ask the Experts™
on
Hi,

I have an interesting problem.  I need to be able to print to printers across a vpn network.  I have set up windows drivers for the printers which are all okidata ml320 turbos.  using win32::printer to format the output I am able to  print results on various printers.  However with the ml320s they only print in nlq.  this is way to much ink.  

Unfortunately I read somewhere that win32::printer resets the printer to defaults.  I have set all the printer drivers to the fastest printing drivers, including the defaults in the windows drivers. I have changed the settings in the printer and it always prints nlq.  It seems that win32 printer uses the factory settings and you can't change them.  This is apparently a fault in the drivers supplied by windows.

I have learned that win32::printer doesn't support printer commands.  (or at least I haven't found out how)  If you know how to do this it would be greatly helpful.  As then I would be able to control the printer directly.  However it seems that net::lpr means that I could bypass the windows drivers.  So my question is will net::lpr accept the formatting from win32::printer and can any one supply a snippet of code to show how.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Win32::Printer sends GDI commands to a windows printer driver drawing the page on the printer's device context.  The printer driver will translate that to something the physical printer understands.  So I doubt that you'll be able to directly send commands to your printer through Win32::Printer.  

You could send the output of Win32::Printer to a file rather than directly to the printer.  There's a chance that you could post-process that file and strip out the switch to NLQ.  Then you just send the resulting file to your printer (using Net::LPR, Win32::Printer::Direct or just by doing a binary copy of the file to the printer-- copy /b file.prn \\printserver\someprinter).  How successful you're going to be with that depends on how well documented whatever printer language the ML320's use or how good you are at reverse engineering raw graphic drawing printer commands.  In the olden days of DOS, you could have probably found info on it.  Nowadays, it's abstracted away in the printer driver-- so it may be difficult to track down any references.
My guess is that you have a whole different coordinate set in NLQ mode (you're going to have a higher density available) so there won't be a simple on/off kinda switch available-- there probably won't be any chance to post-process and do it correctly.  

Is there even an option in the printer driver to disable NLQ mode and still get it to print in graphics mode?  In other words, can you manually get it to do what you want through a change in the printer preferences.  If you can, you can probably get it working.  If you can't, you probably can't.   I use ML320s (haven't printed to them through Windows in years and we don't draw graphics on them... we use them strictly for ascii text printing) but don't remember a way to get the printer driver to work in non NLQ mode.  

BTW, if you're only printing text on them, you can bypass Win32::Printer and the printer driver all together and just send the raw ascii through a file copy, Win32::Printer::Direct or Net::LPR.

Author

Commented:
Thanks very much for your comments.  What my plan was, was to print to a file and then send that file through to the printer via lpr.  However being able to print directly via lpr is a good solution as well.  I am only printing text, no graphics.  However I want to be able to position the text anywhere and adjust font sizes.  Can this be done via lpr?  I have gone through the documentation for Net::LPR and there isn't anything about formatting...
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
I also have the programmers manual for the ml320 and it has all the information to make changes on the fly the only problem is that win32::printer doesn't seem to be able to send them.
If these are already set up as windows printers on a windows printer server (and you're printing from windows) then there's really no reason to use LPR.  If you're not using the drawing functions of GDI and you've got documentation that says how to get the printer to modify fonts and place text at a certain location then there's no reason to use Win32::Printer either.    Just create your file including the commands to get it to do what you want and copy the file to the printer share.  If your printer was PCL compatible, for example:

   open OUT, ">somefile.prn"
   binmode OUT;
   print OUT chr(27),"&a5R"  # move to row 5
   print OUT chr(27),"&a5C"  # move to col 5
   print OUT chr(27),"(s18V"  # set to 18pt
   print OUT "hello there\n";
   close OUT;
   system("copy /b somefile.prn \\\\printserver\\print_share");

If you don't like the idea of the copy command, you can use Win32::Printer::Direct (http://search.cpan.org/~wasx/Win32-Printer-0.9.1/Printer/Direct.pm) which essentially does the same thing.
Haven't tried it and don't have a printer here to try it with, but my bet is that you don't need the intermediate file and that you can open up the filehandle directly to the print queue.

   open OUT, ">\\\\printserver\\print_share"
   binmode OUT;
   print OUT chr(27),"&a5R"  # move to row 5
   print OUT chr(27),"&a5C"  # move to col 5
   print OUT chr(27),"(s18V"  # set to 18pt
   print OUT "hello there\n";
   close OUT;

Author

Commented:
I have the printers setup locally and print to an ip address port 515.  How would I print to this?  Their port name?

I was kinda hoping to avoid making a new template for the setup.  Can you set your page to be in points?  If so I could use all the coordinates of the template made for win32::printer?

I have noticed from looking at the reference manual That the commands to select HSD Print Mode is?
ASCII: ESC # 0
Dec: 27 35 48
Hex: 1B 23 30

This is going to take a lot of reading, do you perchance know of good short cuts?

Author

Commented:
I have realized that we are embarking on possibly a new question and I don't think that 500 points will be good enough.  Do you want me to open a new question and supply you the link to it so that you can get more points?
If they're defined as local printers, I would probably try a temporary file and Win32::Printer::Direct (http://search.cpan.org/~wasx/Win32-Printer-0.9.1/Printer/Direct.pm).

  use Win32::Printer::Direct;
  Printfile("printer name", "test.prn");

where the first parameter is the name of your defined printer.

As far as converting your template, I don't know how your printer specifies coordinates-- so can't really help.  If you're lucky you may just have to apply a scaling factor to convert it from points into whatever your printer wants.

Author

Commented:
I discounted Win32::Printer::Direct because it relies on Win32::Printer and as such I expect the same problem.  However I will try it tomorrow just to make sure.  Do you think i should make the prn with win32::printer?

I just had an idea, is there a way to get all the attributes of a printer?  If so just change the setting when the loop finds it if possible

Otherwise how hard would it be to build an addition to win32::printer.  win32::printer already has lots of hooks into the windows api.  I just went through the docs and you can change the settings for everything else just not quality

Author

Commented:
from everything I have read and done, the best way for me to do this printing is to use win32::printer.  I would like to thank you for your help.  I can read the properties of the printer I just can't set that one.  so I am going to try to contact the author of the original and see if he has any insight.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial