Link to home
Start Free TrialLog in
Avatar of ralphs1961
ralphs1961Flag for Canada

asked on

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

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.
Avatar of clockwatcher
clockwatcher

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.
Avatar of ralphs1961

ASKER

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...
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;

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?
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?
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.