Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to display a pdf file using CGI

Reply
Thread Tools

How to display a pdf file using CGI

 
 
perlUSER
Guest
Posts: n/a
 
      04-14-2006
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.

 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      04-14-2006

"perlUSER" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
 
 
 
perlUSER
Guest
Posts: n/a
 
      04-15-2006
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_0 515.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

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-15-2006
perlUSER wrote:
> 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


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-15-2006
perlUSER <(E-Mail Removed)> wrote:

> open(my $pdf, '<', $pdfFile);


> Any suggestions where I am going wrong?



Not checking the return value from open().


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Convert PCL5 to PDF, Display UNICODE & ASCII Characters Inside PDF sherazam Java 0 02-22-2011 08:42 AM
Postscript to PDF with pdf-tools, pdf-writer, or other Sean Nakasone Ruby 1 04-14-2008 09:13 PM
PDF::Writer, create pdf and insert in other pdf file. Ricardo Pog Ruby 1 03-26-2008 08:24 PM
Using barcode reader, CGI form, <iframe> to display a PDF document Jimbo Perl Misc 2 01-26-2006 05:03 AM



Advertisments