title: How to build PDF file from binary string returned from a web-service using javascript
body: <p>I am trying to build a PDF file out of a binary stream which I receive as a response from an Ajax request.</p>
  
  <p>Via <code>XmlHttpRequest</code> I receive the following data:</p>
  
  <pre><code>%PDF-1.4....
  .....
  ....hole data representing the file
  ....
  %% EOF
  </code></pre>
  
  <p>What I tried so far was to embed my data via <code>data:uri</code>. Now, there's nothing wrong with it and it works fine. Unfortunately, it does not work in IE9 and Firefox. A possible reason may be that FF and IE9 have their problems with this usage of the <code>data-uri</code>.</p>
  
  <p>Now, I'm looking for any solution that works for all browsers. Here's my code:</p>
  
  <pre><code>// responseText encoding 
  pdfText = $.base64.decode($.trim(pdfText));
  
  // Now pdfText contains %PDF-1.4 ...... data...... %%EOF
  
  var winlogicalname = "detailPDF";
  var winparams = 'dependent=yes,locationbar=no,scrollbars=yes,menubar=yes,'+
              'resizable,screenX=50,screenY=50,width=850,height=1050';
  
  var htmlText = '&lt;embed width=100% height=100%'
                       + ' type="application/pdf"'
                       + ' src="data:application/pdf,'
                       + escape(pdfText)
                       + '"&gt;&lt;/embed&gt;'; 
  
                  // Open PDF in new browser window
                  var detailWindow = window.open ("", winlogicalname, winparams);
                  detailWindow.document.write(htmlText);
                  detailWindow.document.close();
  </code></pre>
  
  <p>As I have said, it works fine with Opera and Chrome (Safari hasn't been tested). Using IE or FF will bring up a blank new window.</p>
  
  <p>Is there any solution like building a PDF file on a file system
  in order to let the user download it? I need the solution that works in all browsers, at least in IE, FF, Opera, Chrome and Safari.</p>
  
  <p>I have no permission to edit the web-service implementation. So it had to be a solution at client-side. Any ideas?</p>