File does not begin with '%PDF-'

I have a servlet that returns a PDF over SSL (using Struts and fop).

HttpServletResponse Res;

Res.setContentType("application/pdf");

Res.setHeader("Content-disposition","inline;filename=\""+MyFile+".pdf\"");

Here I get the OutputStream from Res (Res.getOutputStream() ) and stream out the PDF

I was getting IE security warnings and while going through various sites and from this link "http://support.microsoft.com/default.aspx?scid=kb;en-us;321532", I used Res.setHeader("Accept-Ranges", "bytes") in my code.

But now, some screens work perfectly fine without the warnings while for some screens I get the error "File does not begin with %PDF".

Anyone faced this ?

Thanks.

[730 byte] By [Deal_NoDeala] at [2007-11-26 15:30:07]
# 1

According to the HTTP RFC, the filename should not have quotes around it. Just use

Res.setContentType("application/pdf");

Res.setHeader("Content-disposition","inline;filename="+MyFile+".pdf");

Res.setHeader("Accept-Ranges", "bytes");

I doubt that this will fix your problem, but it is worth a try at least.

gimbal2a at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Will give it a shot now .. thx for suggesting ...
Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Unfortunately, this did not fix it :(
Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Maybe this is a radical suggestion, but have you considered accepting the message at face value and finding out why the data you are sending doesn't start with those characters?
DrClapa at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hmm well let me tell that this occurs only with IE and not with Firefox but unfortunately our users use IE.

Also, if I remove the Res.setHeader("Accept-Ranges", "bytes");

then I do not get this error and only the IE security warning appears. Accepting that loads the PDF correctly.

I read it somewhere that IE makes multiple GETs to the server while requesting for the PDF. Although, it would be requesting for the content-type which I am specifically setting to my response, not sure where things are going wrong.

Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
One more addition to this ..If I upgrade my acrobat to the latest, then everything seems alright but again that is not an option here since we can't ask users to upgrade the acrobat.
Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> Hmm well let me tell that this occurs only with IE

> and not with Firefox but unfortunately our users use IE.

Ah, I see. There's no accounting for taste, is there?

> Also, if I remove the Res.setHeader("Accept-Ranges",

> "bytes");

> then I do not get this error and only the IE security

> warning appears. Accepting that loads the PDF

> correctly.

That header is making a statement to the client that your web server has the ability to... um, I don't know exactly what. Maybe you could look it up. But at any rate it appears that your web server doesn't actually have that ability, hence the problem. (My guess.)

> I read it somewhere that IE makes multiple GETs to

> the server while requesting for the PDF. Although, it

> would be requesting for the content-type which I am

> specifically setting to my response, not sure where

> things are going wrong.

Right. Or else it's Acrobat that is requesting a particular range of bytes (if that's what the header actually means) and your web server can't support that request properly. And maybe the new version of Acrobat has a better way of doing things that doesn't require this. (More guessing.)

Edit: And maybe that Microsoft support page assumed your web server was IIS and it does support the Accept-Ranges header, but yours isn't.

Message was edited by:

DrClap

DrClapa at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

> > Hmm well let me tell that this occurs only with IE

> > and not with Firefox but unfortunately our users

> use IE.

>

> Ah, I see. There's no accounting for taste, is

> there?

>

> > Also, if I remove the

> Res.setHeader("Accept-Ranges",

> > "bytes");

> > then I do not get this error and only the IE

> security

> > warning appears. Accepting that loads the PDF

> > correctly.

>

> That header is making a statement to the client that

> your web server has the ability to... um, I don't

> know exactly what. Maybe you could look it up. But at

> any rate it appears that your web server doesn't

> actually have that ability, hence the problem. (My

> guess.)

>

> > I read it somewhere that IE makes multiple GETs to

> > the server while requesting for the PDF. Although,

> it

> > would be requesting for the content-type which I

> am

> > specifically setting to my response, not sure

> where

> > things are going wrong.

>

> Right. Or else it's Acrobat that is requesting a

> particular range of bytes (if that's what the header

> actually means) and your web server can't support

> that request properly. And maybe the new version of

> Acrobat has a better way of doing things that doesn't

> require this. (More guessing.)

>

I guess you are right here. The web server doesn't have the ability to understand the "Accept-Ranges = bytes" and moreover as you said the MS site would be self assuming everyone has IIS only.

> Edit: And maybe that Microsoft support page assumed

> your web server was IIS and it does support the

> Accept-Ranges header, but yours isn't.

>

> Message was edited by:

> DrClap

Message was edited by:

Deal_NoDeal

Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Well a correction here ... I think my web server is able to understand the "Accept-Ranges" since some pages begin to work just fine but this problem occurs only with few other pages.
Deal_NoDeala at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Anyone got this working ?
Ignorance_is_Blissa at 2007-7-8 21:46:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...