469,647 Members | 1,755 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

Problem with perl, cgi & pdf

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.

Apr 26 '06 #1
1 1823
This is the asp.net framework newsgroup and has nothing to do with perl
or cgi. Sorry ;)

by********@gmail.com 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.

Apr 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stephen Ferg | last post: by
29 posts views Thread by Bart Nessux | last post: by
4 posts views Thread by Xah Lee | last post: by
2 posts views Thread by Xah Lee | last post: by
reply views Thread by dohnut | last post: by
1 post views Thread by Justin Kozuch | last post: by
9 posts views Thread by débutante | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.