HomePagePrinterDialogViewModel.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Regions;
  4. using Prism.Services.Dialogs;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Windows;
  8. using System.Drawing.Printing;
  9. using ComPDFKit.PDFDocument;
  10. using PDF_Office.Model;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
  14. using System.Threading.Tasks;
  15. using ComPDFKit.PDFPage;
  16. using PDF_Office.Helper;
  17. using System.Drawing.Drawing2D;
  18. using ComPDFKitViewer.PdfViewer;
  19. using System.Windows.Media.Imaging;
  20. using System.Drawing.Imaging;
  21. using PDF_Office.CustomControl;
  22. using Prism.Events;
  23. using ImTools;
  24. using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePagePrinter;
  25. using System.Printing;
  26. using System.Windows.Media.Animation;
  27. using System.Windows.Controls;
  28. using static Dropbox.Api.TeamLog.SharedLinkAccessLevel;
  29. using DryIoc;
  30. using System.Text.RegularExpressions;
  31. using System.Diagnostics;
  32. using PDF_Office.EventAggregators;
  33. using System.Collections.ObjectModel;
  34. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  35. {
  36. public class HomePagePrinterDialogViewModel : BindableBase, IDialogAware
  37. {
  38. public IRegionManager printRegion;
  39. public IDialogService printDialogs;
  40. public IEventAggregator printEvent;
  41. private CPDFViewer PDFViewer;
  42. public PrintSettingsInfo PrintSettingsInfo = new PrintSettingsInfo();
  43. #region 常用字符串
  44. public string Title => "Primter";
  45. public string HomePagePrinterDocumentName = "HomePagePrinterDocumentContent";
  46. public string HomePagePrinterModSizeName = "HomePagePrinterModSizeContent";
  47. public string HomePagePrinterModPosterName = "HomePagePrinterModPosterContent";
  48. public string HomePagePrinterModMultipleName = "HomePagePrinterModMultipleContent";
  49. public string HomePagePrinterModBookletName = "HomePagePrinterModBookletContent";
  50. #endregion
  51. #region 字典
  52. public Dictionary<string, string> GetPrintModNameFromRadioButton = new Dictionary<string, string>();
  53. #endregion
  54. #region 打印系统配置
  55. private readonly PrintServer localDefaultPrintServer = new PrintServer();
  56. private PrintQueue printQueue;
  57. #endregion
  58. #region 打印参数设置
  59. /// <summary>
  60. /// (文档本身的)打印页集合
  61. /// </summary>
  62. private List<int> DocumentTargetPages = new List<int>();
  63. #endregion
  64. private int _printOrientationIndex = 0;
  65. public int PrintOrientationIndex
  66. {
  67. get => _printOrientationIndex;
  68. set => SetProperty(ref _printOrientationIndex, value);
  69. }
  70. #region 相关region
  71. private string _homePagePrinterDocumentRegionName;
  72. public string HomePagePrinterDocumentRegionName
  73. {
  74. get { return _homePagePrinterDocumentRegionName; }
  75. set { _homePagePrinterDocumentRegionName = value; }
  76. }
  77. private string _homePagePrinterModRegionName;
  78. public string HomePagePrinterModRegionName
  79. {
  80. get { return _homePagePrinterModRegionName; }
  81. set { _homePagePrinterModRegionName = value; }
  82. }
  83. #endregion
  84. #region 打印参数设置
  85. /// <summary>
  86. /// 打印机名称
  87. /// </summary>
  88. public string PrinterName;
  89. private int _maxCopiesNumber;
  90. /// <summary>
  91. /// 最大打印份数
  92. /// </summary>
  93. public int MaxCopiesNumber
  94. {
  95. get => _maxCopiesNumber;
  96. set => SetProperty(ref _maxCopiesNumber, value);
  97. }
  98. /// <summary>
  99. /// 打印机支持的颜色
  100. /// </summary>
  101. public List<OutputColor> OutputColorList = new List<OutputColor>();
  102. #endregion
  103. #region 组件
  104. private List<string> _printerNameList;
  105. /// <summary>
  106. /// 打印机名
  107. /// </summary>
  108. public List<string> PrinterNameList
  109. {
  110. get { return _printerNameList; }
  111. set { _printerNameList = value; }
  112. }
  113. private List<string> _printContentList;
  114. /// <summary>
  115. /// 打印内容
  116. /// </summary>
  117. public List<string> PrintContentList
  118. {
  119. get { return _printContentList; }
  120. set { _printContentList = value; }
  121. }
  122. private int _printContentIndex = 0;
  123. public int PrintContentIndex
  124. {
  125. get => _printContentIndex;
  126. set => SetProperty(ref _printContentIndex, value);
  127. }
  128. private List<string> _printerOrientationList;
  129. /// <summary>
  130. /// 打印列表
  131. /// </summary>
  132. public List<string> PrintOrientationList
  133. {
  134. get { return _printerOrientationList; }
  135. set
  136. {
  137. _printerOrientationList = value;
  138. }
  139. }
  140. private int _printerSelectedIndex;
  141. public int PrinterSelectedIndex
  142. {
  143. get => _printerSelectedIndex;
  144. set => SetProperty(ref _printerSelectedIndex, value);
  145. }
  146. #endregion
  147. #region 打印态
  148. private bool _isBothSides;
  149. public bool IsBothSides
  150. {
  151. get => _isBothSides;
  152. set => _isBothSides = value;
  153. }
  154. public enum EnumBothSidesStage
  155. {
  156. StatusFrontSide,
  157. StatusBackSide
  158. }
  159. /// <summary>
  160. /// 双面打印阶段:正面或背面
  161. /// </summary>
  162. public EnumBothSidesStage BothSidesStage;
  163. #endregion
  164. #region 窗口相关参数
  165. private EnumPrintMod currentHomePagePrinterMod;
  166. private string _currentHomePagePrinterModName;
  167. public string CurrentHomePagePrinterModName
  168. {
  169. get => _currentHomePagePrinterModName;
  170. set
  171. {
  172. _currentHomePagePrinterModName = value;
  173. if (value == "HomePagePrinterModSizeContent")
  174. {
  175. currentHomePagePrinterMod = EnumPrintMod.StatusSize;
  176. }
  177. else if (value == "HomePagePrinterModPosterContent")
  178. {
  179. currentHomePagePrinterMod = EnumPrintMod.StatusPoster;
  180. }
  181. else if (value == "HomePagePrinterModMultipleContent")
  182. {
  183. currentHomePagePrinterMod = EnumPrintMod.StatusMultiple;
  184. }
  185. else if (value == "HomePagePrinterModBookletContent")
  186. {
  187. currentHomePagePrinterMod = EnumPrintMod.StatusBooklet;
  188. }
  189. }
  190. }
  191. public bool IsFirstOpen = true;
  192. string Unicode = null;
  193. #endregion
  194. #region 委托
  195. public DelegateCommand CancelCommand { get; set; }
  196. public DelegateCommand ConfirmPrintCommand { get; set; }
  197. public DelegateCommand SetPaperCommand { get; set; }
  198. public DelegateCommand<object> SelectPrinterCommand { get; set; }
  199. public DelegateCommand<object> ChangePrintModCommand { get; set; }
  200. public DelegateCommand<object> SetGrayscaleCommand { get; set; }
  201. public DelegateCommand<object> SetDuplexCommand { get; set; }
  202. public DelegateCommand<object> SetPageRangeSelectionIndexCommand { get; set; }
  203. public DelegateCommand<object> SetCustomPageRangeCommand { get; set; }
  204. public DelegateCommand<object> SetPrintContentCommand { get; set; }
  205. public DelegateCommand<object> SetReversePageCommand { get; set; }
  206. public DelegateCommand<object> SetPrintBorderCommand { get; set; }
  207. public DelegateCommand<object> SetPrintOritationCommand { get; set; }
  208. #endregion
  209. HomePagePrinterDialogViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  210. {
  211. this.printRegion = regionManager;
  212. this.printDialogs = dialogService;
  213. this.printEvent = eventAggregator;
  214. HomePagePrinterDocumentRegionName = Guid.NewGuid().ToString();
  215. HomePagePrinterModRegionName = Guid.NewGuid().ToString();
  216. CancelCommand = new DelegateCommand(Cancel);
  217. ConfirmPrintCommand = new DelegateCommand(ConfirmPrint);
  218. SetPaperCommand = new DelegateCommand(SetPaper);
  219. SelectPrinterCommand = new DelegateCommand<object>(SelectPrinter);
  220. ChangePrintModCommand = new DelegateCommand<object>(ChangePrintMod);
  221. SetGrayscaleCommand = new DelegateCommand<object>(SetGrayscale);
  222. SetDuplexCommand = new DelegateCommand<object>(SetDuplex);
  223. SetPageRangeSelectionIndexCommand = new DelegateCommand<object>(SetPageRangeSelectionIndex);
  224. SetCustomPageRangeCommand = new DelegateCommand<object>(SetCustomPageRange);
  225. SetPrintContentCommand = new DelegateCommand<object>(SetPrintContent);
  226. SetReversePageCommand = new DelegateCommand<object>(SetReversePage);
  227. SetPrintBorderCommand = new DelegateCommand<object>(SetPrintBorder);
  228. SetPrintOritationCommand = new DelegateCommand<object>(SetPrintOritation);
  229. Unicode = Guid.NewGuid().ToString();
  230. InitComponent();
  231. InitDictionary();
  232. InitParams();
  233. printEvent.GetEvent<SendPrintSettingsModInfoEvent>().Subscribe(RecvPrintSettingsModInfo, e => e.Unicode == Unicode);
  234. }
  235. private void InitComponent()
  236. {
  237. InitPrinterNameList();
  238. InitPrintContentList();
  239. InitPrintOrientationList();
  240. }
  241. private void InitDictionary()
  242. {
  243. InitGetPrintModNameFromRadioButton();
  244. }
  245. private void InitParams()
  246. {
  247. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  248. List<PageMediaSize> PageMediaSizeList = new List<PageMediaSize>();
  249. foreach (PageMediaSize size in printQueue.GetPrintCapabilities().PageMediaSizeCapability)
  250. {
  251. if (size == null || size.PageMediaSizeName == null)
  252. {
  253. continue;
  254. }
  255. if (size.PageMediaSizeName == PageMediaSizeName.ISOA4)
  256. {
  257. PrintSettingsInfo.PageMediaSize = size;
  258. }
  259. PageMediaSizeList.Add(size);
  260. }
  261. if (PrintSettingsInfo.PageMediaSize == null)
  262. {
  263. PrintSettingsInfo.PageMediaSize = PageMediaSizeList[0];
  264. }
  265. }
  266. private void InitPrinterNameList()
  267. {
  268. PrinterNameList = new List<string>();
  269. PrintDocument printDocument = new PrintDocument();
  270. string defaultPrinterName = printDocument.PrinterSettings.PrinterName;
  271. foreach (string printerListItem in PrinterSettings.InstalledPrinters)
  272. {
  273. PrinterNameList.Add(printerListItem);
  274. }
  275. if (PrinterNameList.Contains("Microsoft Print to PDF"))
  276. {
  277. PrinterSelectedIndex = PrinterNameList.IndexOf("Microsoft Print to PDF");
  278. }
  279. else
  280. {
  281. PrinterSelectedIndex = 0;
  282. }
  283. PrinterName = PrinterNameList[PrinterSelectedIndex];
  284. }
  285. private void InitPrintContentList()
  286. {
  287. PrintContentList = new List<string>();
  288. PrintContentList.Add("文档");
  289. PrintContentList.Add("文档和标记");
  290. PrintContentList.Add("文档和图章");
  291. PrintContentList.Add("文档和表单");
  292. }
  293. private void InitPrintOrientationList()
  294. {
  295. PrintOrientationList = new List<string>();
  296. PrintOrientationList.Add("纵向");
  297. PrintOrientationList.Add("横向");
  298. }
  299. public void InitGetPrintModNameFromRadioButton()
  300. {
  301. GetPrintModNameFromRadioButton.Clear();
  302. GetPrintModNameFromRadioButton.Add("ModSizeRdo", HomePagePrinterModSizeName);
  303. GetPrintModNameFromRadioButton.Add("ModPosterRdo", HomePagePrinterModPosterName);
  304. GetPrintModNameFromRadioButton.Add("ModMultipleRdo", HomePagePrinterModMultipleName);
  305. GetPrintModNameFromRadioButton.Add("ModBookletRdo", HomePagePrinterModBookletName);
  306. }
  307. public void AutoOritation()
  308. {
  309. //纸张长边为高
  310. //if (PrintSettingsInfo.PageMediaSize.Height / PrintSettingsInfo.PageMediaSize.Width >= 1)
  311. //{
  312. // //PDF长边为高
  313. // if (PDFViewer.Document.GetPageSize(0).Height / PDFViewer.Document.GetPageSize(0).Width >= 1)
  314. // {
  315. // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusPortrait;
  316. // }
  317. // //PDF长边为宽
  318. // else
  319. // {
  320. // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
  321. // }
  322. //}
  323. ////纸张短边为高
  324. //else
  325. //{
  326. // //PDF长边为高
  327. // if (PDFViewer.Document.GetPageSize(0).Height / PDFViewer.Document.GetPageSize(0).Width >= 1)
  328. // {
  329. // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
  330. // }
  331. // //PDF长边为宽
  332. // else
  333. // {
  334. // PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusPortrait;
  335. // }
  336. //}
  337. //PrintOrientationIndex = (int)PrintSettingsInfo.EnumPrintOrientation;
  338. }
  339. public void InitParamsByPDFView()
  340. {
  341. AutoOritation();
  342. }
  343. /// <summary>
  344. /// 选择打印机
  345. /// </summary>
  346. /// <param name="e"></param>
  347. public void SelectPrinter(object e)
  348. {
  349. var comboBox = e as ComboBox;
  350. PrinterName = comboBox.SelectedItem.ToString();
  351. }
  352. /// <summary>
  353. /// 打开纸张设置窗口
  354. /// </summary>
  355. public void SetPaper()
  356. {
  357. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  358. LoadPrinterSettings();
  359. DialogParameters value = new DialogParameters();
  360. value.Add("Unicode", Unicode);
  361. value.Add(ParameterNames.PrintQueue, printQueue);
  362. printDialogs.ShowDialog(DialogNames.HomePagePrinterPaperSettingsDialog, value, e =>
  363. {
  364. if (e.Result == ButtonResult.OK)
  365. {
  366. PrintSettingsInfo.PageMediaSize = e.Parameters.GetValue<PageMediaSize>("PageMediaSize");
  367. PrintSettingsInfo.Margin.Clear();
  368. PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginLeft"));
  369. PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginTop"));
  370. PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginRight"));
  371. PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginBottom"));
  372. AutoOritation();
  373. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  374. }
  375. });
  376. }
  377. public void ChangePrintMod(object e)
  378. {
  379. var rdo = e as RadioButton;
  380. CurrentHomePagePrinterModName = GetPrintModNameFromRadioButton[rdo.Name];
  381. NavigationParameters param = new NavigationParameters();
  382. param.Add("document", PDFViewer.Document);
  383. param.Add("Unicode", Unicode);
  384. printRegion.RequestNavigate(HomePagePrinterModRegionName, CurrentHomePagePrinterModName, param);
  385. }
  386. /// <summary>
  387. /// 加载对应打印设置
  388. /// </summary>
  389. public void LoadPrinterSettings()
  390. {
  391. if (printQueue.GetPrintCapabilities().MaxCopyCount.HasValue)
  392. {
  393. MaxCopiesNumber = printQueue.GetPrintCapabilities().MaxCopyCount.Value;
  394. }
  395. else
  396. {
  397. MaxCopiesNumber = 1;
  398. }
  399. OutputColorList.Clear();
  400. foreach (OutputColor color in printQueue.GetPrintCapabilities().OutputColorCapability)
  401. {
  402. OutputColorList.Add(color);
  403. }
  404. }
  405. #region 来自UI的设置
  406. /// <summary>
  407. /// 设置灰度
  408. /// 改变打印机设置
  409. /// 改变渲染
  410. /// </summary>
  411. public void SetGrayscale(object e)
  412. {
  413. var chk = e as CheckBox;
  414. if ((bool)chk.IsChecked)
  415. {
  416. PrintSettingsInfo.IsGrayscale = true;
  417. }
  418. else if (!(bool)chk.IsChecked)
  419. {
  420. PrintSettingsInfo.IsGrayscale = false;
  421. }
  422. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  423. }
  424. /// <summary>
  425. /// 设置双面打印
  426. /// 改变打印流程
  427. /// 不改变打印相关参数
  428. /// </summary>
  429. /// <param name="e"></param>
  430. public void SetDuplex(object e)
  431. {
  432. var chk = e as CheckBox;
  433. if ((bool)chk.IsChecked)
  434. {
  435. PrintSettingsInfo.IsDuplex = true;
  436. }
  437. else if (!(bool)chk.IsChecked)
  438. {
  439. PrintSettingsInfo.IsDuplex = false;
  440. }
  441. }
  442. public void SetPageRangeSelectionIndex(object e)
  443. {
  444. var cmb = e as WritableComboBox;
  445. PrintSettingsInfo.PageRangeList.Clear();
  446. PrintSettingsInfo.EnumPageRange = (EnumPageRange)int.Parse(cmb.SelectedIndex);
  447. if (int.Parse(cmb.SelectedIndex) < cmb.Items.Count - 1)
  448. {
  449. PrintSettingsInfo.EnumPageRange = (EnumPageRange)int.Parse(cmb.SelectedIndex);
  450. if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusAllRange)
  451. {
  452. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  453. {
  454. PrintSettingsInfo.PageRangeList.Add(temp);
  455. }
  456. }
  457. else if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusOddRange)
  458. {
  459. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
  460. {
  461. PrintSettingsInfo.PageRangeList.Add(temp);
  462. }
  463. }
  464. else if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusEvenRange)
  465. {
  466. //TODO: 偶数页页数不够异常
  467. if (PDFViewer.Document.PageCount <= 1)
  468. {
  469. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  470. {
  471. PrintSettingsInfo.PageRangeList.Add(temp);
  472. }
  473. }
  474. else
  475. {
  476. for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
  477. {
  478. PrintSettingsInfo.PageRangeList.Add(temp);
  479. }
  480. }
  481. }
  482. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  483. }
  484. }
  485. public void SetCustomPageRange(object e)
  486. {
  487. if (PrintSettingsInfo.EnumPageRange == EnumPageRange.StatusCustomizedRange)
  488. {
  489. var cmb = e as WritableComboBox;
  490. if (cmb == null)
  491. {
  492. return;
  493. }
  494. if (!CommonHelper.GetPagesInRange(ref DocumentTargetPages, cmb.Text, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  495. { //TODO
  496. Trace.WriteLine("输入不对");
  497. MessageBoxEx.Show("输入不对");
  498. return;
  499. }
  500. PrintSettingsInfo.PageRangeList.Clear();
  501. PrintSettingsInfo.PageRangeList = DocumentTargetPages;
  502. }
  503. }
  504. public void SetPrintOritation(object e)
  505. {
  506. var cmb = e as ComboBox;
  507. PrintSettingsInfo.EnumPrintOrientation = (EnumPrintOrientation)cmb.SelectedIndex;
  508. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  509. }
  510. public void SetPrintContent(object e)
  511. {
  512. var cmb = e as ComboBox;
  513. if (cmb.SelectedIndex == (int)EnumPrintContent.StatusOnlyDocument)
  514. {
  515. PrintSettingsInfo.IsPrintWithAnnot = false;
  516. PrintSettingsInfo.IsPrintWithForm = false;
  517. }
  518. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndMarkUps)
  519. {
  520. PrintSettingsInfo.IsPrintWithAnnot = true;
  521. PrintSettingsInfo.IsPrintWithForm = true;
  522. }
  523. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndStamps)
  524. {
  525. PrintSettingsInfo.IsPrintWithAnnot = true;
  526. PrintSettingsInfo.IsPrintWithForm = false;
  527. }
  528. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndForm)
  529. {
  530. PrintSettingsInfo.IsPrintWithAnnot = false;
  531. PrintSettingsInfo.IsPrintWithForm = true;
  532. }
  533. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  534. }
  535. public void SetReversePage(object e)
  536. {
  537. PrintSettingsInfo.PageRangeList.Reverse();
  538. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  539. }
  540. public void SetPrintBorder(object e)
  541. {
  542. var chk = e as CheckBox;
  543. if ((bool)chk.IsChecked)
  544. {
  545. PrintSettingsInfo.IsPrintPageBorde = true;
  546. }
  547. else
  548. {
  549. PrintSettingsInfo.IsPrintPageBorde = false;
  550. }
  551. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  552. }
  553. public void RecvPrintSettingsModInfo(PrintModInfoWithUnicode printModInfoWithUnicode)
  554. {
  555. if (printModInfoWithUnicode.printModInfo.EnumPrintMod == currentHomePagePrinterMod)
  556. {
  557. PrintSettingsInfo.printModInfo = printModInfoWithUnicode.printModInfo;
  558. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  559. }
  560. }
  561. #endregion
  562. public void Cancel()
  563. {
  564. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  565. }
  566. public void NavigateDocumentRegion()
  567. {
  568. NavigationParameters param = new NavigationParameters();
  569. param.Add(ParameterNames.PDFViewer, PDFViewer);
  570. param.Add(ParameterNames.PrintSettingsInfo, PrintSettingsInfo);
  571. param.Add("Unicode", Unicode);
  572. printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
  573. }
  574. public void NavigateModRegion()
  575. {
  576. NavigationParameters param = new NavigationParameters();
  577. param.Add(ParameterNames.PDFViewer, PDFViewer);
  578. param.Add("Unicode", Unicode);
  579. printRegion.RequestNavigate(HomePagePrinterModRegionName, HomePagePrinterModSizeName);
  580. }
  581. /// <summary>
  582. /// 确认打印,单面或手动双面
  583. /// </summary>
  584. public void ConfirmPrint()
  585. {
  586. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  587. LoadPrinterSettings();
  588. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode {printQueue= this.printQueue ,Unicode = this.Unicode});
  589. //Collection<Duplexing> list = new Collection<Duplexing>();
  590. //if (printQueue.GetPrintCapabilities().DuplexingCapability.Count > 0)
  591. //{
  592. // list.Clear();
  593. // for (int temp = 0; temp < printQueue.GetPrintCapabilities().DuplexingCapability.Count; temp++)
  594. // {
  595. // list.Add(printQueue.GetPrintCapabilities().DuplexingCapability[temp]);
  596. // }
  597. //}
  598. //if (!IsBothSides)
  599. //{
  600. // RequestClose.Invoke(new DialogResult(ButtonResult.OK));
  601. //}
  602. //else if (IsBothSides)
  603. //{
  604. // MessageBoxEx.Show("翻页");
  605. //}
  606. }
  607. public event Action<IDialogResult> RequestClose;
  608. public bool CanCloseDialog()
  609. {
  610. return true;
  611. }
  612. public void OnDialogClosed()
  613. {
  614. this.printQueue.Dispose();
  615. }
  616. public void OnDialogOpened(IDialogParameters parameters)
  617. {
  618. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  619. if (PDFViewer != null)
  620. {
  621. //文件损坏导致无法读取
  622. try
  623. {
  624. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  625. {
  626. PrintSettingsInfo.PageRangeList.Add(temp);
  627. }
  628. NavigationParameters param = new NavigationParameters();
  629. NavigateDocumentRegion();
  630. NavigateModRegion();
  631. InitParamsByPDFView();
  632. }catch
  633. {
  634. PDFViewer = null;
  635. }
  636. }
  637. }
  638. }
  639. }