Chief Engineer Scott has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to read from a table where the records contain a file name (always a .pdf), a drive path, and a \\printserver\printername reference, then have Perl print the .pdf on the specified printer? e.g
Acrobat.pdf c:\cfusion\documents\test \\zz-test-web\IT-URDU

Replies are listed 'Best First'.
Re: Print a PDF from a script
by Corion (Patriarch) on May 10, 2004 at 18:26 UTC

    You don't even need Perl for this, as long as the printer is the default printer. If you right-click on a .pdf file, you will notice that there is a context menu entry labeled 'print'. Looking for the corresponding action with Regedit.exe, you will find some special invocation of acrord32.exe using the /p command line switch (or so I think I remember). Use system() with that switch to make Acrobat Reader print the .pdf.

    For the second part of your problem, setting the default printer temporarily to something different, look at what Win32::Printer has to offer, together with Win32::Printer::Enum.

      Sorry, I guess my question was unclear, what I have is a database table with a number of records, for each record there is a PDF document number, a path to the PDF, and the \\printserver\printer reference where the user requires the PDF to be printed, I think this would rule out the use of WIN32. Example Table Batch Acrobat.pdf c:\cfusion\batch\ \\zz-test-web\IT-URD2 DaVinci.PDF c:\cfusion\drawing\ \\zz-test-web\AD-MAN3 Rates.pdf c:\cfusion\specs\ \\zz-test-web\ED-URA5 In each case I would like to pass the PDF directly to the printer for printer, or if that is not possible, somehow open it "silently" and have the contents printed. Any help will be greatly appreciated

        Why do you believe that this "rules out WIN32" ?

        My approach would directly print the .pdf files without any further interaction, but unless you clarify what your problem with my approach is, I can't help you.

Re: Print a PDF from a script
by periapt (Hermit) on May 11, 2004 at 12:48 UTC
    This should be doable. The Win32::Printer modules should help you select the printer to send to if necessary. For printing, you could shell out to the command line for actual printing with system() or even backticks.

    I don't know if you have tried command line printing with adobe acrobat, but I have never been able to get it to work. I even called Adobe's support line once and the person I spoke to said it wasn't possible. For command line printing, I usually use GSView/Ghostscript ( http://www.cs.wisc.edu/~ghost/gsview/get45.htm, http://www.cs.wisc.edu/~ghost/doc/AFPL/get811.htm). With ghostscript, you can actually specify the printer to print to on the command line which might obviate the need for the Win32::Printer modules.

    Unfortunately, although I do a fair amount of this sort of processing and printing, it usually takes a little finagaling to get it working correctly.

    Good Luck
    PJ
Re: Print a PDF from a script
by Juerd (Abbot) on May 10, 2004 at 18:16 UTC

    Is it possible to read from a table where the records contain a file name (always a .pdf), a drive path, and a \\printserver\printername reference, then have Perl print the .pdf on the specified printer?

    Yes, it is.

    Good luck!

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }