B
byrapaneni
Hello all;
I have gathered information from this group and several other groups to
write a script to display a pdf document in the browser window. 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;
}
==================================================================
Case 1:
This scipt returns the pdf document to the browser correctly.
This script doesn't return anything If I change the file name to
something else and execute it.
But this script returns the error message if executed from a new
browser window.
Case 2:
If I execute this scrit from the web browser with incorrect file name,
I can see the proper error message. Now, if I change the file name back
to it's original name and execute the script in the same window I end
with raw data.
I think the browser saves the content-type when the script invoked for
the first time and saves it. Could some one please help me fix this
problem? Thanks in advance.
Regards,
Sri.
I have gathered information from this group and several other groups to
write a script to display a pdf document in the browser window. Here is
my script;
==================================================================
#!/bin/perl
use CGI qw
$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;
}
==================================================================
Case 1:
This scipt returns the pdf document to the browser correctly.
This script doesn't return anything If I change the file name to
something else and execute it.
But this script returns the error message if executed from a new
browser window.
Case 2:
If I execute this scrit from the web browser with incorrect file name,
I can see the proper error message. Now, if I change the file name back
to it's original name and execute the script in the same window I end
with raw data.
I think the browser saves the content-type when the script invoked for
the first time and saves it. Could some one please help me fix this
problem? Thanks in advance.
Regards,
Sri.