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.
8 15654
As GunnarH stated, your bug is in not setting binmode: -
open(PDF, "path of pdf") or die "could not open PDF [$!]";
-
binmode PDF;
-
my $output = do { local $/; <PDF> };
-
close(PDF);
-
-
print "Content-Type: application/pdf\n";
-
print "Content-Length: " .length($output) . "\n\n";
-
print $output;
-
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,
it needs a semi-colon on the end: - my $output = do { local $/; <PDF> };
Yep. A semi-colon is what it needs. I've edited the code to reflect this.
- Miller
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,
Did you find out how to get the pdf displayed instead of binary code? I would like to know.
Thanks
@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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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: ...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |