title: Print PDF Created in iTextSharp and then Return Control to Browser
body: <p>This is somewhat of a return to my 2012 question - <a href="https://stackoverflow.com/questions/13307468/is-it-possible-to-fire-a-keypress-event-for-an-iframe-that-has-been-used-to-load">Is it possible to fire a keypress event for an iframe that has been used to load a PDF file</a>, I think I may have been mistaken accepting the answer there.</p>
  
  <p>The current situation is this -</p>
  
  <ul>
  <li>The <code>document</code> of the main page has an <code>onkeypress</code> event attached to it which will load a PDF into an object when the user scans a particular barcode.</li>
  <li>The PDF is created using iTextSharp and has the open action set - <code>writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG))</code> (<code>writer</code> is a <code>PdfWriter</code>).</li>
  </ul>
  
  <p>So a user will scan the barcode which automatically loads a PDF file which opens it's print dialog. The user will then choose the printer and print the PDF.  The problem comes when the user wants to scan the next unit they need to click somewhere within the html body (but outside of the PDF object) and <em>then</em> scan the barcode for the new PDF to be loaded.</p>
  
  <p>I had a look at <a href="http://www.javabeat.net/javascript-communication-between-html-and-pdf-in-itext/" rel="nofollow noreferrer">this</a> and saw that it is possible to setup some kind of communication between the PDF plugin and the browser but is is possible to tell the plugin to surrender control to the browser/javascript</p>
  
  <p><strong>EDIT</strong>
   Some extra background information -</p>
  
  <ul>
  <li>I've tried using both objects and and iframes.</li>
  <li>Using the debugger, if I type <code>document.activeElement.id</code> gives the ID of an element an appropriate element however (in the case of text inputs) any key presses do not appear.</li>
  <li>Using the debugger I can use blur the active element bring focus to another element even change the value of an input but no user input is seen by the HTML/javascript when the user types/scans.</li>
  <li>This is a legacy application runs in Internet Explorer compatibility mode.</li>
  </ul>
  
  <p>Just to sum up - I want to scan a barcode which will open a PDF (already done) which opens it's print dialog automatically (already done) the user prints the PDF and then without any further human interaction with the page (i.e. the user does not need to use the mouse or keyboard after clicking the print button in the print dialog) the user should be able to scan another barcode which will open a new PDF.</p>