3

I have to display a PDF(stored as BLOB in SQL Server table) in a partial view. I am doing the same for a ".jpeg" image stored as BLOB in the table.The image is getting displayed,however,the PDF isnt.I have the following code in my controller:

[Authorize]
public ActionResult Show3LeadImage(int id)
{
    Byte[] imageData = null;
    using (var scope = new PatientPersistenceScope())
    {
         searchRequest leadRequest = new searchRequest();
         leadRequest.CaseNumber = id;
         var mrx12LeadBitmap = _mrxSearchService.Get12Lead(leadRequest);
         imageData = mrx12LeadBitmap.Data12Leads[0].mrx3Lead;
         scope.Done();
    }
   return File(imageData,"image/png");//I have tried "FileContentResult,but it didnt work
 }

The code in the partial view(.ascx) looks like this:

<object data='<%= Url.Action("Show3LeadImage", "CareRecord", new { id = Model.CareRecord.CaseNumber}) %>' type="application/pdf" style="width: 721px; height: 800px;" ></object>

I do not have access to the physical file....the BLOB is all I have.

Is it even possible to display a PDF as image in partial view? I came across lots of articles that explained how to make a PDF available for download in the partial view.But I do not want my file to be downloadable. Is this functionality achievable or am I trying to do something impossible?

user1550951
  • 369
  • 2
  • 9
  • 26
  • You can achieve it easily by placing your pdf on disk and keeping its path in sql. I guess,that will lower down the SQL read/write times. –  Oct 01 '13 at 05:00

1 Answers1

1

Converting a PDF to image is not as simple as serving it as a PNG. You will need to convert it using a library, like ImageMagick or ABCPdf (sample: Convert PDF to image with high resolution)

If you want to embed the PDF inside the HTML the are several ways to do it, i.e. Recommended way to embed PDF in HTML?

Community
  • 1
  • 1
Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206