1

I want to show a PDF file preview in a browser window. When user clicks on a PDF file I want to open a new browser window and show that PDF file in it. I understand that browser can render a PDF file by itself without needing any third party libraries. So this is what I'm doing:

window.open(LinkToPDF,'_blank','width=800, height=900'); 

This does open a new window, but instead of showing a PDF it downloads it. What am I doing wrong? If I just open some PDF url in a browser it shows me the PDF then why is this code downloading that PDF instead?


EDIT: In the PDF URL content-disposition header is set as attachment which is forcing browser to download the file, is there any way to ignore this header or just download the content in javascript and display it.

sublime
  • 3,675
  • 9
  • 46
  • 83
  • In general it depends on the configuration that you're using for browser. Also it can opens if is on the _blank. Please be specific on browser and version – Leandro Oct 30 '14 at 23:46
  • 1
    the URL does not have .pdf in the end? could that be the reason? How do I create an Iframe saying that it's a PDF? – sublime Oct 30 '14 at 23:48
  • +1 for interesting question – Leandro Oct 30 '14 at 23:57

1 Answers1

0

Try with:

function newwin(url,w,h) {
     var win = window.open("","temp","width="+w+",height="+h+",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes");
     win.location.href = url;
     win.focus();
}

UPDATE:

You must specify the content with extension and/or headers

Leandro
  • 6,537
  • 12
  • 59
  • 95
  • could you say what browser, version are you using? Is your pdf a direct url to a file or are you creating dinamically the response? – Leandro Oct 30 '14 at 23:52
  • no I cannot, but there has to be way, dropbox does it ( i just checked dropbox urls and they do not have .pdf in the end either) – sublime Oct 30 '14 at 23:55
  • I don't think dropbox works on that way, I suposse that the header contains the specific information of the file format/type. Some browsers download the file with a wrong/missing header/extension. Are you using plain HTML or you can read it with some programically httpclient, as with C# ? – Leandro Oct 30 '14 at 23:57
  • no I'm using plain HTML, I just need to launch an iFrame in a new window I don't know how to do that – sublime Oct 30 '14 at 23:58
  • 1
    Iframe will work as any another window/browser. You -must- correct the miss-specification. Read more about it: http://stackoverflow.com/questions/18728215/link-to-a-pdf-in-html-the-file-has-no-extension-but-i-know-it-is-pdf-how-to-ma – Leandro Oct 31 '14 at 00:01