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