0

ASP.NET Core 3.1 VMMV, C# and SQl Server

There are PDF (BLOBs) documents (20KB to 800MB) in a SQl Server varbinary(max) field that I read using Dapper ORM into a View Model object: The BLOB is successfully read into a byte array called _DocumentBLOB which is accessible from the Razor page.

So, the PDF is binary data in a byte array on the Razor page - How do I render the PDF onto the page?

View Model Object:

public class BLOBModel
{
    public int _Document_DataID; // retrieval argument
    public byte[] _DocumentBLOB; // PDF BLOB
...
}

table:

CREATE TABLE [dbo].[DocBLOB](
    [Document_DataID] [int] NOT NULL,
    [DocumentBLOB] [varbinary](max) NULL
)
Dogburrito
  • 11
  • 5

1 Answers1

0

You get pdf from byte array (variable pdfBytes) with the follow code:

var pdfStream = new System.IO.MemoryStream();
pdfStream.Write(pdfBytes, 0, pdfBytes.Length);
pdfStream.Position = 0;
var file = new FileStreamResult(pdfStream, "application/pdf");

And this is stackoverflow's answer show pdf in razor pages

krlosmederos
  • 176
  • 3
  • 11