Re: Print to a printer
by Blue (Hermit) on Nov 02, 2000 at 02:42 UTC
|
Could you give us a little more info? Are you on an Unix platform or a windows platform? Is it a directly attached printer?
It could be as easy as:
root@mysystem:> ./myscript.pl | lp -d mylaser
or
C:\>perl myscript.pl > lpt1:
(I think I got that right, I'm a Unix man myself.)
=Blue
...you might be eaten by a grue... | [reply] [d/l] |
RE: Print to a printer
by BastardOperator (Monk) on Nov 02, 2000 at 03:08 UTC
|
Just in case you meant that you want it to print to the client's printer, try:
<A HREF="Javascript: window.print()">Print</A>
| [reply] [d/l] |
|
|
Thanks this works, but i wanted to write a CGI script instead in Javascript. IS there a function in perl
| [reply] |
|
|
If you want a perl equivalent of the Javascript snippet
above that prints a web page to the client's printer,
no, there is no function or module in perl that does
what you want. As more than one person says above, a CGI
perl script cannot access resources on the client
side.
Besides, isn't this what the "print" button on their browser
is for?
The only possible exception (which your situation
does not seem to be) is on an internal-only web
server (that is, the client is on your network, at your
company), and then it could make a system call to print
some kind of output of the perl script. However (and this
is important), perl is not a web broswer, and so
it cannot output to the printer the same thing that a
browser would, so this is a bad solution too.
amelinda (see source for aside comment)
| [reply] |
Re: Print to a printer
by moen (Hermit) on Nov 02, 2000 at 02:47 UTC
|
http://search.cpan.org/search?mode=module&query=printer
I like to emphase(?) Net::Printer even though if you are in a WinNT environment your printer server/printer need to support (have the protocoll installed) LPD, witch is not necessarily standard in your WinNT system.
It's is rather standard with Unix/Linux systems though
What I'm trying to say is that the printer need to be installed on an printer server so that your application can talk to it by Net::Printer using LPD and print. Some printers also support this directly without the need of an printer server (the printer is the server)
Update: Didn't get it that the client should do the printing ..oh well ;o) | [reply] |
Re: Print to a printer
by AgentM (Curate) on Nov 02, 2000 at 02:53 UTC
|
There is no browser method to print a page, since this would become a security hole. If you know that the users of your CGI are local then you can print it out to specific printers if you wish from within the CGI and not HTML. Otherwise, you can provide a button that allows the user view a "printer-friendly" page with all extra junk removed so that it can be printed nicely.
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.
| [reply] |
Re: Print to a printer
by Anonymous Monk on Nov 02, 2000 at 02:46 UTC
|
No I am sorry that i didn't explain what i want exactly.
I am using ActivePerl and I have a button on my html page that when clicked should print the current page to the printer.
So i need to write some cgi script using modules. | [reply] |
|
|
Still not 100% sure what you're asking here. With CGI, Perl is a server-side scripting language. A button on your web page, if posting to a CGI script, would execute the Perl script on the server, which is the only place Perl can initiate a print function. So if this is the route you can go, a user hitting a web page and clicking on a Print button would post a form to your CGI script, and your CGI script would presumably print something on the server, not the client's printer.
If you're wanting to put a button on an HTML page that prints the current page in the client's printer (as if the user clicked on File | Print in their browser), you can't do this with Perl. Consider JavaScript or some ActiveX/Java component that would communicate with the browser and initiate a print command that way. Perl can't directly interact with a browser. All it does in a CGI context is return content to the browser, typically in the form of an HTML page.
If I'm misunderstanding, by all means elaborate.
| [reply] |
|
|
Thanks a lot for the help. The explanation was nice and clear. But I have one more question is that what do you use NET::Printer what exactly does that module do.
| [reply] |
|
|
|
|
|
|
|
|
|
|
|
|
Re: Print to a printer
by Anonymous Monk on Nov 03, 2000 at 06:15 UTC
|
If you're on an intranet, and everybody's printer is networked, you could do this.
It would still be server side though.
That is if you have a way of identifying who hit the button,
via cookies, login, ip, menu, or something. Then you simply print to his printer(which is justa a node on the network that the server has access to) from the server.
P.S. You'd want to keep this behind a firewall. | [reply] |