HomePagePrinterDialogViewModel.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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(App.MainPageLoader.GetString("PrintContents_Document"));
  448. PrintContentList.Add(App.MainPageLoader.GetString("PrintContents_DocumentAndMarkups"));
  449. PrintContentList.Add(App.MainPageLoader.GetString("PrintContents_DocumentAndFComment"));
  450. PrintContentList.Add(App.MainPageLoader.GetString("PrintContents_DocumentAndForm"));
  451. }
  452. private void InitPrintOrientationList()
  453. {
  454. PrintOrientationList = new List<string>();
  455. PrintOrientationList.Add(App.MainPageLoader.GetString("Print_Portrait"));
  456. PrintOrientationList.Add(App.MainPageLoader.GetString("Print_Landscape"));
  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("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  716. return;
  717. }
  718. PrintSettingsInfo.PageRangeList = DocumentTargetPages;
  719. //自定义页面范围链表增加反转判断
  720. if (PrintSettingsInfo.needReversePage)
  721. {
  722. PrintSettingsInfo.PageRangeList.Reverse();
  723. }
  724. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  725. }
  726. }
  727. public void PageTextChanged(object e)
  728. {
  729. if ((PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange && !isCurrentPage) || (PrintSettingsInfo.EnumPageRange == (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange && isCurrentPage))
  730. {
  731. var cmb = e as WritableComboBox;
  732. if (cmb == null)
  733. {
  734. return;
  735. }
  736. if (!CommonHelper.GetPagesInRange(ref DocumentTargetPages, cmb.Text, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  737. { //TODO
  738. PrintSettingsInfo.PageRangeList.Clear();
  739. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  740. {
  741. PrintSettingsInfo.PageRangeList.Add(temp);
  742. }
  743. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  744. if (PrintSettingsInfo.needReversePage)
  745. {
  746. PrintSettingsInfo.PageRangeList.Reverse();
  747. }
  748. return;
  749. }
  750. PrintSettingsInfo.PageRangeList = DocumentTargetPages;
  751. if (PrintSettingsInfo.needReversePage)
  752. {
  753. PrintSettingsInfo.PageRangeList.Reverse();
  754. }
  755. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  756. }
  757. }
  758. public void SetPrintOritation(object e)
  759. {
  760. var cmb = e as ComboBox;
  761. if ((EnumPrintOrientation)cmb.SelectedIndex == EnumPrintOrientation.StatusPortrait)
  762. {
  763. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = false;
  764. }
  765. else
  766. {
  767. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
  768. }
  769. PrintSettingsInfo.EnumPrintOrientation = (EnumPrintOrientation)cmb.SelectedIndex;
  770. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  771. }
  772. public void SetPrintContent(object e)
  773. {
  774. var cmb = e as ComboBox;
  775. if (cmb.SelectedIndex == (int)EnumPrintContent.StatusOnlyDocument)
  776. {
  777. PrintSettingsInfo.IsPrintWithAnnot = false;
  778. PrintSettingsInfo.IsPrintWithForm = false;
  779. }
  780. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndMarkUps)
  781. {
  782. PrintSettingsInfo.IsPrintWithAnnot = true;
  783. PrintSettingsInfo.IsPrintWithForm = true;
  784. }
  785. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndStamps)
  786. {
  787. PrintSettingsInfo.IsPrintWithAnnot = true;
  788. PrintSettingsInfo.IsPrintWithForm = false;
  789. }
  790. else if (cmb.SelectedIndex == (int)EnumPrintContent.StatusDocumentAndForm)
  791. {
  792. PrintSettingsInfo.IsPrintWithAnnot = false;
  793. PrintSettingsInfo.IsPrintWithForm = true;
  794. }
  795. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  796. }
  797. public void SetReversePage(object e)
  798. {
  799. var reversePageChk = e as CheckBox;
  800. if ((bool)reversePageChk.IsChecked)
  801. {
  802. PrintSettingsInfo.needReversePage = true;
  803. }
  804. else
  805. {
  806. PrintSettingsInfo.needReversePage = false;
  807. }
  808. PrintSettingsInfo.PageRangeList.Reverse();
  809. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  810. }
  811. public void SetPrintBorder(object e)
  812. {
  813. var chk = e as CheckBox;
  814. if ((bool)chk.IsChecked)
  815. {
  816. PrintSettingsInfo.IsPrintPageBorde = true;
  817. }
  818. else
  819. {
  820. PrintSettingsInfo.IsPrintPageBorde = false;
  821. }
  822. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  823. }
  824. public void RecvPrintSettingsModInfo(PrintModInfoWithUnicode printModInfoWithUnicode)
  825. {
  826. if (printModInfoWithUnicode.printModInfo.EnumPrintMod == currentHomePagePrinterMod)
  827. {
  828. PrintSettingsInfo.PrintModInfo = printModInfoWithUnicode.printModInfo;
  829. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  830. }
  831. }
  832. public void RecvDuplexPrintMod(EnumDuplexPrintModWithUnicode enumDuplexPrintModWithUnicode)
  833. {
  834. PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod = enumDuplexPrintModWithUnicode.enumDuplexPrintMod;
  835. }
  836. public void RecvFinishedFrontSide(FinishedFrontSide finishedFrontSide)
  837. {
  838. FinishedFrontSideFlag = true;
  839. }
  840. #endregion
  841. public void Cancel()
  842. {
  843. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  844. }
  845. public void NavigateDocumentRegion()
  846. {
  847. NavigationParameters param = new NavigationParameters();
  848. param.Add(ParameterNames.PDFViewer, PDFViewer);
  849. param.Add(ParameterNames.PrintSettingsInfo, PrintSettingsInfo);
  850. param.Add("Unicode", Unicode);
  851. printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
  852. PageSetupDialog pageSetupDialog = new PageSetupDialog();
  853. PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
  854. pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
  855. PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
  856. if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
  857. {
  858. PrintOrientationIndex = 0;
  859. }
  860. else
  861. {
  862. PrintOrientationIndex = 1;
  863. }
  864. this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
  865. }
  866. public void NavigateModRegion()
  867. {
  868. NavigationParameters param = new NavigationParameters();
  869. param.Add(ParameterNames.PDFViewer, PDFViewer);
  870. param.Add("Unicode", Unicode);
  871. printRegion.RequestNavigate(HomePagePrinterModRegionName, HomePagePrinterModSizeName, param);
  872. }
  873. public bool IsBookletSinglePage(PrintModInfo printModInfo)
  874. {
  875. if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
  876. {
  877. var bookletInfo = (BookletInfo)printModInfo;
  878. if (!(bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides))
  879. {
  880. return true;
  881. }
  882. }
  883. return false;
  884. }
  885. public bool IsBookletBothPage(PrintModInfo printModInfo)
  886. {
  887. if (printModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet)
  888. {
  889. var bookletInfo = (BookletInfo)printModInfo;
  890. if (bookletInfo.EnumBookletSubset == EnumBookletSubset.StatusBothSides)
  891. {
  892. return true;
  893. }
  894. }
  895. return false;
  896. }
  897. /// <summary>
  898. /// 确认打印,单面,双面或手动双面
  899. /// 大小模式支持单面,双面
  900. /// 海报模式只支持单面
  901. /// 多页模式支持单面,双面
  902. /// 小册子模式双面打印:双面
  903. /// 仅正面/背面:单面
  904. ///
  905. /// 单面打印:正常传参
  906. ///
  907. /// 双面打印:
  908. /// 长边翻页,短边翻页
  909. ///
  910. /// 自动双面打印
  911. /// 传值给打印机就行
  912. ///
  913. /// 手动双面打印
  914. /// 长边翻页 先打印奇数页,进入二阶段,正向打印偶数页
  915. /// 短边翻页 先打印奇数页,进入二阶段,反向打印偶数页
  916. ///
  917. /// 异常退出是否要挂起打印机线程?
  918. ///
  919. /// </summary>
  920. public void ConfirmPrint()
  921. {
  922. IsHitVisible = false;
  923. List<int> PageIndexLists = new List<int>();
  924. if (PageRangeSelectIndex == 4)
  925. {
  926. if (!CommonHelper.GetPagesInRange(ref PageIndexLists, CustomRangeString, PDFViewer.Document.PageCount, new char[] { ',' }, new char[] { '-' }))
  927. { //TODO
  928. AlertsMessage alertsMessage = new AlertsMessage();
  929. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  930. IsHitVisible = true;
  931. return;
  932. }
  933. }
  934. printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
  935. LoadPrinterSettings();
  936. Collection<Duplexing> list = new Collection<Duplexing>();
  937. if (printQueue.GetPrintCapabilities().DuplexingCapability.Count > 0)
  938. {
  939. list.Clear();
  940. for (int temp = 0; temp < printQueue.GetPrintCapabilities().DuplexingCapability.Count; temp++)
  941. {
  942. list.Add(printQueue.GetPrintCapabilities().DuplexingCapability[temp]);
  943. }
  944. }
  945. ///单面打印的情况:直接执行
  946. if (PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod == EnumDuplexPrintMod.StatusNone && !IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
  947. {
  948. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  949. }
  950. else if (IsBookletSinglePage(PrintSettingsInfo.PrintModInfo))
  951. {
  952. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  953. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
  954. }
  955. ///双面打印的情况
  956. else if ((int)PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod > 0 || IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
  957. {
  958. ///支持自动双面
  959. if (list.Count > 0)
  960. {
  961. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  962. }
  963. ///手动翻面
  964. ///手动翻面需要注意只有一页时和单面打印一致
  965. ///那奇数页呢?
  966. else
  967. {
  968. AlertsMessage alertsMessage = new AlertsMessage();
  969. if ((PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusSize && PrintSettingsInfo.PageRangeList.Count == 1) || (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet && PrintSettingsInfo.PageRangeList.Count == 1))
  970. {
  971. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  972. }
  973. else if (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusMultiple)
  974. {
  975. var multipleInfo = (MultipleInfo)PrintSettingsInfo.PrintModInfo;
  976. if (PrintSettingsInfo.PageRangeList.Count / (multipleInfo.HorizontalPageNumber * multipleInfo.VerticalPageNumber) == 0)
  977. {
  978. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
  979. }
  980. else
  981. {
  982. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
  983. if (FinishedFrontSideFlag)
  984. {
  985. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Tip_ReversePage"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  986. if (alertsMessage.result == ContentResult.Ok)
  987. {
  988. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
  989. FinishedFrontSideFlag = false;
  990. }
  991. }
  992. }
  993. }
  994. else
  995. {
  996. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
  997. if (FinishedFrontSideFlag)
  998. {
  999. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Tip_ReversePage"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  1000. if (alertsMessage.result == ContentResult.Ok)
  1001. {
  1002. this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
  1003. FinishedFrontSideFlag = false;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. try
  1010. {
  1011. RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
  1012. }
  1013. catch { }
  1014. }
  1015. public event Action<IDialogResult> RequestClose;
  1016. public bool CanCloseDialog()
  1017. {
  1018. return true;
  1019. }
  1020. public void OnDialogClosed()
  1021. {
  1022. this.printQueue.Dispose();
  1023. }
  1024. public void OnDialogOpened(IDialogParameters parameters)
  1025. {
  1026. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1027. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsPrinting, printDialogs);
  1028. if (result.IsDiscryptied)
  1029. {
  1030. if (result.Password != null)
  1031. {
  1032. string filePath = PDFViewer.Document.FilePath;
  1033. if (PDFViewer.Document.IsLocked)
  1034. {
  1035. PDFViewer.Document.UnlockWithPassword(result.Password);
  1036. }
  1037. else
  1038. {
  1039. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1040. }
  1041. }
  1042. string appUnicode = string.Empty;
  1043. if (parameters.TryGetValue<string>(ParameterNames.Unicode, out appUnicode))
  1044. {
  1045. this.printEvent.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = appUnicode });
  1046. }
  1047. }
  1048. if (!result.IsDiscryptied)
  1049. {
  1050. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1051. {
  1052. this.RequestClose(new Prism.Services.Dialogs.DialogResult());
  1053. }));
  1054. }
  1055. if (PDFViewer != null && PDFViewer.Document != null && result.IsDiscryptied)
  1056. {
  1057. for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
  1058. {
  1059. PrintSettingsInfo.PageRangeList.Add(temp);
  1060. }
  1061. if (parameters.TryGetValue<int>(ParameterNames.PrintCurrentPage, out printCurrentPageIndex))
  1062. {
  1063. isCurrentPage = true;
  1064. }
  1065. else
  1066. {
  1067. isCurrentPage = false;
  1068. }
  1069. if (parameters.TryGetValue<List<int>>(ParameterNames.PageList, out PageList))
  1070. {
  1071. PageListString = CommonHelper.GetPageParmFromList(PageList);
  1072. PrintSettingsInfo.PageRangeList = PageList;
  1073. for (int temp = 0; temp < PrintSettingsInfo.PageRangeList.Count; temp++)
  1074. {
  1075. PrintSettingsInfo.PageRangeList[temp]--;
  1076. }
  1077. if (!string.IsNullOrEmpty(PageListString))
  1078. {
  1079. if (PageList.Count == 1)
  1080. {
  1081. //不注释的话 从页面编辑进来会有显示当前页然后又跳转到第一页的情况
  1082. //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1083. //{
  1084. PageRangeSelectIndex = 1;
  1085. //}));
  1086. }
  1087. else
  1088. {
  1089. PrintSettingsInfo.PageRangeList = PageList;
  1090. PageRangeSelectIndex = 4;
  1091. CustomRangeString = PageListString;
  1092. }
  1093. }
  1094. }
  1095. System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
  1096. if ((pageSize.Height / pageSize.Width > 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width < 1.0)
  1097. || (pageSize.Height / pageSize.Width < 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width > 1.0))
  1098. {
  1099. PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
  1100. PrintOrientationIndex = 0;
  1101. PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
  1102. }
  1103. MaxPageRange = PDFViewer.Document.PageCount;
  1104. NavigationParameters param = new NavigationParameters();
  1105. NavigateDocumentRegion();
  1106. NavigateModRegion();
  1107. }
  1108. }
  1109. }
  1110. }