• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Display byte array of PDF in browser

 
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.

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");

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

if(inputBytes !=null){
// inputBytes are not null, checked its correct size too.
outputStream.write(inputBytes);
}
outputStream.flush();
}

PDF does not displayed. There is already pdf file under C directory which I can manually open. inputBytes are not null, checked its size too.

Is there a better way to display pdf in browser from bytes?

Any help with code will be appreciated.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sam Gehouse:

PDF does not displayed.



Please have a look at Notes on Microsoft Internet Explorer, its for FOP, but still you can use the tips for ur case.
 
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
No luck with 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");
//from sam
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();
}
 
They weren't very bright, but they were very, very big. Ad contrast:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic