I would recommend creating another action on the controller designed specifically for rendering the PDF data. Then it's just a matter of referencing it within your data attribute:

data="@Url.Action("GetPdf", "PDF")"

I'm not sure you can dump raw PDF data within the DOM without hitting some kind of encoding issue. You may be able to do like images, though I've never tried. But, for demo's sake and image would look like:

src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

So, assuming the same could be done it would probably look like the following:

@{
  String base64EncodedPdf = System.Convert.ToBase64String(Model.pdfInBytes);
}

@* ... *@
<object data="data:application/pdf;base64,@base64EncodedPdf"
        width="900" height="600" type="application/pdf"></object>

I still stand by my original response to create a new action however.

Answer from Brad Christie on Stack Overflow
🌐
DEV Community
dev.to › letsbelopez › how-to-load-a-pdf-in-a-browser-from-a-pdf-byte-array-56ic
How to Load a PDF in a Browser from a PDF Byte Array - DEV Community
March 23, 2020 - Here's my solution. I ended up using an embed tag and make the src attribute equal to the api endpoint that was returning the byte array. <div class="pdf"> <embed src="https://api_url/path/to/endpoint" type="application/pdf" /> </div>
Discussions

asp.net mvc - C# MVC website PDF file in stored in byte array, display in browser - Stack Overflow
I am receiving a byte[] which contains a PDF. I need to take the byte[] and display the PDF in the browser. I have found similar questions like this - How to return PDF to browser in MVC?. But, it More on stackoverflow.com
🌐 stackoverflow.com
Embed PDF Byte Data in HTML
Stack Overflow chat opening up to all users in January; Stack Exchange chat... 11 How to show PDF in browser using byte array of PDF in JavaScript? ... 0 display byte array as pdf in browser i tried several options from stack overflow but it did not work for me More on stackoverflow.com
🌐 stackoverflow.com
Stream pdf and then convert that to html as bytes array .. (pdf to html) using stream - Free Support Forum - aspose.com
(1) reading pdf in stream and then convert it to html (2) output byte[] resultHtmlAsBytes. See attached file for detail code More on forum.aspose.com
🌐 forum.aspose.com
1
0
October 15, 2015
Display PDF from byte array | Telerik Forums
I want to show a PDF without saving it to disk on the server. I call a WCF method and recieve a byte array. I then save the PDF to the IsolatedStorage. But then I cannot display it in the HTMLPlaceHolder. Isn´t there a way to display a file such as HTML or PDF without saving it on the server? More on telerik.com
🌐 telerik.com
January 20, 2011
🌐
Aspose
forum.aspose.com › aspose.pdf product family
Stream pdf and then convert that to html as bytes array .. (pdf to html) using stream - Free Support Forum - aspose.com
October 15, 2015 - (1) reading pdf in stream and then convert it to html (2) output byte[] resultHtmlAsBytes. See attached file for detail code
🌐
Telerik
telerik.com › forums › display-pdf-from-byte-array
Display PDF from byte array | Telerik Forums
January 20, 2011 - Hi Raymond, If you have the byte stream of an HTML page, you can display it in the RadHtmlPlaceholder using the HtmlSource property: ... htmlPlaceHolder.HtmlSource = htmlSource; Also, you can use the same approach to display HTML files saved in an isolated storage: htmlPlaceHolder.HtmlSource ...
Find elsewhere
🌐
DynamicPDF
dynamicpdf.com › examples › html-to-pdf-byte-array-.net-core
Convert HTML to PDF Byte Arrays Using .NET
The following steps and C# sample code illustrate converting HTML to a PDF byte array using DynamicPDF HTML Converter for .NET.
🌐
Aspose
forum.aspose.com › aspose.pdf product family
PDF byte array to stream to HTML | PDF to HTML using C# Aspose.PDF for .NET - Free Support Forum - aspose.com
March 2, 2021 - Hi, I am trying to convert a PDF ... exception. I am using Aspose.Pdf version 17.8.0.0 . using (var stream = new MemoryStream(pdfByteArray)) { using (var document ......
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1512272 › displaying-binary-pdf-file-on-a-webpage-using-gene
Displaying Binary PDF file on a webpage using Generic Handler - Microsoft Q&A
January 25, 2024 - using System; using System.Web; namespace WebForms1 { public class Handler4 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetExpires(DateTime.Now.ToUniversalTime()); context.Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0, 0)); context.Response.ContentType = "application/pdf"; // byte array is obtained from the file in Files holder (not from DB) string filename = "JBL4312G.pdf"; string path = context.Server.MapPath("~/Files") + "\\" + filename; byte[] data = System.IO.File.ReadAllBytes(p
🌐
GitHub
github.com › VadimDez › ng2-pdf-viewer › issues › 88
Display PDF from Byte Array · Issue #88 · VadimDez/ng2-pdf-viewer
May 10, 2017 - I'm hitting a service that generates a pdf based on data sent it and returns the pdf in a byte array. Is there a way to use this plugin to display the pdf? ... You can’t perform that action at this time.
Published   May 10, 2017
Author   jjacobs33589
🌐
Aspose
forum.aspose.com › aspose.pdf product family
PDF Byte Array to HTML - Free Support Forum - aspose.com
August 14, 2014 - What is the proper way to convert a pdf stored in a byte array to raw html? It would be preferable to have the html output stored as a String, but that is not completely necessary. I am currently creating a aspose.pdf.Document object using a ByteArrayInputStream as a parameter.
🌐
GitHub
github.com › mozilla › pdf.js › issues › 9142
Display pdf as byte-array · Issue #9142 · mozilla/pdf.js
November 16, 2017 - Closed · Display pdf as byte-array#9142 · Copy link · abrasat · opened · on Nov 16, 2017 · Issue body actions · Is it possible to display a pdf from a byte-array in memory, instead from a Uri ? No one assigned · No labels · No labels · No type · No projects ·
Author   abrasat
🌐
DynamicPDF
dynamicpdf.com › examples › open-pdf-bytearray-.net
Opening PDFs From Byte Arrays using .NET
Learn how to open a PDF from a byte array. Steps and C# Code. Over 24 Years experience providing easy to use PDF Libraries. Provided libraries in C# and VB.NET.
🌐
Reddit
reddit.com › r/blazor › display of pdf documents from byte[]
r/Blazor on Reddit: Display of PDF documents from byte[]
January 18, 2022 -

I have a slight problem in a Blazor Server application when displaying PDF documents. I have tried to find a C# based solution for this but cannot find one anywhere.

The background to this is I am working on an application that is used in part to store and display PDF documents. For various reasons (which I won't go into as I have tried to change this many times but the arguments to not do it are actually quite well presented) these are not stored in a document format but within the database so are handled in the Blazor application as byte[] variables.

So for display to the user when they select the document we convert the byte[] into base64 and embed the resultant code into the pages displayed.

In the C#

string DisplayPDF;

DisplayPDF = "data:application/pdf;base64," + Convert.ToBase64String(nc.DocData);

and in the HTML

<embed src="@DisplayPDF" type="application/pdf" width=1000 height=800 />

And to some extent this works fine, until we get over approx 2Mb in size for the document at which point we get a blank screen. I believe this is to do with the URL size displayed as over 2Mb the src value gets too long and most browsers won't display it.

Has anyone had any experience with this issue and know of a solution? I have found one using Java but this doesn't work for us. How do we handle large PDF files as the vast majority of the files in use are over the size limit set by this issue?

🌐
The Coding Forums
thecodingforums.com › archive › archive › java
Display byte array back to pdf and display in IE | Java | Coding Forums
October 20, 2005 - You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser. ... I get Base64 encoded String for a PDF file. I convert that String to character array. Then I decode it back to byte array.