473,545 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening a pdf file in browser using perl

6 New Member
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,"pa th 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 15673
miller
1,089 Recognized Expert Top Contributor
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
ccnguyen
6 New Member
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\Dis playPDFfileonbr owser.pl line 17, near "close"
Execution of D:\CGI\cgi-bin\samples\Dis playPDFfileonbr owser.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 Recognized Expert Specialist
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 Recognized Expert Top Contributor
Yep. A semi-colon is what it needs. I've edited the code to reflect this.

- Miller
May 1 '07 #6
ccnguyen
6 New Member
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
Brent Kerr
1 New Member
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 Recognized Expert Moderator Specialist
@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
6924
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 the user clicks on an excel file, it is opening within the browser, which unforntuntely confuses the heck out of them because the usual Print/Print...
14
11032
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 window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin =...
5
3311
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: When I run any of the web apps on my workstations iis website, the pdf download always produces the "File Download" dialog, even though I have...
4
2215
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 "application/vnd.ms-excel". To access this page the user requires to login, once the user is logged in he can access this file. Now when this file is...
16
3950
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: my $seq_in=Bio::SeqIO->new('-file' => '$fasta_file', '-format' => 'fasta'); ##### script ######## #!/usr/bin/perl -w use strict; use...
1
6165
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 giving the script i used for opening excel file.. So i want to know how to provide password parameter while opening the file. use strict; use...
3
2200
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 upload the script into server (Browser) it shows trimmed file names(single space for double spaces). I have checked both IE and Firefox it shows...
1
47373
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or...
0
7470
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7405
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7428
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5975
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5334
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.