473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error When Redirecting to a PDF file

Hi,

We recently moved our webserver from Win2K to Win2003. The application
works fine. Only problem is that when user views a report as a PDF, IE
does not show it. The following code is used to redirect:

Response.Redire ct("/website/pdffiles/myreport.pdf");
Response.End;

IE opens a "File Download" box and if you click the "open" button then
nothing happens. If you click the "Save" button the following error
comes up:

"Internet Explorer cannot download "myreport.p df" from "website".
Internet Explorer was not able to open this Internet site. The
requested site is either unavialable or cannot be found. Please try
again later."

if I use the following code:
<%
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
Response.Binary Write("/website/pdffiles/" + pdfFile);
Response.End;
%>

Acrobat open and displays the following error "File does not begin
with '%PDF-'".

Any help would be greatly appreciated.

Jun 6 '07 #1
17 9449
ma*******@yahoo .com wrote on Wed, 06 Jun 2007 16:10:48 -0700:
Hi,

We recently moved our webserver from Win2K to Win2003. The application
works fine. Only problem is that when user views a report as a PDF, IE
does not show it. The following code is used to redirect:

Response.Redire ct("/website/pdffiles/myreport.pdf");
Response.End;

IE opens a "File Download" box and if you click the "open" button then
nothing happens. If you click the "Save" button the following error
comes up:

"Internet Explorer cannot download "myreport.p df" from "website".
Internet Explorer was not able to open this Internet site. The
requested site is either unavialable or cannot be found. Please try
again later."
Can you turn off show friendly error messages in IE and try again? What does
the address URL show in IE?

Did you add PDF to the list of allowed MIME types to IIS? Out of the box
IIS6 allows very little, it's a more secure model and you need to enable any
file extensions that you want to allow to be downloaded.
if I use the following code:
<%
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
Response.Binary Write("/website/pdffiles/" + pdfFile);
Response.End;
%>

Acrobat open and displays the following error "File does not begin
with '%PDF-'".
BinaryWrite sends raw binary data. In this case, you are sending the string
/website/pdffiles/myreport.pdf as the data. To use BinaryWrite to send the
data in the file, you need to open the file, read it's content, and then
pass that into BinaryWrite. If you sort out the redirection to work you
won't need to do this.

Dan
Jun 7 '07 #2
Hi Dan,

I added the PDF MIME to the server. It made no difference. I still get
the same error when I click the open or save button. The URL in the
window is of the original ASP page that redirects to PDF file. The PDF
file ("/webserver/pdffiles/myreport.pdf") URL is NOT displayed.

Oh, I left out a line by mistake. I have a com object that reads the
file and send the file content to BinaryWrite. I any ideas?

Thanks for your help.
Jun 8 '07 #3
ma*******@yahoo .com wrote:
if I use the following code:
<%
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
Response.Binary Write("/website/pdffiles/" + pdfFile);
Response.End;
%>

Acrobat open and displays the following error "File does not begin
with '%PDF-'".
Response.Binary Write does not take a string argument. You must put a byte
array in there. This could come from an ADODB.Stream, recordset, or similar.

http://msdn.microsoft.com/library/en...adoobjects.asp

Typical uses would look like:

Response.Binary Write(adoStream .Read())
Response.Binary Write(adoRecord set.Fields("Fil eData").Value)
Response.Binary Write(adoField. GetChunk(size))
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 8 '07 #4
Hi Dave,

I left out a line of code by mistake. Here is my code:

<%
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
var oPDF = oProcess.FileTo Str(pdfFile);
Response.Binary Write(oPDF);
Response.End;
%>

Yes I am sending the correct data to BinaryWrite. I used the plain
text page to see if the content was right.

Jun 8 '07 #5
ma*******@yahoo .com wrote:
I left out a line of code by mistake. Here is my code:

<%
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
var oPDF = oProcess.FileTo Str(pdfFile);
Response.Binary Write(oPDF);
Response.End;
%>

Yes I am sending the correct data to BinaryWrite. I used the plain
text page to see if the content was right.
OK. That leaves me with a couple of questions. First, this appears to be
JScript, but you are not calling Response.Clear( ) and Response.End() as
methods. Does it change anything to do so?

Second, your error states that "File does not begin with '%PDF-'". If you
change the content-type to "text/plain", does the output have anything
before those characters?

I am also curious to know why you use both of these lines when they do the
same thing:

Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 8 '07 #6
ma*******@yahoo .com wrote:
>>The following code is used to redirect:

Response.Redi rect("/website/pdffiles/myreport.pdf");
Response.En d;

pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
var oPDF = oProcess.FileTo Str(pdfFile);
Response.Binary Write(oPDF);
Response.End;
I am a bit confused. On one hand, you say you are redirecting to a .pdf
file, but on the other hand, this looks like a .asp script. Have you set up
IIS to parse .pdf files with asp.dll?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 8 '07 #7
On Jun 8, 5:08 pm, "Dave Anderson" <NPQRWPDWZ...@s pammotel.comwro te:
mansb2...@yahoo .com wrote:
>The following code is used to redirect:
>Response.Redir ect("/website/pdffiles/myreport.pdf");
Response.End ;
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
var oPDF = oProcess.FileTo Str(pdfFile);
Response.Binary Write(oPDF);
Response.End;

I am a bit confused. On one hand, you say you are redirecting to a .pdf
file, but on the other hand, this looks like a .asp script. Have you set up
IIS to parse .pdf files with asp.dll?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Yes, I am using JScript.

I thought Response.Clear( ) and Response.End() was for ASP.NET!

When I changed to "text/plain" the file I get back starts with
"%PDF-1.3".

I don't know why I have both lines in there. I saw an example on the
net and I thought it might help. I am new to this and as you can see
desperate as well.

No I have not setup IIS to parse PDF files with asp.dll. Is that only
if you are posting data to the server? Would you please give me some
direction as how setup this? I set IIS6 identical to IIS5 which works
just fine.

Thanks again.

Jun 8 '07 #8
On Jun 8, 5:08 pm, "Dave Anderson" <NPQRWPDWZ...@s pammotel.comwro te:
mansb2...@yahoo .com wrote:
>The following code is used to redirect:
>Response.Redir ect("/website/pdffiles/myreport.pdf");
Response.End ;
pdfFile = "myreport.p df";
Response.Clear;
Response.Conten tType = "applicatio n/pdf";
Response.AddHea der("Content-Type", "applicatio n/pdf");
Response.AddHea der("content-disposition", "inline;filenam e=" +
pdfFile);
var oPDF = oProcess.FileTo Str(pdfFile);
Response.Binary Write(oPDF);
Response.End;

I am a bit confused. On one hand, you say you are redirecting to a .pdf
file, but on the other hand, this looks like a .asp script. Have you set up
IIS to parse .pdf files with asp.dll?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Yes, I am using JScript.

I thought Response.Clear( ) and Response.End() was for ASP.NET!

When I changed to "text/plain" the file I get back starts with
"%PDF-1.3".

I don't know why I have both lines in there. I saw an example on the
net and I thought it might help. I am new to this and as you can see
desperate as well.

No I have not setup IIS to parse PDF files with asp.dll. Is that only
if you are posting data to the server? Would you please give me some
direction as how setup this? I set IIS6 identical to IIS5 which works
just fine.

Thanks again.

Jun 8 '07 #9
ma*******@yahoo .com wrote:
>>>>The following code is used to redirect:
>>>>Response.Re direct("/website/pdffiles/myreport.pdf");
I no longer believe this. It appears you are redirecting to an ASP script,
not to a PDF flie.

When I changed to "text/plain" the file I get back starts with
"%PDF-1.3".
Which means your ASP script is being parsed, since the browser behavior
changed.

I don't know why I have both lines in there. I saw an example on
the net and I thought it might help.
It wouldn't be a bad idea to quote the passage to which you are responding.
I'll assume this is about two different ways of setting the content-type
header. I would not dare to guess how the browser deals with mulitple
content-type headers. In my opinion, you should get rid of one.

No I have not setup IIS to parse PDF files with asp.dll. Is that
only if you are posting data to the server? Would you please give
me some direction as how setup this? I set IIS6 identical to IIS5
which works just fine.
That does not appear to be required, based on your further description of
the issue. When you asserted that you were redirecting to a .pdf file, you
implied that myreport.pdf was actually an ASP script. So, either you are
already set up to parse .pdf that way, or you are not redirecting to a
resource called myreport.pdf.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 11 '07 #10

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

Similar topics

5
2525
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already started sending out the content of the page. Web content is always delivered with a few headers at the top, ending with a blank line. For...
1
1753
by: Elie B. | last post by:
Hi, I'm new to Python. I'm trying to embbed Python in my Windows application having some success with redirecting the stdin/out to my windows application using: In my C++ code I use PyRun_SimpleString to execute this code: import sys import mymodule class LOGwriter :
6
3557
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html error page. All six steps in the article work just fine. Then at the end of the article, there is a little comment about redirecting errors to an aspx...
25
17166
by: moondaddy | last post by:
I have an application where users need to upload images and in my web.config file I have a setting like this: <httpRuntime maxRequestLength="512" /> Which restricts image larger than 500k from being uploaded. I'm also using the HtmlInputFile control to do the uploading. My problem is that when the user's file size exceeds 512k, the page...
3
2455
by: tony | last post by:
I've been searching through the threads to find a solution for 401.3 error triggered by windows authentication not being able to redirect to a custom error page to no avail. It seems that ASP.NET does not redirect 401 errors yet changing the Custom Errors redirect in IIS does not help either. Has anyone found a solution to this problem? ...
8
5770
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can technically create an executable that calls the function and then using a command prompt call the exexutable using the > output.txt redirector but I...
8
2837
by: Taras_96 | last post by:
Hi everyone, We' ve come to the conclusion that we wish the user to be directed to an error page if javascript is disabled <enter comment about how a webpage shouldn't rely on javascript here :) >. I've read quite a few posts on how to do this, but none meet my need (the two main suggestions was set a jsEnabled variable in a <scriptsection...
4
1118
by: karthi84 | last post by:
hi, i have developed a project in .net 1.1, when i view the project in a browser i get the following error. Server Error in '/Alfi/invoice generation/WebApplication1' Application. Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the...
3
19845
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be found at www.srmiles.com/freestuff/ajax_file_uploader/ . you can do multiple file uploads. each upload will have it's own "form"-tag, so that each...
0
7935
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7692
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
7992
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6313
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
5519
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
5244
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
3677
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...
1
2128
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1235
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.