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

Hey,

I've tried to figure out a way to print like 500+ .pdf files using Perl here in Windows, but my testings are rather limited since my printer's ink is no more.
However, after some research, Ive found some methods. The sub printFile is called for every file. I've tested with around 10 files. And now I need monks expertise!


Method #1:
use Win32::Printer::Direct; sub printFile { my $filename = shift; my $val = Printfile("HP DeskJet 870Cxi", $filename); return ($val == 1); }
This seems to be working the best, since EVERY file is added to the printqueue. However, can someone confirm the data printed is ok? It doesnt say amount of pages in the printqueue as it does with other ways mentioned below. Something about a "raw" print... Dont wanna have rubish on paper...

Method #2:
use Win32::API; my $shellopen = new Win32::API("shell32", "ShellExecute", ['N', 'P', 'P', 'P', 'P', 'I'], 'N'); sub printFile { my $filename = shift; if ($shellopen) { $shellopen->Call(0, "print", $filename, 0, 0, 0); print "Printing $filename...\n"; } }
This one doesnt seem to print every file. And if I add a sleep inside the if, only one is added to the printqueue, and then nothing seems to be happening. Doesnt even seem exit the sub. Wierdo.

Method #3:
my $exec = '"K:\\Program\\Adobe\\Acrobat 7.0\\Acrobat\\Acrobat.exe" /t + "a_pdf_file.pdf" "HP DeskJet 870Cxi"'; system($exec); system($exec); system($exec);
Well, this one kinda works, but next is not taken until I close the application.

So, anyone here got some bright ideas to solve this? The best would be to just let the app print em all, but seems like I have to add some kind of interaction... like print 10, wait for confirmation.. loop.
The thing is, I generate .pdf files, and after one is created the idea is to print it, delete it, and take next. However, it seems quite tricky, since the printing can't coop, and I may delete the file before it even reaches the printers buffer...

Thanks,
Ace

Replies are listed 'Best First'.
Re: Printing MANY .pdf files in Windows
by xdg (Monsignor) on Mar 24, 2006 at 16:28 UTC

    I would have thought you could use OLE directly on Acrobat to open and print, but it seems that it's not supported for the reader, only the full version of Acrobat. This thread (from codecomments.com) purports to have an approach that might work.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Printing MANY .pdf files in Windows
by radiantmatrix (Parson) on Mar 24, 2006 at 16:41 UTC
      Alrighty! Thanks! Any way way to bundle external exes with par and use then from there? ;)

      UPDATE: Crap, need Ghostscript aswell... hard to bundle all that.