Hi,

I'm trying to run a service on Vista that prints any pdf file dropped into a directory. The program works when started by hand.

### print files dropped into this directory use strict; use File::Copy; while(1) { opendir(DIRH, "c:\\printpdf") or die "couldn't open: $!"; open(FH, ">log.txt") or die "Cannot open log file"; foreach (readdir DIRH) { ### only take pdf files next unless /pdf$/i; ### acroread needs full path my $file = "c:\\PrintPDF\\$_"; print FH "Found $file\n"; #system "c:\\apps\\AcroRd32.lnk /p \"$file\""; system "c:\\apps\\AcroRd32.lnk /N /T \"$file\""; ### not sure how long acroread keeps the file open sleep 10; move("$_", "Done") or die "move failed: $!"; } close(FH); closedir(DIRH); sleep 30; }
When installed as service the print does not happen. I can see that AcroRd32 gets started but then hangs.

I assume that is because a GUI program cannot be run as service.

I also tried a printing alternativ found on this site:

use Win32::API; my $shellopen = new Win32::API("shell32", "ShellExecute", ['N', 'P', 'P', 'P', 'P', 'I'], 'N'); $shellopen->Call(0, "print", $file, 0, 0, 0);
Same problem - works when started manually - hangs when started as service.

Does anyone known a way to print PDFs w/o having to start any type of GUI application?

Thanx.


In reply to Printing PDFs as a windows service by stephanm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.