File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Display PDF in IE from byte array using Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display PDF in IE from byte array using Servlet" Watch "Display PDF in IE from byte array using Servlet" New topic
Author

Display PDF in IE from byte array using Servlet

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
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

Joined: Jun 17, 2003
Posts: 81


Cheers
ASA
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
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

Joined: Oct 09, 2002
Posts: 294
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.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display PDF in IE from byte array using Servlet
 
Similar Threads
Pdf opens blank in browser
Display byte array of PDF in browser
In the HttpServletResponse header what does expire date mean
Response as PDF
PDF file display on the browser