title: Programmatically printing WebBrowser and setting its PrinterSettings in VB
body: <p>I am trying to find a way to set <code>PrinterSettings</code> when printing contents of WebBrowser similar to the following code</p>
  <pre><code>Dim doc As PrintDocument = New PrintDocument()
  With doc
       .PrinterSettings = New PrinterSettings()
       With .PrinterSettings
            .PrinterName = &quot;PrinterName&quot;
            .PrintToFile = True
            .PrintFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + &quot;test.pdf&quot;)
       End With
  End With
  doc.Print()
  </code></pre>
  <p>I converted this from a C# code I've found that tells how to set <code>PrinterSettings</code> programmatically.</p>
  <p>Is there a way to combine the code above with <code>WebBrowser.Print()</code> in order to print HTML and set <code>PrinterSettings</code> programmatically</p>
  <p>I have tried doing it like this thinking that this code might set default printer to <code>Microsoft Print to PDF</code></p>
  <pre><code>Dim doc As PrintDocument = New PrintDocument()
  With doc
       .PrinterSettings = New PrinterSettings()
       With .PrinterSettings
            .PrinterName = &quot;Microsoft Print to PDF&quot;
            .PrintToFile = True
            .PrintFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + &quot;test.pdf&quot;)
       End With
  End With
  WebBrowser.Print()
  </code></pre>
  <p>But it prints on the default printer and not on <code>Microsoft Print to PDF</code></p>
  <p>Edit: The WebBrowser contains the document I'm trying to print in HTML Format and some inline CSS. The WebBrowser don't have a UI, It is a plain code Declared as <code>Private WithEvents WebBrowser As WebBrowser</code>. Hope this helps clear my problem, thanks.</p>
  <p>Edit(2): Setting the Default Printer have been problematic to me because of the printer setting &quot;let windows manage my printers.&quot; Unchecking this allow the application to set the default printer. <em>credits to K J</em></p>