1

HI I have base64 binary data for pdf and I'm trying to open in new window, it is getting downloaded but not opening , the new window is empty with about blank

<a click="openfile(sampledoc)"  href="#"><img src="some.png" /></a>

function openfile(binaryData){
 window.open('data:application/pdf;base64,'+binaryData, 'samplepdf', 'width=700px,height=600px');
}

Pdf is downloading perfectly but its not displaying in the opened window.

Pdf is displaying in new tab in firefox but in chrome its downloading but not displaying

3
  • What do you mean by base64 binary data? Base64 is a text form in the range of A–Z, a–z, 0–9 and = sign. Commented Apr 8, 2017 at 15:51
  • and the window.open signature is window.open(URL, name, specs, replace). So you should remove one of '_blank' or 'window'. Both does the same, except 'window' name can be used as a target. window.open('data:application/pdf;base64,'+binaryData, 'aMoreDescriptiveName', 'width=700px,height=600px') Commented Apr 8, 2017 at 15:55
  • I have modified question, can you please check now, in forefox its opening, but in chrome its downloading instead opwning Commented Apr 8, 2017 at 16:00

1 Answer 1

2

I tried this on both firefox and chrome, it was opened in a new window instead of downloading.

window.open("data:application/pdf;base64,JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwogIC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAvTWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0KPj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAgL1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9udAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2JqCgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAwMDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9vdCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G", "mypdf", "width=700px,height=600px");

May be it is related to chrome settings on your machine. Please try from another machine.

Opening/printing pdf on browsers is problematic. Some browsers open using adobe plugin, some uses pdf.js, some uses other methods, some downloads instead of opening.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.