In modern browsers, you can use a Blob to create an object URL which can then be used instead of a base64 URL (which has some limitations in different browsers, like length limits).

Here's a working example that does that. This sample displays the PDF inside an iframe, but you can really do whatever you want with that objectURL like open it in a new tab or whatever.

var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
    // Create the Blob URL:
    var buffer = xhr.response;
    var blob = new Blob([buffer], {
        type: 'application/pdf'
    });
    var objectURL = URL.createObjectURL(blob);

    // Create an iframe to demonstrate it:
    var iframe = document.createElement('iframe');
    iframe.className = 'sample-iframe';
    iframe.src = objectURL;
    document.body.appendChild(iframe);
    console.log(objectURL);
};
xhr.open('GET', 'https://gist.githubusercontent.com/AlexanderOMara/4cd0ae77a3027a8363eecb5929b30ee3/raw/900734831709f3cb94718649ca8f7f9715adeb78/hello-world.pdf', true);
xhr.send();
html, body {
  width: 100%;
  height: 100%;
}  
.sample-iframe {
  width: 90%;
  height: 90%;
}

Of course, the browser's built-in print function for the PDF will work also.

Answer from Alexander O'Mara 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

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
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
c# - Show byte[] as pdf with html5 - Stack Overflow
Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams · Get early access and see previews of new features. Learn more about Labs ... Hi i have a big problem. I have a byte[] receveid from a Wcf service. The byte array represents a pdf ... More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
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
🌐
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.
🌐
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.
🌐
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.
🌐
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?