title: Is there a way of writing PDF byte data to an IFrame clientside
body: <p>Odd question I know but say one has PDF byte data contained within a hidden field on a page which also has an IFrame on it.</p>
  
  <p>Is there a way of writing the pdf data to the IFrame using JavaScript such that the IFrame will load in the adobe plug-in and display the data?</p>
  
  <p>The reason we'd like to do this is that we need the PDF data in the hidden field anyway so if the user clicks a button we can call a Java applet via JS with the data so it writes the PDF byte data to a proprietary system.  We'd also like to display the PDF as well.</p>
  
  <p>So: </p>
  
  <ol>
  <li>PDF byte data (generated on the
  server) chucked in the hidden field.</li>
  <li>PDF byte data from hidden field
  written clientside to IFrame by some
  <em>soon-to-be-discovered-via-the-wonders-of-StackOverflow</em>
  JS magic and thus displayed.</li>
  <li>When button clicked Java applet called clientside
  passing in PDF byte data stored in
  hidden field</li>
  </ol>
  
  <p>Just like Southpark's underpant gnomes we've got phase 1 and 3 but not 2!</p>
  
  <p>Any ideas gratefully received!</p>
  
  <p>Further info:</p>
  
  <p>We need to have the byte data available on the client side to be passed via a JS call to a Java applet. We do this currently via a hidden field. That's okay and it works just fine.</p>
  
  <p>The problem is that the call to the applet only takes place if the okay button on an ajax modal dilaog is clicked ('Do you want to send this document to UglyProprietorySystem?').</p>
  
  <p>As you all know you can't put anything on top of an adobe plug-in display. Obviously if the whole page is of type PDF then there's no place for any JS to show the dialog so that wouldn't work and if you use an IFrame you still can't put anything on top of what the plug-in displays (it's effectively another app's airspace and violating that is just plain rude!).</p>
  
  <p>We worked around this by:</p>
  
  <ol>
  <li>Inititally showing a blurred image of a generic PDF doc and popping the modal dialog on top of that.</li>
  <li>When the user had responded to the dialog we called (or not) the java app with the pdf byte data from the hiden field</li>
  <li>We then posted back after clearing the hidden field (Woo! Posting back a form with PDF binary data is not appreciated by the server!)</li>
  <li>In the page_load of the code behind we then, on postback, wrote to the response stream with he PDF byte data, setting the contentype to be appplication/pdf and thus the pdf is displayed.</li>
  </ol>
  
  <p>Lovely. It all works and gets us kind of what we'd like.</p>
  
  <p>Only problem is we either need to:</p>
  
  <pre><code>* generate the PDF data twice (once on initital page_load for the clientside call to our applet and then again on postback to display).
  </code></pre>
  
  <p>or</p>
  
  <pre><code>* We store the PDF byte data in the session after the first response so as to be able to, after the postback, still have the pdf data to be able to display it.
  </code></pre>
  
  <p>Neither is great but we went with the latter but now we're thinking we'd like to avoid that if we can.</p>
  
  <p>Thus the idea of generating the PDF, putting it into a hidden field, having a button on the page to save the PDF to our proprietary system via an applet call and also writing to the IFrame with that data already on the client in the hidden field thus displaying it.</p>
  
  <p>Phew!</p>
  
  <p>So that's why we wanted to on the client using JS, write the pdf binary data to the IFrame and have it's content type set to application/pdf so the browser would load up the adobe plug-in and display it.</p>