http://www.perlmonks.org?node_id=827484

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.

    HTH.

    Just a something something...