File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display PDF in IE from byte array using Servlet

 
Sam Gehouse
Ranch Hand
Posts: 281
  • 0
  • Mark post as helpful
  • send pies
  • 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();
}
 
Anupreet Arora
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Cheers
ASA
 
Sam Gehouse
Ranch Hand
Posts: 281
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic