Ickster
Ickster

Reputation: 2217

Spring MVC with an externally rendered PDF as the view

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.

Upvotes: 2

Views: 3789

Answers (1)

matt b
matt b

Reputation: 139931

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".

Upvotes: 2

Related Questions