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

sudhir
  • 1,387
  • 3
  • 25
  • 43
  • 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. – yavuzkavus Apr 08 '17 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')** – yavuzkavus Apr 08 '17 at 15:55
  • I have modified question, can you please check now, in forefox its opening, but in chrome its downloading instead opwning – sudhir Apr 08 '17 at 16:00

1 Answers1

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.

yavuzkavus
  • 1,268
  • 11
  • 17