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
Search in jspdf.js this:
if(type == 'datauri') {
document.location.href ='data:application/pdf;base64,' + Base64.encode(buffer);
}Add :
if(type == 'datauriNew') {
window.open('data:application/pdf;base64,' + Base64.encode(buffer));
}- 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
React Button Onclick Redirect Page
How to Include External JavaScript Library in Reactjs
How Get Total Sum from Input Box Values Using JavaScript
Jquery Validation Code for Not Allowed Only Blank Space in Textbox
Cannot Access Json Object Property Returns Undefined
Change Button Color When Click on the Button
Webpack: Module Not Found: Error: Can't Resolve (With Relative Path)
Websocket Connection Failed: Error During Websocket Handshake: Unexpected Response Code: 400
How to Disable Onclick Without Altering Its Function
How to Use If Statement Inside Json
How to Show Which Question a User Is on When Taking My Quiz
How to Render a Word Document (.Doc, .Docx) in the Browser Using JavaScript
Retrieving Keys from Json Array Key-Value Pair Dynamically - JavaScript
Random Numbers Between 1 and 50; 50 Times
Regex Pattern to Match At Least 1 Number and 1 Character in a String
How to Bind on Click Event on Dynamically Created Button in Angular 6