MVC 5 – How to Display a PDF in a View

Assuming that you have a PDF in your controller as a byte array, add the following code to convert the data to a base64 string and send to your view.

string imageBase64Data = Convert.ToBase64String(results);
string imageDataURL = string.Format("data:application/pdf;base64,{0}", imageBase64Data);
ViewBag.ImageData = imageDataURL;

 In your view, display the PDF in an iframe.

 <div class="container">
    <div class="row">
        <div class="form-group-sm">
            <div class="col-md-12" style="padding-left: 0px;">
                <iframe style="width: 75%; height: 500px;" src="@ViewBag.ImageData"></iframe>
Please follow and like us: