HomePagePrinterDialogViewModel.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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_Master.Model;
  11. using System.Drawing;
  12. using System.Reflection;
  13. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePagePrinter;
  14. using System.Threading.Tasks;
  15. using ComPDFKit.PDFPage;
  16. using PDF_Master.Helper;
  17. using System.Drawing.Drawing2D;
  18. using ComPDFKitViewer.PdfViewer;
  19. using System.Windows.Media.Imaging;
  20. using System.Drawing.Imaging;
  21. using PDF_Master.CustomControl;
  22. using Prism.Events;
  23. using ImTools;
  24. using PDF_Master.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_Master.EventAggregators;
  33. using System.Collections.ObjectModel;
  34. using System.Windows.Forms;
  35. using ComboBox = System.Windows.Controls.ComboBox;
  36. using CheckBox = System.Windows.Controls.CheckBox;
  37. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  38. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
  39. {
  40. public class HomePagePrinterDialogViewModel : BindableBase, IDialogAware
  41. {
  42. #region 文案
  43. private string T_title;
  44. public string T_Title
  45. {
  46. get { return T_title; }
  47. set
  48. {
  49. SetProperty(ref T_title, value);
  50. }
  51. }
  52. private string T_printer;
  53. public string T_Printer
  54. {
  55. get { return T_printer; }
  56. set
  57. {
  58. SetProperty(ref T_printer, value);
  59. }
  60. }
  61. private string T_pageSettings;
  62. public string T_PageSettings
  63. {
  64. get { return T_pageSettings; }
  65. set
  66. {
  67. SetProperty(ref T_pageSettings, value);
  68. }
  69. }
  70. private string T_copies;
  71. public string T_Copies
  72. {
  73. get { return T_copies; }
  74. set
  75. {
  76. SetProperty(ref T_copies, value);
  77. }
  78. }
  79. private string T_blackAndWhite;
  80. public string T_BlackAndWhite
  81. {
  82. get { return T_blackAndWhite; }
  83. set
  84. {
  85. SetProperty(ref T_blackAndWhite, value);
  86. }
  87. }
  88. private string T_printSettings;
  89. public string T_PrintSettings
  90. {
  91. get { return T_printSettings; }
  92. set
  93. {
  94. SetProperty(ref T_printSettings, value);
  95. }
  96. }
  97. private string T_orientation;
  98. public string T_Orientation
  99. {
  100. get { return T_orientation; }
  101. set
  102. {
  103. SetProperty(ref T_orientation, value);
  104. }
  105. }
  106. private string T_printContent;
  107. public string T_PrintContent
  108. {
  109. get { return T_printContent; }
  110. set
  111. {
  112. SetProperty(ref T_printContent, value);
  113. }
  114. }
  115. private string T_reversePages;
  116. public string T_ReversePages
  117. {
  118. get { return T_reversePages; }
  119. set
  120. {
  121. SetProperty(ref T_reversePages, value);
  122. }
  123. }
  124. private void InitString()
  125. {
  126. T_Title = App.MainPageLoader.GetString("Print_Title");
  127. T_Printer = App.MainPageLoader.GetString("Print_Printer");
  128. T_PageSettings = App.MainPageLoader.GetString("Print_PageSettings");
  129. T_Copies = App.MainPageLoader.GetString("Print_Copies");
  130. T_BlackAndWhite = App.MainPageLoader.GetString("Print_BlackAndWhite");
  131. T_PrintSettings = App.MainPageLoader.GetString("Print_PrintSettings");
  132. T_Orientation = App.MainPageLoader.GetString("Print_Orientation");
  133. T_PrintContent = App.MainPageLoader.GetString("Print_PrintContent");
  134. T_ReversePages = App.MainPageLoader.GetString("Print_ReversePages");
  135. }
  136. #endregion
  137. public IRegionManager printRegion;
  138. public IDialogService printDialogs;
  139. public IEventAggregator printEvent;
  140. private CPDFViewer PDFViewer;
  141. public PrintSettingsInfo PrintSettingsInfo = new PrintSettingsInfo();
  142. List<int> PageList = new List<int>();
  143. #region 常用字符串
  144. public string Title => "";
  145. public string HomePagePrinterDocumentName = "HomePagePrinterDocumentContent";
  146. public string HomePagePrinterModSizeName = "HomePagePrinterModSizeContent";
  147. public string HomePagePrinterModPosterName = "HomePagePrinterModPosterContent";
  148. public string HomePagePrinterModMultipleName = "HomePagePrinterModMultipleContent";
  149. public string HomePagePrinterModBookletName = "HomePagePrinterModBookletContent";
  150. #endregion
  151. #region 字典
  152. public Dictionary<string, string> GetPrintModNameFromRadioButton = new Dictionary<string, string>();
  153. #endregion
  154. #region 打印系统配置
  155. private readonly PrintServer localDefaultPrintServer = new PrintServer();
  156. private PrintQueue printQueue;
  157. #endregion
  158. #region 打印参数设置
  159. /// <summary>
  160. /// (文档本身的)打印页集合
  161. /// </summary>
  162. private List<int> DocumentTargetPages = new List<int>();
  163. #endregion
  164. private int _printOrientationIndex = 0;
  165. public int PrintOrientationIndex
  166. {
  167. get => _printOrientationIndex;
  168. set => SetProperty(ref _printOrientationIndex, value);
  169. }
  170. private int _maxPageRange = 0;
  171. public int MaxPageRange
  172. {
  173. get => _maxPageRange;
  174. set => SetProperty(ref _maxPageRange, value);
  175. }
  176. private int _pageRangeSelectIndex = 0;
  177. public int PageRangeSelectIndex
  178. {
  179. get => _pageRangeSelectIndex;
  180. set => SetProperty(ref _pageRangeSelectIndex, value);
  181. }
  182. #region 相关region
  183. private string _homePagePrinterDocumentRegionName;
  184. public string HomePagePrinterDocumentRegionName
  185. {
  186. get { return _homePagePrinterDocumentRegionName; }
  187. set { _homePagePrinterDocumentRegionName = value; }
  188. }
  189. private string _homePagePrinterModRegionName;
  190. public string HomePagePrinterModRegionName
  191. {
  192. get { return _homePagePrinterModRegionName; }
  193. set { _homePagePrinterModRegionName = value; }
  194. }
  195. #endregion
  196. #region 打印参数设置
  197. /// <summary>
  198. /// 打印机名称
  199. /// </summary>
  200. public string PrinterName;
  201. private int _maxCopiesNumber;
  202. /// <summary>
  203. /// 最大打印份数
  204. /// </summary>
  205. public int MaxCopiesNumber
  206. {
  207. get => _maxCopiesNumber;
  208. set => SetProperty(ref _maxCopiesNumber, value);
  209. }
  210. private string _copiesNumber = "1";
  211. public string CopiesNumber
  212. {
  213. get => _copiesNumber;
  214. set
  215. {
  216. SetProperty(ref _copiesNumber, value);
  217. PrintSettingsInfo.Copies = int.Parse(_copiesNumber);
  218. PrintSettingsInfo.needRerendering = false;
  219. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  220. }
  221. }
  222. private Visibility _printPageBorderVisibility = Visibility.Collapsed;
  223. public Visibility PrintPageBorderVisibility
  224. {
  225. get => _printPageBorderVisibility;
  226. set => SetProperty(ref _printPageBorderVisibility, value);
  227. }
  228. /// <summary>
  229. /// 打印机支持的颜色
  230. /// </summary>
  231. public List<OutputColor> OutputColorList = new List<OutputColor>();
  232. #endregion
  233. #region 组件
  234. private List<string> _printerNameList;
  235. /// <summary>
  236. /// 打印机名
  237. /// </summary>
  238. public List<string> PrinterNameList
  239. {
  240. get { return _printerNameList; }
  241. set { _printerNameList = value; }
  242. }
  243. private List<string> _printContentList;
  244. /// <summary>
  245. /// 打印内容
  246. /// </summary>
  247. public List<string> PrintContentList
  248. {
  249. get { return _printContentList; }
  250. set { _printContentList = value; }
  251. }
  252. private int _printContentIndex = 1;
  253. public int PrintContentIndex
  254. {
  255. get => _printContentIndex;
  256. set => SetProperty(ref _printContentIndex, value);
  257. }
  258. private List<string> _printerOrientationList;
  259. /// <summary>
  260. /// 打印列表
  261. /// </summary>
  262. public List<string> PrintOrientationList
  263. {
  264. get { return _printerOrientationList; }
  265. set
  266. {
  267. _printerOrientationList = value;
  268. }
  269. }
  270. private int _printerSelectedIndex;
  271. public int PrinterSelectedIndex
  272. {
  273. get => _printerSelectedIndex;
  274. set => SetProperty(ref _printerSelectedIndex, value);
  275. }
  276. public PageSetupDialog pageSetupDialog = new PageSetupDialog();
  277. #endregion
  278. #region 打印态
  279. private bool _isBothSides;
  280. public bool IsBothSides
  281. {
  282. get => _isBothSides;
  283. set => _isBothSides = value;
  284. }
  285. public bool FinishedFrontSideFlag = false;
  286. public int printCurrentPageIndex;
  287. public string PageListString = null;
  288. public bool isCurrentPage;
  289. /// <summary>
  290. /// 双面打印阶段:正面或背面
  291. /// </summary>
  292. public EnumBothSidesStage BothSidesStage = EnumBothSidesStage.StatusNone;
  293. #endregion
  294. #region 窗口相关参数
  295. private EnumPrintMod currentHomePagePrinterMod;
  296. private string _currentHomePagePrinterModName;
  297. public string CurrentHomePagePrinterModName
  298. {
  299. get => _currentHomePagePrinterModName;
  300. set
  301. {
  302. _currentHomePagePrinterModName = value;
  303. if (value == "HomePagePrinterModSizeContent")
  304. {
  305. currentHomePagePrinterMod = EnumPrintMod.StatusSize;
  306. }
  307. else if (value == "HomePagePrinterModPosterContent")
  308. {
  309. currentHomePagePrinterMod = EnumPrintMod.StatusPoster;
  310. }
  311. else if (value == "HomePagePrinterModMultipleContent")
  312. {
  313. currentHomePagePrinterMod = EnumPrintMod.StatusMultiple;
  314. }
  315. else if (value == "HomePagePrinterModBookletContent")
  316. {
  317. currentHomePagePrinterMod = EnumPrintMod.StatusBooklet;
  318. }
  319. }
  320. }
  321. private string _customRangeString;
  322. public string CustomRangeString
  323. {
  324. get => _customRangeString;
  325. set
  326. {
  327. SetProperty(ref _customRangeString, value);
  328. }
  329. }
  330. public bool IsFirstOpen = true;
  331. string Unicode = null;
  332. private bool _isHitVisible = true;
  333. public bool IsHitVisible
  334. {
  335. get => _isHitVisible;
  336. set
  337. {
  338. SetProperty(ref _isHitVisible, value);
  339. }
  340. }
  341. #endregion
  342. #region 委托
  343. public DelegateCommand CancelCommand { get; set; }
  344. public DelegateCommand ConfirmPrintCommand { get; set; }
  345. public DelegateCommand SetPaperCommand { get; set; }
  346. public DelegateCommand<object> SelectPrinterCommand { get; set; }
  347. public DelegateCommand<object> ChangePrintModCommand { get; set; }
  348. public DelegateCommand<object> SetGrayscaleCommand { get; set; }
  349. public DelegateCommand<object> SetDuplexCommand { get; set; }
  350. public DelegateCommand<object> SetPageRangeSelectionIndexCommand { get; set; }
  351. public DelegateCommand<object> SetCustomPageRangeCommand { get; set; }
  352. public DelegateCommand<object> SetPrintContentCommand { get; set; }
  353. public DelegateCommand<object> SetReversePageCommand { get; set; }
  354. public DelegateCommand<object> SetPrintBorderCommand { get; set; }
  355. public DelegateCommand<object> SetPrintOritationCommand { get; set; }
  356. public DelegateCommand<object> PageTextChangedCommand { get; set; }
  357. #endregion
  358. HomePagePrinterDialogViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  359. {
  360. InitString();
  361. this.printRegion = regionManager;
  362. this.printDialogs = dialogService;
  363. this.printEvent = eventAggregator;
  364. HomePagePrinterDocumentRegionName = Guid.NewGuid().ToString();
  365. HomePagePrinterModRegionName = Guid.NewGuid().ToString();
  366. CancelCommand = new DelegateCommand(Cancel);
  367. ConfirmPrintCommand = new DelegateCommand(ConfirmPrint);
  368. ChangePrintModCommand = new DelegateCommand<object>(ChangePrintMod);
  369. SetPaperCommand = new DelegateCommand(SetPaper);
  370. SelectPrinterCommand = new DelegateCommand<object>(SelectPrinter);
  371. SetGrayscaleCommand = new DelegateCommand<object>(SetGrayscale);
  372. SetDuplexCommand = new DelegateCommand<object>(SetDuplex);
  373. SetPageRangeSelectionIndexCommand = new DelegateCommand<object>(SetPageRangeSelectionIndex);
  374. SetCustomPageRangeCommand = new DelegateCommand<object>(SetCustomPageRange);
  375. PageTextChangedCommand = new DelegateCommand<object>(PageTextChanged);
  376. SetPrintContentCommand = new DelegateCommand<object>(SetPrintContent);
  377. SetReversePageCommand = new DelegateCommand<object>(SetReversePage);
  378. SetPrintBorderCommand = new DelegateCommand<object>(SetPrintBorder);
  379. SetPrintOritationCommand = new DelegateCommand<object>(SetPrintOritation);
  380. Unicode = Guid.NewGuid().ToString();
  381. InitComponent();
  382. InitDictionary();
  383. InitParams();
  384. pageSetupDialog = new PageSetupDialog();
  385. PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
  386. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
  387. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = false;
  388. pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
  389. PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
  390. if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
  391. {
  392. PrintOrientationIndex = 0;
  393. }
  394. else
  395. {
  396. PrintOrientationIndex = 1;
  397. }
  398. printEvent.GetEvent<SendPrintSettingsModInfoEvent>().Subscribe(RecvPrintSettingsModInfo, e => e.Unicode == Unicode);
  399. printEvent.GetEvent<SendDuplexPrintModEvent>().Subscribe(RecvDuplexPrintMod, e => e.Unicode == Unicode);
  400. printEvent.GetEvent<SendFinishedFrontSideEvent>().Subscribe(RecvFinishedFrontSide, e => e.Unicode == Unicode);
  401. PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
  402. if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
  403. {
  404. PrintOrientationIndex = 0;
  405. }
  406. else
  407. {
  408. PrintOrientationIndex = 1;
  409. }
  410. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  411. }
  412. private void InitComponent()
  413. {
  414. InitPrinterNameList();
  415. InitPrintContentList();
  416. InitPrintOrientationList();
  417. }
  418. private void InitDictionary()
  419. {
  420. InitGetPrintModNameFromRadioButton();
  421. }
  422. private void InitParams()
  423. {
  424. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  425. List<PageMediaSize> PageMediaSizeList = new List<PageMediaSize>();
  426. }
  427. private void InitPrinterNameList()
  428. {
  429. PrinterNameList = new List<string>();
  430. foreach (string printerListItem in PrinterSettings.InstalledPrinters)
  431. {
  432. PrinterNameList.Add(printerListItem);
  433. }
  434. if (PrinterNameList.Contains("Microsoft Print to PDF"))
  435. {
  436. PrinterSelectedIndex = PrinterNameList.IndexOf("Microsoft Print to PDF");
  437. }
  438. else
  439. {
  440. PrinterSelectedIndex = 0;
  441. }
  442. PrinterName = PrinterNameList[PrinterSelectedIndex];
  443. }
  444. private void InitPrintContentList()
  445. {
  446. PrintContentList = new List<string>();
  447. PrintContentList.Add("文档");
  448. PrintContentList.Add("文档和标记");
  449. PrintContentList.Add("文档和图章");
  450. PrintContentList.Add("文档和表单");
  451. }
  452. private void InitPrintOrientationList()
  453. {
  454. PrintOrientationList = new List<string>();
  455. PrintOrientationList.Add("纵向");
  456. PrintOrientationList.Add("横向");
  457. }
  458. public void InitGetPrintModNameFromRadioButton()
  459. {
  460. GetPrintModNameFromRadioButton.Clear();
  461. GetPrintModNameFromRadioButton.Add("ModSizeRdo", HomePagePrinterModSizeName);
  462. GetPrintModNameFromRadioButton.Add("ModPosterRdo", HomePagePrinterModPosterName);
  463. GetPrintModNameFromRadioButton.Add("ModMultipleRdo", HomePagePrinterModMultipleName);
  464. GetPrintModNameFromRadioButton.Add("ModBookletRdo", HomePagePrinterModBookletName);
  465. }
  466. /// <summary>
  467. /// 选择打印机
  468. /// </summary>
  469. /// <param name="e"></param>
  470. public void SelectPrinter(object e)
  471. {
  472. var comboBox = e as ComboBox;
  473. PrinterName = comboBox.SelectedItem.ToString();
  474. }
  475. /// <summary>
  476. /// 打开纸张设置窗口
  477. /// </summary>
  478. public void SetPaper()
  479. {
  480. Margins defaultMargin = new Margins();
  481. PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
  482. pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
  483. defaultMargin = PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins;
  484. pageSetupDialog.Document.DefaultPageSettings.Margins = new Margins((int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Left * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Right * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Top * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Bottom * 2.54));
  485. if (pageSetupDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  486. {
  487. PrintSettingsInfo.IsPaperSizeChanged = true;
  488. PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
  489. if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
  490. {
  491. PrintOrientationIndex = 0;
  492. }
  493. else
  494. {
  495. PrintOrientationIndex = 1;
  496. }
  497. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  498. PrintSettingsInfo.IsPaperSizeChanged = false;
  499. }
  500. else
  501. {
  502. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins = defaultMargin;
  503. }
  504. }
  505. public void ChangePrintMod(object e)
  506. {
  507. var rdo = e as System.Windows.Controls.RadioButton;
  508. CurrentHomePagePrinterModName = GetPrintModNameFromRadioButton[rdo.Name];
  509. if (CurrentHomePagePrinterModName == "HomePagePrinterModMultipleContent" || CurrentHomePagePrinterModName == "HomePagePrinterModBookletContent")
  510. {
  511. PrintPageBorderVisibility = Visibility.Visible;
  512. }
  513. else
  514. {
  515. PrintPageBorderVisibility = Visibility.Collapsed;
  516. }
  517. NavigationParameters param = new NavigationParameters();
  518. param.Add("document", PDFViewer.Document);
  519. param.Add("Unicode", Unicode);
  520. printRegion.RequestNavigate(HomePagePrinterModRegionName, CurrentHomePagePrinterModName, param);
  521. }
  522. /// <summary>
  523. /// 加载对应打印设置
  524. /// </summary>
  525. public void LoadPrinterSettings()
  526. {
  527. if (printQueue.GetPrintCapabilities().MaxCopyCount.HasValue)
  528. {
  529. MaxCopiesNumber = printQueue.GetPrintCapabilities().MaxCopyCount.Value;
  530. }
  531. else
  532. {
  533. MaxCopiesNumber = 1;
  534. }
  535. OutputColorList.Clear();
  536. foreach (OutputColor color in printQueue.GetPrintCapabilities().OutputColorCapability)
  537. {
  538. OutputColorList.Add(color);
  539. }
  540. }
  541. #region 来自UI的设置
  542. /// <summary>
  543. /// 设置灰度
  544. /// 改变打印机设置
  545. /// 改变渲染
  546. /// </summary>
  547. public void SetGrayscale(object e)
  548. {
  549. var chk = e as CheckBox;
  550. if ((bool)chk.IsChecked)
  551. {
  552. PrintSettingsInfo.IsGrayscale = true;
  553. }
  554. else if (!(bool)chk.IsChecked)
  555. {
  556. PrintSettingsInfo.IsGrayscale = false;
  557. }
  558. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  559. }
  560. /// <summary>
  561. /// 设置双面打印
  562. /// 改变打印流程
  563. /// 不改变打印相关参数
  564. /// </summary>
  565. /// <param name="e"></param>
  566. public void SetDuplex(object e)
  567. {
  568. var chk = e as CheckBox;
  569. if ((bool)chk.IsChecked)
  570. {
  571. PrintSettingsInfo.IsDuplex = true;
  572. }
  573. else if (!(bool)chk.IsChecked)
  574. {
  575. PrintSettingsInfo.IsDuplex = false;
  576. }
  577. }
  578. public void SetPageRangeSelectionIndex(object e)
  579. {
  580. var cmb = e as WritableComboBox;
  581. PrintSettingsInfo.PageRangeList.Clear();
  582. if ((int.Parse(cmb.SelectedIndex) < cmb.Items.Count - 1))
  583. {
  584. if (!isCurrentPage)
  585. {
  586. PrintSettingsInfo.EnumPageRange = int.Parse(cmb.SelectedIndex);
  587. if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusAllRange)
  588. {
  589. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  590. {
  591. PrintSettingsInfo.PageRangeList.Add(temp);
  592. }
  593. }
  594. else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusOddRange)
  595. {
  596. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
  597. {
  598. PrintSettingsInfo.PageRangeList.Add(temp);
  599. }
  600. }
  601. else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusEvenRange)
  602. {
  603. if (PDFViewer.Document.PageCount <= 1)
  604. {
  605. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  606. {
  607. PrintSettingsInfo.PageRangeList.Add(temp);
  608. }
  609. PageRangeSelectIndex = 0;
  610. }
  611. else
  612. {
  613. for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
  614. {
  615. PrintSettingsInfo.PageRangeList.Add(temp);
  616. }
  617. }
  618. }
  619. }
  620. else
  621. {
  622. PrintSettingsInfo.EnumPageRange = int.Parse(cmb.SelectedIndex);
  623. if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusAllRange)
  624. {
  625. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  626. {
  627. PrintSettingsInfo.PageRangeList.Add(temp);
  628. }
  629. }
  630. else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCurrentPage)
  631. {
  632. PrintSettingsInfo.PageRangeList.Add(printCurrentPageIndex);
  633. }
  634. else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusOddRange)
  635. {
  636. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp += 2)
  637. {
  638. PrintSettingsInfo.PageRangeList.Add(temp);
  639. }
  640. }
  641. else if (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusEvenRange)
  642. {
  643. if (PDFViewer.Document.PageCount <= 1)
  644. {
  645. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  646. {
  647. PrintSettingsInfo.PageRangeList.Add(temp);
  648. }
  649. PageRangeSelectIndex = 0;
  650. }
  651. else
  652. {
  653. for (int temp = 1; temp < PDFViewer.Document.PageCount; temp += 2)
  654. {
  655. PrintSettingsInfo.PageRangeList.Add(temp);
  656. }
  657. }
  658. }
  659. }
  660. if (PrintSettingsInfo.needReversePage)
  661. {
  662. PrintSettingsInfo.PageRangeList.Reverse();
  663. }
  664. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  665. }
  666. else
  667. {
  668. PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange;
  669. if (string.IsNullOrEmpty(PageListString))
  670. {
  671. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  672. {
  673. PrintSettingsInfo.PageRangeList.Add(temp);
  674. }
  675. if (PrintSettingsInfo.needReversePage)
  676. {
  677. PrintSettingsInfo.PageRangeList.Reverse();
  678. }
  679. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  680. return;
  681. }
  682. if (!isCurrentPage)
  683. {
  684. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  685. {
  686. PrintSettingsInfo.PageRangeList.Add(temp);
  687. }
  688. PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange;
  689. }
  690. else
  691. {
  692. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  693. {
  694. PrintSettingsInfo.PageRangeList.Add(temp);
  695. }
  696. }
  697. if (PrintSettingsInfo.needReversePage)
  698. {
  699. PrintSettingsInfo.PageRangeList.Reverse();
  700. }
  701. }
  702. }
  703. public void SetCustomPageRange(object e)
  704. {
  705. if ((PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange && !isCurrentPage) || (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange && isCurrentPage))
  706. {
  707. var cmb = e as WritableComboBox;
  708. if (cmb == null)
  709. {
  710. return;
  711. }
  712. if (!CommonHelper.GetPagesInRange(ref DocumentTargetPages, cmb.Text, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  713. { //TODO
  714. AlertsMessage alertsMessage = new AlertsMessage();
  715. alertsMessage.ShowDialog("错误","输入不对","","确认");
  716. return;
  717. }
  718. PrintSettingsInfo.PageRangeList = DocumentTargetPages;
  719. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  720. }
  721. }
  722. public void PageTextChanged(object e)
  723. {
  724. if ((PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange && !isCurrentPage) || (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange && isCurrentPage))
  725. {
  726. var cmb = e as WritableComboBox;
  727. if (cmb == null)
  728. {
  729. return;
  730. }
  731. if (!CommonHelper.GetPagesInRange(ref DocumentTargetPages, cmb.Text, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  732. { //TODO
  733. PrintSettingsInfo.PageRangeList.Clear();
  734. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  735. {
  736. PrintSettingsInfo.PageRangeList.Add(temp);
  737. }
  738. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  739. if (PrintSettingsInfo.needReversePage)
  740. {
  741. PrintSettingsInfo.PageRangeList.Reverse();
  742. }
  743. return;
  744. }
  745. PrintSettingsInfo.PageRangeList = DocumentTargetPages;
  746. if (PrintSettingsInfo.needReversePage)
  747. {
  748. PrintSettingsInfo.PageRangeList.Reverse();
  749. }
  750. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  751. }
  752. }
  753. public void SetPrintOritation(object e)
  754. {
  755. var cmb = e as ComboBox;
  756. if ((EnumPrintOrientation)cmb.SelectedIndex == EnumPrintOrientation.StatusPortrait)
  757. {
  758. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = false;
  759. }
  760. else
  761. {
  762. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
  763. }
  764. PrintSettingsInfo.EnumPrintOrientation = (EnumPrintOrientation)cmb.SelectedIndex;
  765. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  766. }
  767. public void SetPrintContent(object e)
  768. {
  769. var cmb = e as ComboBox;
  770. if (cmb.SelectedIndex == (int)EnumPrintContent.StatusOnlyDocument)
  771. {
  772. PrintSettingsInfo.IsPrintWithAnnot = false;
  773. PrintSettingsInfo.IsPrintWithForm = false;
  774. }
  775. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndMarkUps)
  776. {
  777. PrintSettingsInfo.IsPrintWithAnnot = true;
  778. PrintSettingsInfo.IsPrintWithForm = true;
  779. }
  780. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndStamps)
  781. {
  782. PrintSettingsInfo.IsPrintWithAnnot = true;
  783. PrintSettingsInfo.IsPrintWithForm = false;
  784. }
  785. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndForm)
  786. {
  787. PrintSettingsInfo.IsPrintWithAnnot = false;
  788. PrintSettingsInfo.IsPrintWithForm = true;
  789. }
  790. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  791. }
  792. public void SetReversePage(object e)
  793. {
  794. var reversePageChk = e as CheckBox;
  795. if ((bool)reversePageChk.IsChecked)
  796. {
  797. PrintSettingsInfo.needReversePage = true;
  798. }
  799. else
  800. {
  801. PrintSettingsInfo.needReversePage = false;
  802. }
  803. PrintSettingsInfo.PageRangeList.Reverse();
  804. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  805. }
  806. public void SetPrintBorder(object e)
  807. {
  808. var chk = e as CheckBox;
  809. if ((bool)chk.IsChecked)
  810. {
  811. PrintSettingsInfo.IsPrintPageBorde = true;
  812. }
  813. else
  814. {
  815. PrintSettingsInfo.IsPrintPageBorde = false;
  816. }
  817. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  818. }
  819. public void RecvPrintSettingsModInfo(PrintModInfoWithUnicode printModInfoWithUnicode)
  820. {
  821. if (printModInfoWithUnicode.printModInfo.EnumPrintMod == currentHomePagePrinterMod)
  822. {
  823. PrintSettingsInfo.PrintModInfo = printModInfoWithUnicode.printModInfo;
  824. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  825. }
  826. }
  827. public void RecvDuplexPrintMod(EnumDuplexPrintModWithUnicode enumDuplexPrintModWithUnicode)
  828. {
  829. PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod = enumDuplexPrintModWithUnicode.enumDuplexPrintMod;
  830. }
  831. public void RecvFinishedFrontSide(FinishedFrontSide finishedFrontSide)
  832. {
  833. FinishedFrontSideFlag = true;
  834. }
  835. #endregion
  836. public void Cancel()
  837. {
  838. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  839. }
  840. public void NavigateDocumentRegion()
  841. {
  842. NavigationParameters param = new NavigationParameters();
  843. param.Add(ParameterNames.PDFViewer, PDFViewer);
  844. param.Add(ParameterNames.PrintSettingsInfo, PrintSettingsInfo);
  845. param.Add("Unicode", Unicode);
  846. printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
  847. PageSetupDialog pageSetupDialog = new PageSetupDialog();
  848. PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
  849. pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
  850. PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
  851. if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
  852. {
  853. PrintOrientationIndex = 0;
  854. }
  855. else
  856. {
  857. PrintOrientationIndex = 1;
  858. }
  859. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  860. }
  861. public void NavigateModRegion()
  862. {
  863. NavigationParameters param = new NavigationParameters();
  864. param.Add(ParameterNames.PDFViewer, PDFViewer);
  865. param.Add("Unicode", Unicode);
  866. printRegion.RequestNavigate(HomePagePrinterModRegionName, HomePagePrinterModSizeName, param);
  867. }
  868. public bool IsBookletSinglePage(PrintModInfo printModInfo)
  869. {
  870. if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
  871. {
  872. var bookletInfo = (BookletInfo)printModInfo;
  873. if (!(bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides))
  874. {
  875. return true;
  876. }
  877. }
  878. return false;
  879. }
  880. public bool IsBookletBothPage(PrintModInfo printModInfo)
  881. {
  882. if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
  883. {
  884. var bookletInfo = (BookletInfo)printModInfo;
  885. if (bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides)
  886. {
  887. return true;
  888. }
  889. }
  890. return false;
  891. }
  892. /// <summary>
  893. /// 确认打印,单面,双面或手动双面
  894. /// 大小模式支持单面,双面
  895. /// 海报模式只支持单面
  896. /// 多页模式支持单面,双面
  897. /// 小册子模式双面打印:双面
  898. /// 仅正面/背面:单面
  899. ///
  900. /// 单面打印:正常传参
  901. ///
  902. /// 双面打印:
  903. /// 长边翻页,短边翻页
  904. ///
  905. /// 自动双面打印
  906. /// 传值给打印机就行
  907. ///
  908. /// 手动双面打印
  909. /// 长边翻页 先打印奇数页,进入二阶段,正向打印偶数页
  910. /// 短边翻页 先打印奇数页,进入二阶段,反向打印偶数页
  911. ///
  912. /// 异常退出是否要挂起打印机线程?
  913. ///
  914. /// </summary>
  915. public void ConfirmPrint()
  916. {
  917. IsHitVisible = false;
  918. List<int> PageIndexLists = new List<int>();
  919. if (PageRangeSelectIndex == 4)
  920. {
  921. if (!CommonHelper.GetPagesInRange(ref PageIndexLists, CustomRangeString, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  922. { //TODO
  923. AlertsMessage alertsMessage = new AlertsMessage();
  924. alertsMessage.ShowDialog("页面范围输入错误", "", "确定");
  925. IsHitVisible = true;
  926. return;
  927. }
  928. }
  929. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  930. LoadPrinterSettings();
  931. Collection<Duplexing> list = new Collection<Duplexing>();
  932. if (printQueue.GetPrintCapabilities().DuplexingCapability.Count > 0)
  933. {
  934. list.Clear();
  935. for (int temp = 0; temp < printQueue.GetPrintCapabilities().DuplexingCapability.Count; temp++)
  936. {
  937. list.Add(printQueue.GetPrintCapabilities().DuplexingCapability[temp]);
  938. }
  939. }
  940. ///单面打印的情况:直接执行
  941. if (PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod == EnumDuplexPrintMod.StatusNone && !IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
  942. {
  943. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  944. }
  945. else if (IsBookletSinglePage(PrintSettingsInfo.PrintModInfo))
  946. {
  947. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  948. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  949. }
  950. ///双面打印的情况
  951. else if ((int)PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod > 0 || IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
  952. {
  953. ///支持自动双面
  954. if (list.Count > 0)
  955. {
  956. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  957. }
  958. ///手动翻面
  959. ///手动翻面需要注意只有一页时和单面打印一致
  960. ///那奇数页呢?
  961. else
  962. {
  963. AlertsMessage alertsMessage = new AlertsMessage();
  964. if ((PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusSize && PrintSettingsInfo.PageRangeList.Count == 1) || (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet && PrintSettingsInfo.PageRangeList.Count == 1))
  965. {
  966. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  967. }
  968. else if (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusMultiple)
  969. {
  970. var multipleInfo = (MultipleInfo)PrintSettingsInfo.PrintModInfo;
  971. if (PrintSettingsInfo.PageRangeList.Count / (multipleInfo.HorizontalPageNumber * multipleInfo.VerticalPageNumber) == 0)
  972. {
  973. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  974. }
  975. else
  976. {
  977. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
  978. if (FinishedFrontSideFlag)
  979. {
  980. alertsMessage.ShowDialog("Message", "Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "Cancel", "OK");
  981. if (alertsMessage.result == ContentResult.Ok)
  982. {
  983. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
  984. FinishedFrontSideFlag = false;
  985. }
  986. }
  987. }
  988. }
  989. else
  990. {
  991. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
  992. if (FinishedFrontSideFlag)
  993. {
  994. alertsMessage.ShowDialog("Message", "Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "Cancel", "OK");
  995. if (alertsMessage.result == ContentResult.Ok)
  996. {
  997. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
  998. FinishedFrontSideFlag = false;
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. try
  1005. {
  1006. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
  1007. }
  1008. catch { }
  1009. }
  1010. public event Action<IDialogResult> RequestClose;
  1011. public bool CanCloseDialog()
  1012. {
  1013. return true;
  1014. }
  1015. public void OnDialogClosed()
  1016. {
  1017. this.printQueue.Dispose();
  1018. }
  1019. public void OnDialogOpened(IDialogParameters parameters)
  1020. {
  1021. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1022. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsPrinting, printDialogs);
  1023. if (result.IsDiscryptied)
  1024. {
  1025. if (result.Password != null)
  1026. {
  1027. string filePath = PDFViewer.Document.FilePath;
  1028. if (PDFViewer.Document.IsLocked)
  1029. {
  1030. PDFViewer.Document.UnlockWithPassword(result.Password);
  1031. }
  1032. else
  1033. {
  1034. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1035. }
  1036. }
  1037. string appUnicode = string.Empty;
  1038. if (parameters.TryGetValue<string>(ParameterNames.Unicode, out appUnicode))
  1039. {
  1040. this.printEvent.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = appUnicode });
  1041. }
  1042. }
  1043. if (!result.IsDiscryptied)
  1044. {
  1045. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1046. {
  1047. this.RequestClose(new Prism.Services.Dialogs.DialogResult());
  1048. }));
  1049. }
  1050. int currentPage = -1;
  1051. if (PDFViewer != null && PDFViewer.Document != null && result.IsDiscryptied)
  1052. {
  1053. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  1054. {
  1055. PrintSettingsInfo.PageRangeList.Add(temp);
  1056. }
  1057. if (parameters.TryGetValue<int>(ParameterNames.PrintCurrentPage, out printCurrentPageIndex))
  1058. {
  1059. isCurrentPage = true;
  1060. }
  1061. else
  1062. {
  1063. isCurrentPage = false;
  1064. }
  1065. if (parameters.TryGetValue<List<int>>(ParameterNames.PageList, out PageList))
  1066. {
  1067. PageListString = CommonHelper.GetPageParmFromList(PageList);
  1068. PrintSettingsInfo.PageRangeList = PageList;
  1069. for (int temp = 0; temp < PrintSettingsInfo.PageRangeList.Count; temp++)
  1070. {
  1071. PrintSettingsInfo.PageRangeList[temp]--;
  1072. }
  1073. if (!string.IsNullOrEmpty(PageListString))
  1074. {
  1075. if (PageList.Count == 1)
  1076. {
  1077. //不注释的话 从页面编辑进来会有显示当前页然后又跳转到第一页的情况
  1078. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1079. //{
  1080. PageRangeSelectIndex = 1;
  1081. //}));
  1082. }
  1083. else
  1084. {
  1085. PrintSettingsInfo.PageRangeList = PageList;
  1086. CustomRangeString = PageListString;
  1087. PageRangeSelectIndex = 4;
  1088. }
  1089. }
  1090. }
  1091. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  1092. if ((pageSize.Height / pageSize.Width > 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width < 1.0)
  1093. || (pageSize.Height / pageSize.Width < 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width > 1.0))
  1094. {
  1095. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
  1096. PrintOrientationIndex = 0;
  1097. PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
  1098. }
  1099. MaxPageRange = PDFViewer.Document.PageCount;
  1100. NavigationParameters param = new NavigationParameters();
  1101. NavigateDocumentRegion();
  1102. NavigateModRegion();
  1103. }
  1104. }
  1105. }
  1106. }