Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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);

Replies are listed 'Best First'.
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
NodeReaper lights some incense and reads Tool and Die

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-06-19 20:31 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.