• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pdf and binary files - URGENT

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have some pdf and txt reports stored in oracle database as bfiles. I am retrieving it using a servlet. I could retrieve the text reports without any problem. When I select pdf, pdf reader opens and comes with blank pages. It is showing the actual number of pages though. I am sending the mime header to application/pdf. IF I use outputstream instead of printwriter, I am getting blank pages and it is not opening adobe reader. When I make slight changes in the code again, I am getting a dialog box asking whether to save it or open it. If I say open it, it opens up a notepad with garbage(bytes) in it. Could anybody suggest a way out from this and help me to see my actual pdf file.
Thanks
beksy98@yahoo.com
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same problem with downloading XL file.
Any ideas are would be appreciated.
If I find the solution first I will post it here.
Alex
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any answer, please!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found when sending the pdf to the browser be very careful to ensure that you have included \n\n after the content type
Mac
edit --
But I have had success with this on most browsers
response.setHeader("Content-Type","application/pdf");
[This message has been edited by Mac Fraser (edited July 13, 2001).]
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fraser. I still am not getting anything. Below is the code
Please help!
static void pdfBfile(Connection myConnection,BFILE bfile,HttpServletRequest request, HttpServletResponse response)
throws Exception{
response.setHeader("Content-Type","application/pdf");
OracleCallableStatement read =
(OracleCallableStatement)
myConnection.prepareCall ("begin dbms_lob.read (?, ?, ?, ?); end;");

bfile.openFile();

InputStream instream = bfile.getBinaryStream();

int pos =0;
int len ;
byte[] buf = new byte[1024];
while ((len = instream.read(buf)) != -1)
{
for (int i=0; i<len; i++)
dataOutput.write(buf,i,len);
}
instream.close();
dataOutput.close();
bfile.closeFile();
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I missed one line in the previous post, ...defining outputstream
here it is
OutputStream dataOutput = response.getOutputStream();
Anybody, help!
 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did find a solution.
Here is my Servlet. The servlet gets invoked when a user tries to access an excel file. The servlet checks permissions and ,reads the excel file and then displays it to the user.
Here is the display part
ServletOutputStream out = resp.getOutputStream();
String path = req.getParameter("Path");
FileInputStream fis = new FileInputStream(path);
<b>resp.setContentType("application/vnd.ms-excel");</b> //this is important so the browser knows to open Excel
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] buffer = new byte[1024];
int l = 0;
while ( (l = bis.read(buffer) ) != -1)
out.write(buffer);
bis.close();
out.flush();
out.close();
}
Also make sure that the server has the MIME type defined for your binary files.

[This message has been edited by Aleksey Matiychenko (edited July 13, 2001).]
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aleksey,
I don't think that solution will work for me? or will it? This files are stored in oracle as bfiles. I don't see any methods to get the correct path of the bfile. I see a getName and getDirAlias, not the full path. Any ideas?
Anybody, this is URGENT!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes with binary data it is important to set the content-length header or the browser plugin won't understand when the transmission is done.
Bill
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem might be browser dependent. We had a similar problem at work a few months ago. I know one of the browsers did not load a PDF file unless it's more than a specific size. I just can't remember how they solved it.
Bosun
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setting the length didn't help. I am using IE ( 4&5) and JRUN 2.3.3.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally!!!it worked!!!
Here is what I did if anybody is interested. Thanks to everybody who responded.
static void pdfBfile(Connection myConnection,BFILE bfile,HttpServletRequest request, HttpServletResponse response)
throws Exception{

response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setContentType("application/pdf");
ServletOutputStream out = response.getOutputStream();

OracleCallableStatement read =
(OracleCallableStatement)
myConnection.prepareCall ("begin dbms_lob.read (?, ?, ?, ?); end;");

bfile.openFile();
InputStream instream = bfile.getBinaryStream();

int pos =0;
int len ;
byte[] buf = new byte[1024];

while ((len = instream.read(buf)) != -1)
{
out.write(buf,0,len);
}
instream.close();
out.close();
bfile.closeFile();
}
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can u help and tell me that if input file is PDF and file has to be moved onto server what should i do..I think my problem is kinda similar to yours..Code would be really helpful
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure whether I understood your question correctly, Anuj. All our text files and pdf files are on the server. We are just storing the pointers in the database as bfiles(datatype).
beksy98@yahoo.com
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic