AlainS has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, A little desperate I am... I installed the PDF::API2 library from CPAN, both on my local windows vista machine and on the Linux-server of my provider. I wrote a little piece of code using this library. It does work on my local machine, but not on the server. By the way, I'm used to working with CPAN-libraries, and they all function fine on my provider's server. I wrote the following lines: $pdf = PDF::API2->open($in); $p = $pdf->openpage(1); etc. $in contains the pdf-path/filename on the server. At the openpage-command the program already stops with an error 500. Any monk having an idea about what could be wrong? Thanks a lot!

Replies are listed 'Best First'.
Re: PDF::API2 not working?
by moritz (Cardinal) on Feb 11, 2008 at 16:22 UTC
    First step: look in your server's error.log to find out what the problem is.
Re: PDF::API2 not working?
by mr_mischief (Monsignor) on Feb 11, 2008 at 18:24 UTC
    I haven't seen enough code or error message text to be sure, but I think one or more of these things may help (as they tend to do for CGI errors with code 500):
    • use CGI::Carp qw( fatalsToBRowser );
    • $| = 1; print "Content-type: text/html\n\n";
    • $| = 1; print "Content-type: application/pdf\n\n"; # if you're sending a PDF directly to the browser
    • check your log file to see what's said there
    • run the program from the command line on the server (even if that means a CGI wrapper program that opens it with system()) and see what error gets reported
    • move your Content-type header to an earlier spot in your program
    • make sure your shebang line isn't still set up for Windows once you put the program on the Linux server. That's one of the most frustrating things one can overlook, and I speak from experience.
    A 500 error means that the server can't serve the request because something went wrong with the program being run or with the web server's configuration. Typically with Apache and Perl, it means you forgot to print the Content-type header or that there's an error in the program which aborts before that gets printed and flushed from the buffer.
Re: PDF::API2 not working?
by Anonymous Monk on Feb 12, 2008 at 08:38 UTC
    my guess is open returns undef because it can't access $in, and then openpage fails with Can't call method "openpage" on an undefined value at ...