Hi!

That will work for a small number of files. If you want to automate the
process, then you need to either convert the HTML to a printer-ready file,
or automate sending the file to a browser.

A very crude (but quite effective) way is to use the X11::GUITest or Win32::GuiTest module.

You would open the document with your browser via the command line (something like "browserbinary document.html" should suffice) and then send the key presses required to print the document and close the browser; basically the same a user would do manually.

I haven't tested it completly cause i got no printer at home (did this on Ubuntu Linux with a dummy printer; e.g. can't verify the output), but you could try something like this:

---start---

#!/usr/bin/perl

use strict;
use warnings;

use X11::GUITest qw/
  StartApp
  WaitWindowViewable
  SendKeys
/;

# Start gedit application
StartApp('firefox x.html');

# Wait for application window to come up and become viewable.
my ($WinId) = WaitWindowViewable('firefox');
if (!$WinId) {
  die("Couldn't find firefox window in time!");
}

# Wait for page to render...
sleep(3);

# Access printing dialog (and wait a bit
# for it to pop up), then press ALT-p
SendKeys('%(f)P');
sleep(1);
SendKeys('%(p)');



# Wait for printing to be finished
sleep(5);

# Close Application (Alt-f, q).
SendKeys('%(f)q');


---end---

This is quite a hackish way, you might have to experiment with the timing and the keys you send, depending on your system and prefered browser.

On the other hand, you get *exactly* the same output to your printer as a real user would have.

LG
Rene

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to