Opening Pdf String in New Window With JavaScript

Window.Open with PDF stream instead of PDF location

It looks like window.open will take a Data URI as the location parameter.

So you can open it like this from the question: Opening PDF String in new window with javascript:

window.open("data:application/pdf;base64, " + base64EncodedPDF);

Here's an runnable example in plunker, and sample pdf file that's already base64 encoded.

Then on the server, you can convert the byte array to base64 encoding like this:

string fileName = @"C:\TEMP\TEST.pdf";
byte[] pdfByteArray = System.IO.File.ReadAllBytes(fileName);
string base64EncodedPDF = System.Convert.ToBase64String(pdfByteArray);

NOTE: This seems difficult to implement in IE because the URL length is prohibitively small for sending an entire PDF.

Unable to open pdf file in new tab

The ajax is expecting a JSON in return, there is no need for you to use ajax, you can just use window.open, sending fileName by get

window.open('../content/getPdfPath?fileName='+fileName,'_blank');

So you have to change your controller to

@RequestMapping(value = UriMapping.GET_PDF_PATH, method = RequestMethod.GET)

How to open generated pdf using jspdf in new window

  1. Search in jspdf.js this:

    if(type == 'datauri') {
    document.location.href ='data:application/pdf;base64,' + Base64.encode(buffer);
    }
  2. Add :

    if(type == 'datauriNew') {   
    window.open('data:application/pdf;base64,' + Base64.encode(buffer));
    }
  3. call this option 'datauriNew' Saludos ;)

Opening base64 pdf in a new tab freezes tab over some file size

Load your pdf from a blob:URI instead of from a data:URI.

var win = window.open();
var blob = base64ToBlob(someDoc.url, 'application/pdf');
win.document.write('<iframe src="' + URL.createObjectURL( blob ) + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>')


function base64ToBlob( base64, type = "application/octet-stream" ) {
const binStr = atob( base64 );
const len = binStr.length;
const arr = new Uint8Array(len);
for (let i = 0; i < len; i++) {
arr[ i ] = binStr.charCodeAt( i );
}
return new Blob( [ arr ], { type: type } );
}

live plnkr

There are bugs in Chrome's plugin and Firefox's pdf.js, I also experienced this problem while writing this answer on a very related question (which doesn't have an accepted answer and can't be used as dupe target).

How to Open .pdf on a new Tab

Solved! That works for me

 window.open('/Export/PrintPdf');

PDF gets stuck when opening through iframe using window.open()

This is an old question, but could helpful for others:
The problem is with the iframe width and height tags. Instead of using percentages, use defined pixels. This will resolve the issue.

<iframe width='600px' height='600px' ...> </iframe>


Related Topics



Leave a reply



Submit