Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   Error When Redirecting to a PDF file (http://www.velocityreviews.com/forums/t803281-error-when-redirecting-to-a-pdf-file.html)

mansb2002@yahoo.com 06-06-2007 11:10 PM

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.


Daniel Crichton 06-07-2007 08:26 AM

Re: Error When Redirecting to a PDF file
 
mansb2002@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



mansb2002@yahoo.com 06-08-2007 06:35 PM

Re: Error When Redirecting to a PDF file
 
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.



Dave Anderson 06-08-2007 08:04 PM

Re: Error When Redirecting to a PDF file
 
mansb2002@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.



mansb2002@yahoo.com 06-08-2007 08:25 PM

Re: Error When Redirecting to a PDF file
 
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.


Dave Anderson 06-08-2007 09:03 PM

Re: Error When Redirecting to a PDF file
 
mansb2002@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.



Dave Anderson 06-08-2007 09:08 PM

Re: Error When Redirecting to a PDF file
 
mansb2002@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.



mansb2002@yahoo.com 06-08-2007 09:46 PM

Re: Error When Redirecting to a PDF file
 
On Jun 8, 5:08 pm, "Dave Anderson" <NPQRWPDWZ...@spammotel.com> wrote:
> 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.


mansb2002@yahoo.com 06-08-2007 09:47 PM

Re: Error When Redirecting to a PDF file
 
On Jun 8, 5:08 pm, "Dave Anderson" <NPQRWPDWZ...@spammotel.com> wrote:
> 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.


Dave Anderson 06-11-2007 03:45 PM

Re: Error When Redirecting to a PDF file
 
mansb2002@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.




All times are GMT. The time now is 05:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.