473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1910
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen Ferg | last post by:
Seen in the Wall Street Journal, Monday, July 21, 2003, page B1. Lee Gomes' "Portals" technology column: "Two Men, Two Ways to Speak Computerese and Two Big Successes". This is a brief,...
29
by: Bart Nessux | last post by:
Just fooling around this weekend. Wrote and timed programs in C, Perl and Python. Each Program counts to 1,000,000 and prints each number to the console as it counts. I was a bit surprised. I'm not...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
2
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
0
by: dohnut | last post by:
Here's one for some bored problem solver :) I ran across this earlier today and fixed it, but don't exactly know why. (that usually only happens in C :) I'm using Perl version 5.8.0 btw. ...
1
by: Justin Kozuch | last post by:
Hi All, How do I determine the path to Perl on a Windows 2000 server? My hosting company has installed ActiveState Perl (latest version). I've called them and they said the path to perl is...
9
by: débutante | last post by:
bonjour tout le monde je veux installer perl soous cygwin. pour y procéder voici nles étapes ke g fait: 1) g téléchargé activeperl et je l'ai installé => résultat: c/perl le perl toune...
3
by: jonathan184 | last post by:
The code seems to be working fine for some records but I am thinking it is finding some other records with special characters and so on. I am looking for a way to insert the xml string with escaping...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.