473,406 Members | 2,619 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,406 software developers and data experts.

Need help with a simple Perl script

First of all, I am a rank amateur at Perl. Here is my problem: I have a
hundred or more files in a directory on a web server (let's call it
'Library'). Each file is a pdf file and is named 'yyyymmm.pdf' where yyyy
is the year (i.e. 2007) and mmm is the first 3 letters of the month (i.e.
Jan). So a typical file name looks like '2007Jan.pdf'.

I wrote a simple html page using FORM that allows the user to select the
year and the month and then press the SUBMIT button and I want the
respective pdf file returned into the users browser. The problem is, I
don't know how to return a pdf file to the browser.

Here's what I have so far:

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';

# declare variables...
my $year;
my $month;
my $pdffile;

# get the parameters...
$year = param('Year');
$month = param('Month');

# construct the relative pathname to the actual PDF file
$pdffile = '../Library/'.$Year.$Month.'.pdf';

print 'Content-type: application/pdf\n\n';

This is where I'm stuck. Can someone push me in the right direction. I
would think it should be trivial. I just don't know how to procede.

Thanks in advance...

Dick

Jun 27 '08 #1
3 1848
On Wed, 28 May 2008 22:40:28 -0400, Dick Sutton wrote:
First of all, I am a rank amateur at Perl. Here is my problem: I have a
hundred or more files in a directory on a web server (let's call it
'Library'). Each file is a pdf file and is named 'yyyymmm.pdf' where
yyyy is the year (i.e. 2007) and mmm is the first 3 letters of the month
(i.e. Jan). So a typical file name looks like '2007Jan.pdf'.

I wrote a simple html page using FORM that allows the user to select the
year and the month and then press the SUBMIT button and I want the
respective pdf file returned into the users browser. The problem is, I
don't know how to return a pdf file to the browser.

Here's what I have so far:

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';

# declare variables...
my $year;
my $month;
my $pdffile;

# get the parameters...
$year = param('Year');
$month = param('Month');

# construct the relative pathname to the actual PDF file $pdffile =
'../Library/'.$Year.$Month.'.pdf';

print 'Content-type: application/pdf\n\n';

This is where I'm stuck. Can someone push me in the right direction. I
would think it should be trivial. I just don't know how to procede.

Thanks in advance...

Dick
Grab the file content and print it out after your type header...

open(FILE,"<$pdffile");
@file = <FILE>;
close(FILE);

print "Content-Type:application/pdf\n\n";
print @file;

- Netlurker
Jun 27 '08 #2

"Netlurker" <no*****@foo.barwrote in message
news:qZ********************@fe04.news.easynews.com ...
On Wed, 28 May 2008 22:40:28 -0400, Dick Sutton wrote:
>First of all, I am a rank amateur at Perl. Here is my problem: I have a
hundred or more files in a directory on a web server (let's call it
'Library'). Each file is a pdf file and is named 'yyyymmm.pdf' where
yyyy is the year (i.e. 2007) and mmm is the first 3 letters of the month
(i.e. Jan). So a typical file name looks like '2007Jan.pdf'.

I wrote a simple html page using FORM that allows the user to select the
year and the month and then press the SUBMIT button and I want the
respective pdf file returned into the users browser. The problem is, I
don't know how to return a pdf file to the browser.

Here's what I have so far:

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';

# declare variables...
my $year;
my $month;
my $pdffile;

# get the parameters...
$year = param('Year');
$month = param('Month');

# construct the relative pathname to the actual PDF file $pdffile =
'../Library/'.$Year.$Month.'.pdf';

print 'Content-type: application/pdf\n\n';

This is where I'm stuck. Can someone push me in the right direction. I
would think it should be trivial. I just don't know how to procede.

Thanks in advance...

Dick

Grab the file content and print it out after your type header...

open(FILE,"<$pdffile");
@file = <FILE>;
close(FILE);

print "Content-Type:application/pdf\n\n";
print @file;

- Netlurker
Thanks, Netlurker, I'll give that a try. Then I'll try to figure out what
each line does. ha-ha. I told you I was a novice Perl scripter.

Dick

Jun 27 '08 #3
>>>>"Netlurker" == Netlurker <no*****@foo.barwrites:

Netlurkerprint "Content-Type:application/pdf\n\n";

You're missing the space after the colon. Don't do that.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me****@stonehenge.com<URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
** Posted from http://www.teranews.com **
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: FLEB | last post by:
I like PHP for its excellent inline integration into standard HTML files, but I like Perl for its quick-moving syntax and simpler data-processing. To resolve this deep-seated inner turmoil (oh, the...
2
by: David K. Worman | last post by:
So this is probably a simple thing I'm missing, but then I just started working with perl tonight - and of course I bought the Camel book, and conveniently left it at work on my desk where it does...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
3
by: xrongor | last post by:
hi. i need a simple, hopefully free html editor that besides the standard features has the following properties: allows frames. and will allow me to create a "directory" based on data...
3
by: Sol Linderstein | last post by:
Hi, I'm writing a CGI application and here's what I'm stuck with. There are some text boxes in an html form that I want to validate. The validation needs to happen on the server side because the...
7
by: Wladimir Borsov | last post by:
I want to call a perl script myscript.pl in my cgi-bin from a HTML web page. This call should NOT use SSI (because in this case HTTPS://.... protocol is necessary). Furthermore NO button click...
2
by: mikespike21 | last post by:
Hello, I need a perl script that converts the content of a simple text document. Like the following: Content before: CC -0.007 ZZ 79.854 YY -0.002 XX -0.009
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
4
by: pcaisse | last post by:
I'm having issues sharing global variables with Explorer. This problem probably has a simple answer (as with most newbie questions). The script.pl file: #!/usr/bin/perl -w use strict; use...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.