title: InfoPath C# Button: Switch View then Export to PDF
body: <p>I've seen some questions which might be related but don't really answer the question. I've got an InfoPath 2013 form that's being hosted via SharePoint 2013 InfoPath Forms Services. The form has code-behind, and I'm trying to code a button so that it does the following steps:</p>
  
  <ol>
  <li>Switch to a read-only, pre-formatted print view (NOT the default, which is data entry)</li>
  <li>Export that view of the form to a PDF</li>
  <li>Save the form</li>
  <li>Close the form</li>
  </ol>
  
  <p>Through googling, I've found some solutions that get me close but I keep running into issues like thisXDocument not being recognized in the context, or the Export method not being valid. I'm currently using both "Microsoft.Office.Interop.InfoPath" and "Microsoft.Office.Interop.InfoPath.SemiTrust" as references. I'm working in Visual Studio 2012.</p>
  
  <p>Given the requirements above, can this be done via C# code and (if so) what namespaces are needed?</p>