PDFPreview.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Navigation;
  4. using System.Windows.Threading;
  5. using InABox.Wpf;
  6. using InABox.WPF;
  7. namespace InABox.DynamicGrid
  8. {
  9. /// <summary>
  10. /// Interaction logic for PrintPreview.xaml
  11. /// </summary>
  12. public partial class PDFPreview : ThemableWindow
  13. {
  14. private readonly string _filename = "";
  15. private bool bPrinted;
  16. private WaitCursor cursor;
  17. public PDFPreview(string filename)
  18. {
  19. InitializeComponent();
  20. cursor = new WaitCursor();
  21. _filename = filename;
  22. }
  23. private void Browser_LoadCompleted(object sender, NavigationEventArgs e)
  24. {
  25. //MessageBox.Show("Loaded");
  26. var timer = new DispatcherTimer();
  27. timer.Interval = new TimeSpan(0, 0, 2);
  28. timer.Tick += (ot, et) =>
  29. {
  30. if (!bPrinted)
  31. {
  32. cursor.Dispose();
  33. cursor = null;
  34. //MessageBox.Show("Printing!");
  35. //IHTMLDocument2 doc = browser.Document as IHTMLDocument2;
  36. //doc.execCommand("Print", true, null);
  37. bPrinted = true;
  38. }
  39. else
  40. {
  41. timer.IsEnabled = false;
  42. //MessageBox.Show("Closing!");
  43. Close();
  44. }
  45. };
  46. timer.Start();
  47. }
  48. private void Window_Loaded(object sender, RoutedEventArgs e)
  49. {
  50. var html = string.Format(
  51. "<html><embed src=\"file:///{0}\" type=\"application/x-pdf\" title=\"Pdf Preview\" width=\"100%\" height=\"100%\" /></html>",
  52. _filename);
  53. browser.NavigateToString(html);
  54. }
  55. }
  56. }