Re: Problem with perl, cgi & pdf

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



This is the asp.net framework newsgroup and has nothing to do with perl or cgi. Sorry ;)

byrapaneni@xxxxxxxxx wrote:
Hello all;
I gathered information from this and several other groups to write a
perl & cgi script to display a pdf document. My script works partially
and found an issue when testing.

Here is my script:
===============================================================
#!/bin/perl

use CGI qw(:standard *table);

$q = new CGI;

my $buffer = undef;
my $pdfFile = 'test.pdf';

my $mimeType = 'text/html';

if (! -e $pdfFile){
&die_nice("Cannot find file to open - ". $pdfFile);
}

if (! -r $pdfFile){
&die_nice("Unable to read file - ". $pdfFile);
}

if ((-e $pdfFile) && (-r $pdfFile)){
open(pdfFile, '<', $pdfFile) || &die_nice("Cannot open - ".$pdfFile);
$mimeType = 'application/pdf';
}

print $q->header(-expires=>'now', -type=>$mimeType);

binmode pdfFile;
binmode STDOUT;

while (read(pdfFile, $buffer, 4096, 0)) {
print $buffer;
}

close(pdfFile);

sub die_nice{
my $error = shift;
print $q->header(-expires=>'now', -type=>$mimeType);

print "<dl>";
print "<dt>Some error occurred:</dt>";
print "<dd><strong>$error</strong></dd>";
print "</dl>";

exit;
=========================================================

When I execute this script the test.pdf file is displayed in my
browser. If I change the my $pdfFile = 'test.pdf'; to my $pdfFile =
'test.pd';, basically deleting the last charactor forced to do
die_nice(). I see nothing in the browser.

Closed the browser, opened a new wiondow and I can see the error
message.

Now changed the file name back to it's original name, accessed the
script from the browser and the browser displays the raw data.

Can some one please help me with this issue.

Regards,
Sri.

.



Relevant Pages

  • Re: Help with a stragegy for diagnosis
    ... I have a Perl CGI that has work for years. ... first failure and before the second. ... A strategy would be to write tests for the script until you get the same ...
    (comp.lang.perl.moderated)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... from the documentation provided with Perl. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ...
    (comp.lang.perl.misc)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... from the documentation provided with Perl. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ...
    (comp.lang.perl.misc)
  • Re: Advice about cgi programming
    ... experience with other scripting languages. ... This might not be the most appropriate group, but since Perl is ... input string to this script in the background and return the result. ... Perl is an excellent choice for writing CGI programs. ...
    (comp.lang.perl.misc)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... comes with the standard Perl distribution. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ... The similarity between CGI response headers (defined in the CGI ...
    (comp.lang.perl.misc)