title: Read dynamic PDF from Ruby Watir
body: <p>I am using Watir to log into an application, push some buttons, etc... Basically the normal stuff that a person would use Watir for.</p>
  
  <p>However, my problem is that there is one particular page that I need to test. It's actually a dynamically-generated PDF and I need to get the actual binary data from it, so that I can load it using a certain gem that we're using. This normally works with static PDF files because we can just use:</p>
  
  <pre><code>    open("http://site.com/something.pdf")
  </code></pre>
  
  <p>This works for static PDFs. However, for a dynamically generated one it doesn't work because we are using Ruby to send the HTTP request and it is not aware of the headers/cookies/session that Watir is using. So instead of getting the actual PDF we get a login page.</p>
  
  <p>Another thing we tried was to use Watir to get the PDF:</p>
  
  <pre><code>    @browser.goto "http://site.com/dynamic/thepdffile"
      @browser.text
      @browser.html
  </code></pre>
  
  <p>We tried getting the text or html from the page, but no luck because firefox creates a DOM when loading a pdf so the text is an empty string and the html is the DOM that firefox creates when viewing a pdf page. We need the raw HTTP response and there doesn't seem to be a way to extract that.</p>
  
  <p>So we need a solution for this and in my opinion we have these options:</p>
  
  <ol>
  <li>Figure out a way to use "open" or similar method in Ruby, using the session from Watir.</li>
  <li>Figure out how to use watir to get the binary http response from the PDF page.</li>
  <li>Disable the pdf plugin (which doesn't seem possible) such that the "save as" dialog appears.</li>
  </ol>
  
  <p>Or if you have some other idea please share! Thanks in advance!</p>