Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Unable to find the file while printing

by kalyanrajsista (Scribe)
on Mar 09, 2010 at 06:47 UTC ( #827484=perlquestion: print w/ replies, xml ) Need Help??
kalyanrajsista has asked for the wisdom of the Perl Monks concerning the following question:

Hello all

I'm trying to print PDF files from my perl script with the following code, but getting the error message "There was an error opening this document. This file cannot be found." I found in some of the forums that any spaces in between the filename could be a problem, but as such I don't have any spaces in filename.

When I'm debugging my program, I'm able to print the PDF file, but when executing I'm getting the above message from Adobe Reader

#!c:/perl/bin/perl use strict; use Win32::API; my $filename = "C:\\Invoices\\foobar.pdf"; my $shellopen = new Win32::API("shell32", "ShellExecute", ['N', 'P', 'P', 'P', 'P', 'I'], 'N'); $filename =~ tr!\\!/!s; $shellopen->Call(0, "print", $filename, 0, 0, 0);

Comment on Unable to find the file while printing
Download Code
Re: Unable to find the file while printing
by BioLion (Curate) on Mar 09, 2010 at 09:32 UTC

    A bit of debugging would tell you that your filename is probably not what you think it is and that your transliteration is not doing what you think:

    my $filename = "C:\\Invoices\\foobar.pdf"; print "1 : >>$filename<<\n"; $filename =~ tr!\\!/!s; print "2 : >>$filename<<\n"; __END__ 1 : >>C:\Invoices\foobar.pdf<< 2 : >>C:/Invoices/foobar.pdf<<

    It might also be useful to include file test in your code, just to check that it isn't a permissions problem too.


    Just a something something...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://827484]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2015-01-26 10:29 GMT
Find Nodes?
    Voting Booth?

    My top resolution in 2015 is:

    Results (189 votes), past polls