Write PDF stream to response stream

Since you are using MVC, the best way is to use FileStreamResult:

return new FileStreamResult(stream, "application/pdf")
{
    FileDownloadName = "file.pdf"
};

Playing with Response.Write or Response.OutputStream from your controller is non-idiomatic and there’s no reason to write your own ActionResult when one already exists.

Leave a Comment