java serlvet generates pdf to browserbut doesn't always show.

H

Hans Rytter

Hi.

My java servlet generates a pdf file at returns it to the browser, but on
some clients browser it doesn't show (the pdf). It's the same version of
browser, same service packs, same updates etc, on the clients. It's always
the same clients it's show / not shown.

Anybody got any suggestion for what can be wrong.

Here's a sniplet of my servlet:
......
ByteArrayOutputStream bos = TransformHandler.doPDFTransform(myDocument,
myXslFile);
sessionObj.getHttpResponse().setContentType(MyConsts.PDF_CONTENT_TYPE);
sessionObj.getHttpResponse().setContentLength(bos.size());
OutputStream os = sessionObj.getHttpResponse().getOutputStream();
bos.writeTo(os);
os.flush();
os.close();
.....

/Hans.
 
B

Ben

but on some clients browser it doesn't show
What the symptom of the problem ? Any error message in the browser ?
 
H

Hans Rytter

It's shows nothing, but a blank screen, saying "done" in the lower left
corner, on other machines it asks for wheater you want to save, open etc. in
a dialog box.
 
B

Ben

Blank page and no warning is quite surprising. It means Acrobat didn't start
at all (check from the Task Manager if the process even tries to start).
Assuming this, then it means the page didn't tell the browser it had to
start Acrobat. In such a situation, I'd double check the code to ensure
there isn't an exception raised (check logs) and the HTTP response really
contains the PDF (sniffer capture may help).
 
T

Tor Iver Wilhelmsen

Ben said:
Blank page and no warning is quite surprising. It means Acrobat didn't start
at all (check from the Task Manager if the process even tries to start).

Either that or it sits there with its STUPID "should I check for
updates, pretty please?" dialog in the background.
 
R

Roedy Green

Either that or it sits there with its STUPID "should I check for
updates, pretty please?" dialog in the background.

I'd think if there was an established connection, most users would
prefer it just quietly checked without interrupting the work flow.
Only for dialup should it need permission.

There needs to be a way for java apps to know if there is an
established internet connection without initiating a socket which
might rudely start a dialup connection.

In a pinch, it could always return TRUE if there were no way to
implement it properly.
 
P

Phil...

There are three possibilities for a given client:
1. acrobat or acrobat reader is a plug in
2. acrobat or acrobat reader is a helper application
3. acrobat or acrobat reader is not available
Could it be one of these is not working?
 
S

Scott Yanoff

Hans said:
Hi.

My java servlet generates a pdf file at returns it to the browser, but on
some clients browser it doesn't show (the pdf). It's the same version of
browser, same service packs, same updates etc, on the clients. It's always
the same clients it's show / not shown.

Anybody got any suggestion for what can be wrong.

Here's a sniplet of my servlet:
.....
ByteArrayOutputStream bos = TransformHandler.doPDFTransform(myDocument,
myXslFile);
sessionObj.getHttpResponse().setContentType(MyConsts.PDF_CONTENT_TYPE);
sessionObj.getHttpResponse().setContentLength(bos.size());
OutputStream os = sessionObj.getHttpResponse().getOutputStream();
bos.writeTo(os);
os.flush();
os.close();

Is your PDF_CONTENT_TYPE set to "application/pdf"?

An additional thing that seems to help some IE browsers is to also have:

response.setHeader("Content-Disposition", "inline;filename=somepdf.pdf");

One other trick is to call the servlet that dishes up the PDF with a
dummy parameter at the very end of the URL such as
"filename=somepdf.pdf". Sometimes, seeing the ".pdf" at the end signals
to IE that it needs to launch Acrobat.

Good luck,
 
G

Guest

Is your PDF_CONTENT_TYPE set to "application/pdf"?
An additional thing that seems to help some IE browsers is to also have:
response.setHeader("Content-Disposition", "inline;filename=somepdf.pdf");
One other trick is to call the servlet that dishes up the PDF with a
dummy parameter at the very end of the URL such as
"filename=somepdf.pdf". Sometimes, seeing the ".pdf" at the end signals
to IE that it needs to launch Acrobat.

We've found this necessary in many cases.

You may also find that you can never get Acrobat to work as a plugin,
and must go into the Acrobat configuration and uncheck "integrate with
browser" so that it runs as a helper app. Or live with the annoying
open/save dialog.

For some reason Acrobat and IE have never integrated well when using
servlets. I've been involved with several projects that use PDF
files and the problem the original poster describes occurs again and
again. The "fake filename.pdf" fix you describe has been the most
reliable, but I know for sure it doesn't always work. Sometimes it
will work for Acrobat Reader, but not if the user has the full
Acrobat product installed, which apparently integrates differently
with IE when it is "reader" mode.

Wish someone at MS or Adobe would finally figure out how to fix this
one.

--arne

DISCLAIMER: These opinions and statements are those of the author and
do not represent any views or positions of the Hewlett-Packard Co.
Good luck,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top