Found the solution here it is, i was sending byte array from spring controller which is in the form like %PDF-1 %����. So i send base64 encoded string from spring controller and send the base64 encoded string to browser and it works.

javascript code :

var arrrayBuffer = base64ToArrayBuffer(data); //data is the base64 encoded string
function base64ToArrayBuffer(base64) {
    var binaryString = window.atob(base64);
    var binaryLen = binaryString.length;
    var bytes = new Uint8Array(binaryLen);
    for (var i = 0; i < binaryLen; i++) {
        var ascii = binaryString.charCodeAt(i);
        bytes[i] = ascii;
    }
    return bytes;
}
var blob = new Blob([arrrayBuffer], {type: "application/pdf"});
var link = window.URL.createObjectURL(blob);
window.open(link,'', 'height=650,width=840');

convert byte array to base64 encoded string in spring controller

String encodedString = Base64.getEncoder().encodeToString(bytearrayofpdf);
Answer from user on Stack Overflow
Discussions

javascript - display byte array as pdf in browser i tried several options from stack overflow but it did not work for me - Stack Overflow
enter code here var blob = new ... iframe.className = 'sample-iframe'; iframe.src = objectURL; document.body.appendChild(iframe); above code i am using to display pdf from byte array... More on stackoverflow.com
🌐 stackoverflow.com
Pass byte[] array to javascript and convert the byte array to PDF in javascript.
Find answers to Pass byte array to javascript and convert the byte array to PDF in javascript. from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
March 31, 2010
Display pdf as byte-array
Is it possible to display a pdf from a byte-array in memory, instead from a Uri ? More on github.com
🌐 github.com
2
November 16, 2017
Render byte array as pdf using Javascript inside iframe Internet Explorer/Edge - Stack Overflow
I have a byte array(which was converted from an original PDF file) returned from an http post method. My requirement is to render the original PDF inside an iframe , i use angular 1.x with IE/Edge browser. ... IE and Microsoft Edge don't support iframe with data url as src attribute. So you can't display ... More on stackoverflow.com
🌐 stackoverflow.com
December 17, 2019
🌐
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.
🌐
Experts Exchange
experts-exchange.com › questions › 25629636 › Pass-byte-array-to-javascript-and-convert-the-byte-array-to-PDF-in-javascript.html
Solved: Pass byte[] array to javascript and convert the byte array to PDF in javascript. | Experts Exchange
March 31, 2010 - Sounds like you have the pdf already on the server or on someone else's server If you have it on your own server, ajax a LINK to the pdf and open the pdf in an iframe or a new window If it is on someone else's server or web service, get the ...
🌐
GitHub
github.com › mozilla › pdf.js › issues › 9142
Display pdf as byte-array · Issue #9142 · mozilla/pdf.js
November 16, 2017 - Is it possible to display a pdf from a byte-array in memory, instead from a Uri ?
Author   abrasat
🌐
Stack Overflow
stackoverflow.com › questions › 59361091 › render-byte-array-as-pdf-using-javascript-inside-iframe-internet-explorer-edge
Render byte array as pdf using Javascript inside iframe Internet Explorer/Edge - Stack Overflow
December 17, 2019 - I have a byte array(which was converted from an original PDF file) returned from an http post method. My requirement is to render the original PDF inside an iframe , i use angular 1.x with IE/Edge browser. ... IE and Microsoft Edge don't support iframe with data url as src attribute. So you can't display ...
🌐
Stack Overflow
stackoverflow.com › questions › 46542472 › the-pdf-file-is-not-displayed-from-byte-array-in-the-iframe
javascript - the pdf file is not displayed from byte array in the iframe - Stack Overflow
$(document).ready(function () { $.ajax({ async: false, cache: false, type: "POST", url: "@(Url.RouteUrl("GetAnyRespons"))", responseType: 'arraybyte', success: function (JsonCP) { var data = JsonCP.responseModel.response.ResponseImage; var file = new Blob([data], { type: 'application/pdf' }); var fileURL = URL.createObjectURL(file); var iframe = document.createElement('iframe'); iframe.className = 'responseframe'; iframe.src = fileURL; $('#response').append(iframe); alert('response Loaded.'); }, error: function (xhr, ajaxOptions, thrownError) { alert(thrownError + ' Failed to retrieve response.'); } }); }); <div id="container"> <div id="response"> </div> <div id="marks"></div> </div> The byte array with some other data is passed to client after converting into JSON data by the controller.
Find elsewhere
🌐
Dynamics Community
community.dynamics.com › forums › thread › details
How to display PDF document in an IFRAME or HTML Web ...
Hello All - Any suggestions on how to display an existing PDF document (present in notes attachment) in CRM Online (Either in an IFrame or HTML Web Resource?) · You can do this but it'll be a little bit of work. Check out these two posts:
🌐
Software AG Adabas & Natural Tech Community
tech.forums.softwareag.com › t › trying-to-display-the-byte-array-content-in-iframe-caf-portlet › 205407
Trying to display the byte array content in IFrame CAF portlet - Software AG Adabas & Natural Tech Community & Forums
June 2, 2020 - Hi All, I am invoking a consumer webservice to get the the file content in byte array. I want to display the 1st byte array object in the CAF Iframe portlet. Can you please suggest, how we can do this.
Top answer
1 of 6
2

Nope there is no interface that would allow you to this sort of thing in the web-side security sandbox. The reason you aren't just downloading the PDF from the server is?...

2 of 6
1

As I said in my question we already generate the PDF data on the server.

We need to have the byte data available on the client side to be passed via a JS call to a Java applet. We do this currently via a hidden field. That's okay and it works just fine.

The problem is that the call to the applet only takes place if the okay button on an ajax modal dilaog is clicked ('Do you want to send this document to UglyProprietorySystem?').

As you all know you can't put anything on top of an adobe plug-in display. Obviously if the whole page is of type PDF then there's no place for any JS to show the dialog so that wouldn't work and if you use an IFrame you still can't put anything on top of what the plug-in displays (it's effectively another app's airspace and violating that is just plain rude!).

We worked around this by:

  1. Inititally showing a blurred image of a generic PDF doc and popping the modal dialog on top of that.
  2. When the user had responded to the dialog we called (or not) the java app with the pdf byte data from the hiden field
  3. We then posted back after clearing the hidden field (Woo! Posting back a form with PDF binary data is not appreciated by the server!)
  4. In the page_load of the code behind we then, on postback, wrote to the response stream with he PDF byte data, setting the contentype to be appplication/pdf and thus the pdf is displayed.

Lovely. It all works and gets us kind of what we'd like.

Only problem is we either need to:

  • generate the PDF data twice (once on initital page_load for the clientside call to our applet and then again on postback to display).

or

  • We store the PDF byte data in the session after the first response so as to be able to, after the postback, still have the pdf data to be able to display it.

Neither is great but we went with the latter but now we're thinking we'd like to avoid that if we can.

Thus the idea of generating the PDF, putting it into a hidden field, having a button on the page to save the PDF to our proprietary system via an applet call and also writing to the IFrame with that data already on the client in the hidden field thus displaying it.

Phew!

So that's why we wanted to on the client using JS, write the pdf binary data to the IFrame and have it's content type set to application/pdf so the browser would load up the adobe plug-in and display it.

🌐
Inductive Automation
forum.inductiveautomation.com › ignition
WebDev Python Resources, Display PDF in Perspective PDF Viewer or IFrame - Ignition - Inductive Automation Forum
January 25, 2022 - I have a webserver that hosts PDF in a byte array and want to display it in a perspective PDFViewer or IFrame. I have working Code in Ignition that can save the file locally, but I would like to put that PDFdata directly…
🌐
CopyProgramming
copyprogramming.com › howto › render-pdf-using-pdf-js-and-angularjs-from-byte-array
Utilizing AngularJS and PDF.JS to display PDFs from byte arrays - Javascript
March 15, 2023 - Displaying PDF Files from Byte Array using AngularJS and PDF.JS, Debugging Issues with pdf.js PDF Rendering Without Error Messages, Display PDF from Byte Array in an Iframe using JavaScript on Internet Explorer/Edge, Rendering PDF in UI using HTML5 by converting it to a byte array with JavaScript
🌐
Carolinainsuranceschool
dev-app.carolinainsuranceschool.com › wp-content › themes › busify › fbeea › display-pdf-byte-array-in-browser-javascript.html
Display pdf byte array in browser javascript
You cannot directly manipulate ... best to display the pdf on mobile devices or which ways are possible. NET MVC. Would I have to launch the file in a frame or iframe? I figure my app could write the html code on the fly, and save the file as . For this, I will set return type "FileResult" from MVC controller and return "File" with a byte Array of the file ...
🌐
GitHub
github.com › Hopding › pdf-lib › issues › 1312
Get pdf bytes from blob after filling out PDF form fields (editable PDF) · Issue #1312 · Hopding/pdf-lib
September 11, 2022 - const PdfForm = ({pdfPath, pdfContentToParent}) => { const [pdfInfo, setPdfInfo] = useState("") const [pdfBytesInfo,setPdfBytesInfo ] = useState([]) useEffect(() => { intializePdf(); },[]) const intializePdf = async () => { const url = 'https://pdf-lib.js.org/assets/with_update_sections.pdf' const arrayBuffer = await fetch(url).then(res => res.arrayBuffer()) const pdfDoc = await PDFDocument.load(arrayBuffer) const pdfBytes = await pdfDoc.save(); const blobObj = new Blob([pdfBytes], { type: "application/pdf" }) const docUrl = URL.createObjectURL(blobObj); setPdfBytesInfo(blobObj.arrayBuffer());
Author   sandeep2244
🌐
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?