Problem with perl, cgi & pdf

B

byrapaneni

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.
 
R

Ray Booysen

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top