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

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.Redirect("/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.pdf" 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.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
Response.BinaryWrite("/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 9432
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.Redirect("/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.pdf" 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.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
Response.BinaryWrite("/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.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
Response.BinaryWrite("/website/pdffiles/" + pdfFile);
Response.End;
%>

Acrobat open and displays the following error "File does not begin
with '%PDF-'".
Response.BinaryWrite 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.BinaryWrite(adoStream.Read())
Response.BinaryWrite(adoRecordset.Fields("FileData ").Value)
Response.BinaryWrite(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.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(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.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(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.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/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.Redirect("/website/pdffiles/myreport.pdf");
Response.End;

pdfFile = "myreport.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(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...@spammotel.comwrote:
mansb2...@yahoo.com wrote:
>The following code is used to redirect:
>Response.Redirect("/website/pdffiles/myreport.pdf");
Response.End;
pdfFile = "myreport.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(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...@spammotel.comwrote:
mansb2...@yahoo.com wrote:
>The following code is used to redirect:
>Response.Redirect("/website/pdffiles/myreport.pdf");
Response.End;
pdfFile = "myreport.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(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.Redirect("/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
Response.Redirect("/website/pdffiles/myreport.pdf");
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.
"myreport.pdf" is actual PDF file NOT an ASP page.
Jun 11 '07 #11
ma*******@yahoo.com wrote:
"myreport.pdf" is actual PDF file NOT an ASP page.
There is a huge inconsistency in your description of the problem. If you
are, in fact, redirecting directly to the PDF file, then your ASP script is
irrelevant. So which is it, an ASP script that reads a PDF document and uses
BinaryWrite(), or a PDF document that is sent directly?

--
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 #12
First I would like to apologize for the confusion. Originally, I was
using:

Response.Redirect("/website/pdffiles/myreport.pdf");

To direct the user to the PDF file. Every thing was working ok until I
switched to Win2003 server. At that time the above command no longer
worked. So, I tried the second method which was to read in the PDF
file. This is what I have:

Original.ASP file:
Some code....
....
....
Response.Redirect("/website/html/showpdf.asp");
Response.End;
ShowPDF.ASP file:

<html>
<body>
<% @ LANGUAGE="JScript" CODEPAGE="932" %>
<%
Response.Buffer = true;
Response.Expires = 0;
pdfFile = "myreport.pdf";
Response.Clear;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=" +
pdfFile);
var oPDF = oProcess.FileToStr(pdfFile);
Response.BinaryWrite(oPDF);
Response.End;
%>
</body>
</html>

I hope this will clear some confusion. Again I apologize for getting
all the things mixed up. Thanks for your help.

Jun 12 '07 #13
ma*******@yahoo.com wrote:
First I would like to apologize for the confusion. Originally,
I was using:

Response.Redirect("/website/pdffiles/myreport.pdf");

To direct the user to the PDF file. Every thing was working ok
until I switched to Win2003 server. At that time the above command
no longer worked.
OK. In that case, you can probably just revert to the old redirection to the
PDF file if you enable PDF in IIS6. Open the properties for your web site
and click on the HTTP Headers tab. Click on the [MIME Types...] button, and
add the PDF extension with MIME type "application/pdf".

If this does not work, and you need to resume the ASP approach, let me know
in this thread.


--
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 12 '07 #14
On Jun 12, 4:19 pm, "Dave Anderson" <NPQRWPDWZ...@spammotel.com>
wrote:
mansb2...@yahoo.com wrote:
First I would like to apologize for the confusion. Originally,
I was using:
Response.Redirect("/website/pdffiles/myreport.pdf");
To direct the user to the PDF file. Every thing was working ok
until I switched to Win2003 server. At that time the above command
no longer worked.

OK. In that case, you can probably just revert to the old redirection to the
PDF file if you enable PDF in IIS6. Open the properties for your web site
and click on the HTTP Headers tab. Click on the [MIME Types...] button, and
add the PDF extension with MIME type "application/pdf".

If this does not work, and you need to resume the ASP approach, let me know
in this thread.

--
Dave Anderson
Sorry, I was away.

I just tried your suggestion and guess what? No change. I still get
the same error. 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.pdf" from "website".
Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please try
again later."
Any other ideas

Jun 15 '07 #15
<ma*******@yahoo.comwrote:
I just tried your suggestion and guess what? No change.
Which change? You are now pointing the browser directly to PDF file?
I still get the same error. 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.pdf" from "website".
Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please
try again later."
I would have long ago tested this with Firefox and the LiveHTTPHeaders
extension. You should, too. That way, you can show the response headers
instead of the dumbed down consumer-grade message IE provides.

--
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 16 '07 #16
On Jun 16, 11:00 am, "Dave Anderson" <NPQRWPDWZ...@spammotel.com>
wrote:
<mansb2...@yahoo.comwrote:
I just tried your suggestion and guess what? No change.

Which change? You are now pointing the browser directly to PDF file?
I still get the same error. 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.pdf" from "website".
Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please
try again later."

I would have long ago tested this with Firefox and the LiveHTTPHeaders
extension. You should, too. That way, you can show the response headers
instead of the dumbed down consumer-grade message IE provides.

--
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.
Hi Dave,

FireFox has no problem showing the PDF file. Most of our users only
use IE. :-)

Jun 18 '07 #17
ma*******@yahoo.com wrote:
>I would have long ago tested this with Firefox and the
LiveHTTPHeaders extension. You should, too. That way, you
can show the response headers instead of the dumbed down
consumer-grade message IE provides.

FireFox has no problem showing the PDF file. Most of our
users only use IE. :-)
While that's good information, it ignores the salient point, which is that
you can use the LiveHTTPHeaders extension to view the response headers.
Since you do not have this problem with IIS5, but do have the problem with
IIS6, I suggest you compare the headers. The headers direct disposition
(browser behavior), after all.


--
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 18 '07 #18

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

Similar topics

5
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...
1
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...
6
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...
25
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...
3
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...
8
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...
8
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 :)...
4
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. ...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.