How to display a pdf file using CGI

P

perlUSER

Hello all;
Learned a lot from this group. Thanks to everyone who answered my
questions.

Yet another question.
I am creating web pages to display a table lisitng reports. When a user
clicks the report name corresponding report displayed in the browser.
When the report is displayed the url is the location of the file name.
I am wondering whether perl/CGI can read a pdf file and display it in
the browser. This is to hide the report location on the server.

I was searching for hints for the past couple of days and my search
didn't yield anything.

I would appreciate if someone posts a script if they have done this in
the past.
Please advise the best way to achieve this.

Best regards,
Sri.
 
M

Matt Garrish

perlUSER said:
Hello all;
Learned a lot from this group. Thanks to everyone who answered my
questions.

Yet another question.
I am creating web pages to display a table lisitng reports. When a user
clicks the report name corresponding report displayed in the browser.
When the report is displayed the url is the location of the file name.
I am wondering whether perl/CGI can read a pdf file and display it in
the browser. This is to hide the report location on the server.

The same you'd read any other file and print it out to a browser:

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

my $pdfFile = '/test.pdf';

open(my $pdf, '<', $pdfFile);
binmode $pdf;
binmode STDOUT;
my $buffer;
while (read($pdf, $buffer, 1024, 0)) {
print $buffer;
}
close($pdf);

Error checking and handling left to you.

Matt
 
P

perlUSER

Here is my code runs fine in the console but can't get it to work in
the browser;

#!/usr/local/bin/perl

my $pdfFile =
"C:\\reports\\monthly\\06_04_08\\009NJS01_060315_0515.pdf";

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


open(my $pdf, '<', $pdfFile);
binmode $pdf;
binmode STDOUT;
my $buffer;
while (read($pdf, $buffer, 1024, 0)) {
print $buffer;


}


close($pdf);

==================
Any suggestions where I am going wrong?

Thanks in advance.

Sri
 
J

Jürgen Exner

perlUSER said:
Here is my code runs fine in the console but can't get it to work in
the browser;

Your Question is Asked Frequently: perldoc -q 500
"My CGI script runs from the command line but not the browser."
==================
Any suggestions where I am going wrong?

Not following the advise in the FAQ?

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top