Re: Problem with perl, cgi & pdf
- From: Ray Booysen <rj_booysen_NS@xxxxxxxxxx>
- Date: Wed, 26 Apr 2006 21:37:18 +0100
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.
- References:
- Problem with perl, cgi & pdf
- From: byrapaneni
- Problem with perl, cgi & pdf
- Prev by Date: How to Display an image, from a DB, into the Gridview (ASP.NET 2.0)
- Next by Date: Re: Creating controls at runtime or designtime
- Previous by thread: Problem with perl, cgi & pdf
- Next by thread: Re: Crystal "PrintToPrinter" will not print to Zebra Label Printer... HELP!
- Index(es):
Relevant Pages
|