Hi All, I recently started to use fop and came across the problem with IE not displaying the PDF. After looking around and checking other peoples solutions it seems it was due to the filename extension required to be .pdf and the content-length header needed to be set. To get the content length I needed to buffer the output; and used a ChunkByteBuffer class to do this. This is instead of allocating a byte[] as the current FopServlet does. The ChunkByteBuffer class I have released as LGPL to be added to the FOP project or the embedded example so that others don't need to go through the same pain. :) I hope you find it useful for the project. This ChunkByteBuffer could be used in conjunction with checking the request headers for the type of browser being used by the client. If the browser is IE then use the buffer, otherwise stream directly. The buffer also uses a static vector of free chunks so that data does not need to be reallocated for every buffer used. The free chunk vector currently only grows, and probably needs some timed cleanup mechanism. If you implement this let me know. You can find the code here: www.livemedia.com.au/ChunkByteBuffer.java I don't have an example of how to use it as my current code uses lots of external classes. It would go something like this in the FopServlet.java example. ChunkByteBuffer cbb = new ChunkByteBuffer(); OutputStream bout = cbb.getOutputStream(); Driver driver = new Driver( foFile, bout ); driver.setRenderer( Driver.RENDER_PDF ); driver.run(); bout.close(); response.addIntHeader( "Content-Length", cbb.length() ); OutputStream out = response.getOutputStream(); InputStream in2 = cbb.getInputStream(); byte buffer[] = new byte[2048]; while( (length = in2.read( buffer, 0, 2048)) > 0 ) { out.write( buffer, 0, length ); } in2.close(); out.close(); To make sure files had a .pdf extension I used the mod_rewrite engine of apache. My current test is using a static filename as follows: RewriteRule ^/fred.pdf$ /print/servlet/printServlet [P] If you find it useful in what you're doing or find any bugs let me know. Regards, David. PS I'm currently looking for some contract work.. anyone? :) |