Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. browser.Print();
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Drawing.Printing;
  11. using System.Runtime.InteropServices;
  12.  
  13. namespace ConsoleApp1
  14. {
  15. class Program
  16. {
  17. static void Main(string[] args)
  18. {
  19. foreach (var item in PrinterSettings.InstalledPrinters)
  20. {
  21. Console.WriteLine(item.ToString());
  22. }
  23. string pname = "Nuance PDF";
  24. myPrinters.SetDefaultPrinter(pname);
  25. PrintHelpPage();
  26. Console.ReadKey();
  27. }
  28.  
  29. public static class myPrinters
  30. {
  31. [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
  32. public static extern bool SetDefaultPrinter(string Name);
  33.  
  34. }
  35.  
  36. public static void PrintHelpPage()
  37. {
  38. var th = new Thread(() => {
  39. var br = new WebBrowser();
  40. br.DocumentCompleted += PrintDocument;
  41. br.Navigate("http://oneguggenheim/compliance/Pages/EAA/EAAConsolidatedForm.aspx?AttestationTaskID=65033");
  42. Application.Run();
  43. });
  44. th.SetApartmentState(ApartmentState.STA);
  45. th.Start();
  46. }
  47.  
  48. public static void PrintDocument(object sender,
  49. WebBrowserDocumentCompletedEventArgs e)
  50. {
  51. var browser = sender as WebBrowser;
  52. // Print the document now that it is fully loaded.
  53. browser.Print();
  54. Console.WriteLine("Natigated to {0}", e.Url);
  55. // Dispose the WebBrowser now that the task is complete.
  56. browser.Dispose();
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement