473,417 Members | 1,554 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,417 software developers and data experts.

Opening a pdf file in browser using perl

Hi all,

I am new to this site and this is my first post. But this issue is of high priority.

I am trying to print pdf file in browser using perl script.

Onclick on hyperlink a child window is opened along with through javascript i have redirected to perl.In perl i am doing something like this,

print "Expires -1\n\n";
print "Content-Disposition: Attachmet; filename="Path of the file";
print "Content-Type: application/pdf\n\n";

open(myfile,"path of file") or die("can't open file");

while(<myfile>
{
print "$_";
}




But the problem when i click on hyperlink, a popup comes and gives option to save or open.If i select "Save" pdf file is saved properly.But click on "Open" is giving an error message like "An error encoutered while openinig the file.File not found".


I am using HTTP 1.1 proxy connections for NTLM user authentication.

Also i am trying to execute this code in solaris box.




Any suggestions on this will be very helpful.

Thanks in advance.
Nov 24 '06 #1
8 15654
miller
1,089 Expert 1GB
As GunnarH stated, your bug is in not setting binmode:

Expand|Select|Wrap|Line Numbers
  1. open(PDF, "path of pdf") or die "could not open PDF [$!]";
  2. binmode PDF;
  3. my $output = do { local $/; <PDF> };
  4. close(PDF);
  5.  
  6. print "Content-Type: application/pdf\n";
  7. print "Content-Length: " .length($output) . "\n\n";
  8. print $output;
  9.  
Nov 24 '06 #3
Hi Miller,

When I tried your code, I got the message below: Please help

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


syntax error at D:\CGI\cgi-bin\samples\DisplayPDFfileonbrowser.pl line 17, near "close"
Execution of D:\CGI\cgi-bin\samples\DisplayPDFfileonbrowser.pl aborted due to compilation errors.


I think, there is something about this statement that can not execute :

my $output = do { local $/; <PDF> }



Thanks,
May 1 '07 #4
KevinADC
4,059 Expert 2GB
it needs a semi-colon on the end:

Expand|Select|Wrap|Line Numbers
  1. my $output = do { local $/; <PDF> };
May 1 '07 #5
miller
1,089 Expert 1GB
Yep. A semi-colon is what it needs. I've edited the code to reflect this.

- Miller
May 1 '07 #6
Thanks guy for quick response. The script ran fine without any error. However, the browser display a whole bunch of binary code content, instead of the regular pdf format. Am I missing something?

Thanks,
May 1 '07 #7
Did you find out how to get the pdf displayed instead of binary code? I would like to know.
Thanks
Aug 10 '09 #8
numberwhun
3,509 Expert Mod 2GB
@Brent Kerr
Brent, this thread is over 2 1/2 years old. There is no telling if the OP even remembers the issue or is even still surfing Bytes.com. In situations where the thread is this old, its usually better to PM the OP instead of bringing life back into a thread that has been dormant for such a long time.

Regards,

Jeff
Aug 10 '09 #9

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

Similar topics

1
by: Bob Murdoch | last post by:
I've got an intranet application that presents a list of files in sort of a 'central repository' web page. Each file is an href in the form <a href=file://server/share/path/filename.ext>. When...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
5
by: Brad | last post by:
In several aspx applications I export crytal reports to pdf, xls and doc files and then the aspx page writes the selected export file to the client browser. This all works with one small quirk: ...
4
by: Vishal | last post by:
Hello, I have a dataset with some content. I can convert this dataset in a csv format which is then stored in a stringwriter. Now I want this be open via excel, so I set the contenttype...
16
by: idorjee | last post by:
hi guys, can anyone tell me what's wrong with the following script. i can print $fasta_file on the browser, but i get an error saying i can't open the file ( $fasta_file) when it comes to this line:...
1
by: mohanprasadgutta | last post by:
Hi, I need help to open a password protected excel file in perl using Win32:OLE. when I tried to open file in normal way at the time of program execution it is prompting me to enter password. I am...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.