• Post Reply Bookmark Topic Watch Topic
  • New Topic

Open PDF file in IE by using Java  RSS feed

 
Thamaraiselvan Ponraj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In my servlet i have got String[] which has PDF file content. I need pass the string[] to any output stream to open the PDF file. But output stream only accepts byte[]. How Do i convert String[] to byte[]. If there is any other way of open the PDF file by using String[], please help me.

Regards
Selvan
 
osman cinar eren
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how could you manage to put pdf content into a String array?
Are you sure you have it?

if so(i dont think so), you can get the bytes from each string with the getBytes() method and append them into a new array.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should treat PDF as binary data, not character data. That means using InputStream and OutputStream type methods, not Reader and Writer type. Reading a PDF as String[] is bound to cause trouble because Java will attempt to perform some character conversion.
Bill
 
Thamaraiselvan Ponraj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply. Finally I have changed my code I m using byte[] array. But Still I have one problem When I write byte[] in to output stream My servlet is getting submitted twice. Its getting in to doGet() method twice. Please help me.

private void outputPDF(HttpServletResponse response, byte[] pdf) throws IOException
{

response.setContentType("application/pdf");
log.debug("after getting into the response ");
response.setContentLength(getContentLen(pdf));
response.setDateHeader("Expires",0);
log.debug("after setting the content type and the date");

OutputStream os = response.getOutputStream();
log.debug("PDF Length Value=====" + pdf.length);

for(int i=0;i<pdf.length;i++) {
os.write(pdf[i]);
}
os.close();



}

Regards
Selvan
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have heard that IE has this weird behavior where it requests PDFs twice - once to get the size and then once for the Adobe viewer. Unfortunately I have no idea how to prevent this.
Incidently you don't need to step through pdf[] one byte at a time - OutputStream has a write( byte[] )
Bill
 
Joe Intrakamhang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had an issue like this before when I was submitting a pdf object back to the client. It was due to a bug in the IE browser. It seem to be fix in IE 6.0 but then it got broke again. I would try using another browser (e.g.firefox) to see if it only submits it once.

The way we resolve it was to use a doPost instead of a doGet to retrieve the pdf object.

--Joe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!