views:

1348

answers:

1

Is there a built-in mechanism in Spring that would allow me to display an externally rendered PDF as a view?

I've fetching PDF via a webservice (returned an attached DataHandler) so I'm not looking to subclass AbstractPdfView to render PDF.

This isn't a hard problem to solve on its own; it would be easy enough just to write the PDF to the ServletOutputStream. However, for consistency's sake I'd like to stay with the Spring controller classes which return a ModelAndView which means writing my own subclass of AbstractView to just write the PDF to a ServletOutputStream. Doing so is no big deal, but I don't want to recreate something that might already exist somewhere else within Spring.

+2  A: 

So you have the PDF as a (byte) stream, and you want to write that out to the response? This isn't the case where you have a ModelAndView and you want a PDF to be generated with the Model data in it?

In that case, I can't see what other option you have besides writing it to the response stream. What actions would there be for any re-usable piece of Spring code to do besides this anyway? It sounds like your logic is as simple as "take this stream and write it to the output stream".

matt b
And set the MIME type to "application/pdf", of course.
duffymo
I edited my question to be a little more clear as to what I'm thinking. Thanks for your answer.
Ickster
I don't think anything like that exists already - I don't think having the complete PDF as a bytestream is a common scenario. However creating your own reusable class to handle this is a pretty good idea.
matt b