• 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

Display PDF in IE from byte array using Servlet

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a Servelt to display byte array of PDF into IE browser. Correct number of bytes are returned from existing PDF. Any help with code will be appreciated. I am using code below:

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

resp.setContentType("application/pdf");
resp.setHeader("Expires", "0");
resp.setHeader("Cache-Control","must-revalidate, post-check=0,
pre-check=0");
resp.setHeader("Pragma", "public");

resp.setHeader("Pragma", "no-cache"); //HTTP 1.0
resp.setDateHeader("Expires", 0); //prevents caching at the proxy server
resp.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
resp.setHeader("Cache-Control", "max-age=0");

resp.setHeader("Content-disposition", "inline; filename=stuff.pdf");

byte[] inputBytes = MyTest.getBytesFromFile(new File("C:\\TR.pdf"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

if(inputBytes !=null){
outputStream.write(inputBytes);
}
outputStream.flush();
}
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Cheers
ASA
 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only get Base64 encoded String that makes up PDF. I do not get the PDF itself as argument. So, my input argument is String. I decode that String into byte array.

So, my goal is to convert byte array back to PDF for display purpose.

Any help with sample code?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try:


Note that Sun doesn't recommend to use any classes from misc. However if your app isn't going to last forever, then you can use the package.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic