LinkAnnotPropertyViewModel.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer.PdfViewer;
  5. using PDF_Office.Model;
  6. using PDF_Office.ViewModels.Tools;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Media;
  16. using System.Windows;
  17. using System.Windows.Media.Imaging;
  18. using Prism.Commands;
  19. using PDF_Office.Helper;
  20. using Microsoft.Office.Interop.Word;
  21. using static Dropbox.Api.Files.FileCategory;
  22. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  23. using System.Windows.Controls;
  24. using PDF_Office.CustomControl;
  25. using System.Windows.Markup;
  26. using ComPDFKitViewer;
  27. using System.Runtime.InteropServices;
  28. using System.Text.RegularExpressions;
  29. using System.Net;
  30. using System.Diagnostics;
  31. using static Dropbox.Api.TeamLog.TrustedTeamsRequestState;
  32. using System.Windows.Input;
  33. using Prism.Events;
  34. using Prism.Services.Dialogs;
  35. using PDF_Office.Views.BOTA;
  36. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  37. {
  38. internal class LinkAnnotPropertyViewModel : BindableBase, INavigationAware
  39. {
  40. public AnnotAttribEvent AnnotAttribEvent { get; set; }
  41. private LinkAnnotArgs linkAnnotArgs;
  42. public LinkAnnotArgs LinkAnnotArgs
  43. {
  44. get
  45. {
  46. return linkAnnotArgs;
  47. }
  48. set
  49. {
  50. if (linkAnnotArgs != null)
  51. {
  52. linkAnnotArgs.LinkDrawFinished -= linkAnnotArgs_LinkDrawFinished;
  53. }
  54. linkAnnotArgs = value;
  55. if (linkAnnotArgs != null)
  56. {
  57. linkAnnotArgs.LinkDrawFinished += linkAnnotArgs_LinkDrawFinished;
  58. }
  59. }
  60. }
  61. private AnnotArgsType annotType;
  62. public AnnotArgsType AnnotType
  63. {
  64. get { return annotType; }
  65. set
  66. {
  67. SetProperty(ref annotType, value);
  68. }
  69. }
  70. #region 输入框的验证、设置
  71. private string pageNumTextContent;
  72. public string PageNumTextContent
  73. {
  74. get
  75. {
  76. if (CheckPageNumVaild(out int pageNum, pageNumTextContent))
  77. {
  78. if (LinkAnnotArgs != null)
  79. {
  80. LinkAnnotArgs.DestIndex = pageNum - 1;
  81. LinkAnnotArgs.Content = string.Format($"To Page {LinkAnnotArgs.DestIndex}");
  82. //isTextChanged = (int)AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] != AnnotArgs.DestIndex ? true : false;
  83. SetImagePreview(LinkAnnotArgs.DestIndex);
  84. }
  85. }
  86. else
  87. {
  88. ImagePreviewVisibility = Visibility.Collapsed;
  89. BtnGOorBackVisibility = Visibility.Collapsed;
  90. BtnLocationIsEnabled = false;
  91. }
  92. return pageNumTextContent;
  93. }
  94. set
  95. {
  96. SetProperty(ref pageNumTextContent, value);
  97. }
  98. }
  99. private string pageWebTextContent;
  100. public string PageWebTextContent
  101. {
  102. get
  103. {
  104. if (CheckPageWebVaild(pageWebTextContent))
  105. {
  106. pageWebTextContent = pageWebTextContent.Trim().ToLower();
  107. if (!pageWebTextContent.StartsWith("http://") && !pageWebTextContent.StartsWith("https://"))
  108. {
  109. pageWebTextContent = "http://" + pageWebTextContent;
  110. }
  111. if (LinkAnnotArgs != null)
  112. {
  113. LinkAnnotArgs.URI = pageWebTextContent;
  114. LinkAnnotArgs.Content = LinkAnnotArgs.URI;
  115. //isTextChanged = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] != AnnotArgs.URI ? true : false;
  116. }
  117. }
  118. return pageWebTextContent;
  119. }
  120. set
  121. {
  122. SetProperty(ref pageWebTextContent, value);
  123. }
  124. }
  125. private string pageMailTextContent;
  126. public string PageMailTextContent
  127. {
  128. get
  129. {
  130. if (CheckPageMailVaild(pageMailTextContent))
  131. {
  132. if (!string.IsNullOrEmpty(pageMailTextContent) && LinkAnnotArgs != null)
  133. {
  134. LinkAnnotArgs.URI = "mailto:" + pageMailTextContent.Trim();
  135. LinkAnnotArgs.Content = LinkAnnotArgs.URI;
  136. //isTextChanged = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] != AnnotArgs.URI ? true : false;
  137. }
  138. }
  139. return pageMailTextContent;
  140. }
  141. set
  142. {
  143. SetProperty(ref pageMailTextContent, value);
  144. }
  145. }
  146. /// <summary>
  147. /// 设置预文本内容
  148. /// </summary>
  149. private string pageNumPlaceHoldText = "输入目标页面";
  150. public string PageNumPlaceHoldText
  151. {
  152. get { return pageNumPlaceHoldText; }
  153. set
  154. {
  155. SetProperty(ref pageNumPlaceHoldText, value);
  156. }
  157. }
  158. /// <summary>
  159. /// 是否显示输入框下方提示文案
  160. /// </summary>
  161. private Visibility showPageNumTip = Visibility.Collapsed;
  162. public Visibility ShowPageNumTip
  163. {
  164. get { return showPageNumTip; }
  165. set
  166. {
  167. SetProperty(ref showPageNumTip, value);
  168. }
  169. }
  170. /// <summary>
  171. /// 输入框下方提示文案
  172. /// </summary>
  173. private string pageNumTipText = "Page number error.";
  174. public string PageNumTipText
  175. {
  176. get { return pageNumTipText; }
  177. set
  178. {
  179. SetProperty(ref pageNumTipText, value);
  180. }
  181. }
  182. private bool pageNumTextIsEnabled = false;
  183. public bool PageNumTextIsEnabled
  184. {
  185. get { return pageNumTextIsEnabled; }
  186. set
  187. {
  188. SetProperty(ref pageNumTextIsEnabled, value);
  189. }
  190. }
  191. private bool pageWebTextIsEnabled = false;
  192. public bool PageWebTextIsEnabled
  193. {
  194. get { return pageWebTextIsEnabled; }
  195. set
  196. {
  197. SetProperty(ref pageWebTextIsEnabled, value);
  198. }
  199. }
  200. private string pageWebPlaceHoldText = "输入您要跳转的链接";
  201. public string PageWebPlaceHoldText
  202. {
  203. get { return pageWebPlaceHoldText; }
  204. set
  205. {
  206. SetProperty(ref pageWebPlaceHoldText, value);
  207. }
  208. }
  209. private Visibility showPageWebTip = Visibility.Collapsed;
  210. public Visibility ShowPageWebTip
  211. {
  212. get { return showPageWebTip; }
  213. set
  214. {
  215. SetProperty(ref showPageWebTip, value);
  216. }
  217. }
  218. private string pageWebTipText = "Invalid link.";
  219. public string PageWebTipText
  220. {
  221. get { return pageWebTipText; }
  222. set
  223. {
  224. SetProperty(ref pageWebTipText, value);
  225. }
  226. }
  227. private bool pageMailTextIsEnabled = false;
  228. public bool PageMailTextIsEnabled
  229. {
  230. get { return pageMailTextIsEnabled; }
  231. set
  232. {
  233. SetProperty(ref pageMailTextIsEnabled, value);
  234. }
  235. }
  236. private string pageMailPlaceHoldText = "输入您要跳转邮件地址";
  237. public string PageMailPlaceHoldText
  238. {
  239. get { return pageMailPlaceHoldText; }
  240. set
  241. {
  242. SetProperty(ref pageMailPlaceHoldText, value);
  243. }
  244. }
  245. private Visibility showPageMailTip = Visibility.Collapsed;
  246. public Visibility ShowPageMailTip
  247. {
  248. get { return showPageMailTip; }
  249. set
  250. {
  251. SetProperty(ref showPageMailTip, value);
  252. }
  253. }
  254. private string pageMailTipText = "The email is invalid.Please enter a valid email address.";
  255. public string PageMailTipText
  256. {
  257. get { return pageMailTipText; }
  258. set
  259. {
  260. SetProperty(ref pageMailTipText, value);
  261. }
  262. }
  263. #endregion 输入框的验证、设置
  264. #region 按钮、图片的设置
  265. private bool btnLocationIsEnabled = false;
  266. public bool BtnLocationIsEnabled
  267. {
  268. get { return btnLocationIsEnabled; }
  269. set
  270. {
  271. SetProperty(ref btnLocationIsEnabled, value);
  272. }
  273. }
  274. private bool btnLocationIsChecked = false;
  275. public bool BtnLocationIsChecked
  276. {
  277. get { return btnLocationIsChecked; }
  278. set
  279. {
  280. SetProperty(ref btnLocationIsChecked, value);
  281. }
  282. }
  283. private WriteableBitmap previewImage;
  284. public WriteableBitmap PreviewImage
  285. {
  286. get { return previewImage; }
  287. set
  288. {
  289. SetProperty(ref previewImage, value);
  290. }
  291. }
  292. private int imagePreviewWidth = 196;
  293. public int ImagePreviewWidth
  294. {
  295. get { return imagePreviewWidth; }
  296. set
  297. {
  298. SetProperty(ref imagePreviewWidth, value);
  299. }
  300. }
  301. private int imagePreviewHeight = 256;
  302. public int ImagePreviewHeight
  303. {
  304. get { return imagePreviewHeight; }
  305. set
  306. {
  307. SetProperty(ref imagePreviewHeight, value);
  308. }
  309. }
  310. private Visibility imagePreviewVisibility = Visibility.Collapsed;
  311. public Visibility ImagePreviewVisibility
  312. {
  313. get { return imagePreviewVisibility; }
  314. set
  315. {
  316. SetProperty(ref imagePreviewVisibility, value);
  317. }
  318. }
  319. private Visibility btnGOorBackVisibility = Visibility.Collapsed;
  320. public Visibility BtnGOorBackVisibility
  321. {
  322. get { return btnGOorBackVisibility; }
  323. set
  324. {
  325. SetProperty(ref btnGOorBackVisibility, value);
  326. }
  327. }
  328. private string btnGOorBackContent = "GO";
  329. public string BtnGOorBackContent
  330. {
  331. get { return btnGOorBackContent; }
  332. set
  333. {
  334. SetProperty(ref btnGOorBackContent, value);
  335. }
  336. }
  337. private bool btnLinkPageIsChecked = true;
  338. public bool BtnLinkPageIsChecked
  339. {
  340. get { return btnLinkPageIsChecked; }
  341. set
  342. {
  343. SetProperty(ref btnLinkPageIsChecked, value);
  344. }
  345. }
  346. private bool btnLinkWebIsChecked = false;
  347. public bool BtnLinkWebIsChecked
  348. {
  349. get { return btnLinkWebIsChecked; }
  350. set
  351. {
  352. SetProperty(ref btnLinkWebIsChecked, value);
  353. }
  354. }
  355. private bool btnLinkMailIsChecked = false;
  356. public bool BtnLinkMailIsChecked
  357. {
  358. get { return btnLinkMailIsChecked; }
  359. set
  360. {
  361. SetProperty(ref btnLinkMailIsChecked, value);
  362. }
  363. }
  364. #endregion 按钮、图片的设置
  365. private bool isLoaded = false;
  366. private bool isMail = false;
  367. private bool isSelected = false;
  368. private string historyBtnGOorBackTag = string.Empty;
  369. private int totalPage = 0;
  370. private int backPageIndex = 0;
  371. private int historyPageIndex = 0;
  372. private CPDFViewer pdfViewer;
  373. private CPDFDocument document;
  374. private Button btnGOorBack = null;
  375. private LinkAnnotProperty linkAnnot;
  376. private AnnotPropertyPanel propertyPanel;
  377. private ViewContentViewModel viewContentViewModel;
  378. public IRegionManager region;
  379. public IDialogService dialogs;
  380. public IEventAggregator events;
  381. #region 命令
  382. public DelegateCommand<object> LoadedCommand { get; set; }
  383. public DelegateCommand<object> PageNumTextLostFocusCommand { get; set; }
  384. public DelegateCommand<object> PageNumTextKeyDownCommand { get; set; }
  385. public DelegateCommand<object> PageMailTextLostFocusCommand { get; set; }
  386. public DelegateCommand<object> PageMailTextKeyDownCommand { get; set; }
  387. public DelegateCommand<object> PageWebTextLostFocusCommand { get; set; }
  388. public DelegateCommand<object> PageWebTextKeyDownCommand { get; set; }
  389. public DelegateCommand<object> BtnGOorBackPageCommand { get; set; }
  390. public DelegateCommand<object> LocationCommand { get; set; }
  391. public DelegateCommand<object> ToggleButtonTabCommand { get; set; }
  392. #endregion 命令
  393. public LinkAnnotPropertyViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  394. {
  395. region = regionManager;
  396. dialogs = dialogService;
  397. events = eventAggregator;
  398. LoadedCommand = new DelegateCommand<object>(Loaded);
  399. PageNumTextLostFocusCommand = new DelegateCommand<object>(PageNumTextLostFocus);
  400. PageNumTextKeyDownCommand = new DelegateCommand<object>(PageNumTextKeyDown);
  401. PageMailTextLostFocusCommand = new DelegateCommand<object>(PageMailTextLostFocus);
  402. PageMailTextKeyDownCommand = new DelegateCommand<object>(PageMailTextKeyDown);
  403. PageWebTextLostFocusCommand = new DelegateCommand<object>(PageWebTextLostFocus);
  404. PageWebTextKeyDownCommand = new DelegateCommand<object>(PageWebTextKeyDown);
  405. BtnGOorBackPageCommand = new DelegateCommand<object>(BtnGOorBackPageEvent);
  406. LocationCommand = new DelegateCommand<object>(LocationPage);
  407. ToggleButtonTabCommand = new DelegateCommand<object>(ToggleButtonTabSelected);
  408. isLoaded = true;
  409. }
  410. private void PageWebTextKeyDown(object obj)
  411. {
  412. if (obj is KeyEventArgs keyEventArgs)
  413. {
  414. if (keyEventArgs.Key == Key.Enter)
  415. {
  416. PageWebTextLostFocus(obj);
  417. }
  418. }
  419. }
  420. private void PageWebTextLostFocus(object obj)
  421. {
  422. if (!string.IsNullOrEmpty(PageWebTextContent))
  423. {
  424. if (CheckPageWebVaild(PageWebTextContent))
  425. {
  426. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  427. PageWebTextContent = PageWebTextContent.Trim().ToLower();
  428. if (!PageWebTextContent.StartsWith("http://") && !PageWebTextContent.StartsWith("https://"))
  429. {
  430. PageWebTextContent = "http://" + PageWebTextContent;
  431. }
  432. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, PageWebTextContent);
  433. AnnotAttribEvent?.UpdateAnnot();
  434. LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  435. }
  436. }
  437. }
  438. private void PageMailTextKeyDown(object obj)
  439. {
  440. if (obj is KeyEventArgs keyEventArgs)
  441. {
  442. if (keyEventArgs.Key == Key.Enter)
  443. {
  444. PageMailTextLostFocus(obj);
  445. }
  446. }
  447. }
  448. private void PageMailTextLostFocus(object obj)
  449. {
  450. if (!string.IsNullOrEmpty(PageMailTextContent))
  451. {
  452. if (CheckPageMailVaild(PageMailTextContent))
  453. {
  454. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  455. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, "mailto:" + PageMailTextContent.Trim());
  456. AnnotAttribEvent?.UpdateAnnot();
  457. LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  458. }
  459. }
  460. }
  461. /// <summary>
  462. /// 页码文本框 Enter键
  463. /// </summary>
  464. /// <param name="obj"></param>
  465. private void PageNumTextKeyDown(object obj)
  466. {
  467. if (obj is KeyEventArgs keyEventArgs)
  468. {
  469. if (keyEventArgs.Key == Key.Enter)
  470. {
  471. PageNumTextLostFocus(obj);
  472. }
  473. }
  474. }
  475. /// <summary>
  476. /// 页码文本框失去焦点
  477. /// </summary>
  478. /// <param name="obj"></param>
  479. private void PageNumTextLostFocus(object obj)
  480. {
  481. if (!string.IsNullOrEmpty(PageNumTextContent))
  482. {
  483. if (CheckPageNumVaild(out int pageNum, PageNumTextContent))
  484. {
  485. //isSelected = true;
  486. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
  487. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageNum - 1);
  488. AnnotAttribEvent?.UpdateAnnot();
  489. //isTextChanged = false;
  490. SetImagePreview(LinkAnnotArgs.DestIndex);
  491. //ImagePreviewVisibility = Visibility.Collapsed;
  492. //BtnGOorBackVisibility= Visibility.Collapsed;
  493. BtnLocationIsEnabled = false;
  494. LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  495. SelectAnnotation();
  496. }
  497. else
  498. {
  499. ImagePreviewVisibility = Visibility.Collapsed;
  500. BtnGOorBackVisibility = Visibility.Collapsed;
  501. isSelected = false;
  502. }
  503. }
  504. }
  505. /// <summary>
  506. /// 模块选择
  507. /// </summary>
  508. /// <param name="obj"></param>
  509. private void ToggleButtonTabSelected(object obj)
  510. {
  511. if (obj is RadioButton radioButton)
  512. {
  513. switch (radioButton.Tag)
  514. {
  515. case "Page":
  516. LinkAnnotArgs.LinkType = LINK_TYPE.GOTO;
  517. LinkAnnotArgs.URI = string.Empty;
  518. AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.GOTO;
  519. AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
  520. isMail = false;
  521. if (btnGOorBack != null)
  522. {
  523. if (!string.IsNullOrEmpty(historyBtnGOorBackTag))
  524. {
  525. ChangeBtnGOorBack(historyBtnGOorBackTag, btnGOorBack);
  526. }
  527. else
  528. {
  529. ChangeBtnGOorBack("GO", btnGOorBack);
  530. }
  531. }
  532. BtnGOorBackVisibility = string.IsNullOrEmpty(PageNumTextContent) ? Visibility.Collapsed : Visibility.Visible;
  533. break;
  534. case "Web":
  535. isMail = false;
  536. SetLinkType_URIState("Web");
  537. BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
  538. break;
  539. case "Mail":
  540. isMail = true;
  541. SetLinkType_URIState("Mail");
  542. BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
  543. break;
  544. }
  545. }
  546. }
  547. /// <summary>
  548. /// 设置BtnGOorBack状态
  549. /// </summary>
  550. /// <param name="uri"></param>
  551. private void SetLinkType_URIState(string uri)
  552. {
  553. LinkAnnotArgs.LinkType = LINK_TYPE.URI;
  554. LinkAnnotArgs.URI = string.Empty;
  555. AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
  556. AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
  557. if (btnGOorBack != null)
  558. {
  559. historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
  560. //ChangeBtnGOorBack("GO", btnGOorBack);
  561. switch (uri)
  562. {
  563. case "Web":
  564. if (!string.IsNullOrEmpty(PageWebTextContent))
  565. {
  566. ChangeBtnGOorBack("GO", btnGOorBack);
  567. }
  568. //BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
  569. break;
  570. case "Mail":
  571. if (!string.IsNullOrEmpty(PageMailTextContent))
  572. {
  573. ChangeBtnGOorBack("GO", btnGOorBack);
  574. }
  575. //BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
  576. break;
  577. }
  578. }
  579. }
  580. /// <summary>
  581. /// 定位目标范围
  582. /// </summary>
  583. /// <param name="obj"></param>
  584. private void LocationPage(object obj)
  585. {
  586. pdfViewer.EnableDrawSelectArea(true);
  587. historyPageIndex = pdfViewer.CurrentIndex;
  588. PageNumTextIsEnabled = false;
  589. isSelected = false;
  590. BtnLocationIsChecked = true;
  591. bool isExist = false;
  592. if (region.Regions.ContainsRegionWithName(viewContentViewModel.TipContentRegionName))
  593. {
  594. var views = region.Regions[viewContentViewModel.TipContentRegionName].Views;
  595. foreach (var item in views)
  596. {
  597. if (item is Views.TipContent.LinkAnnotTip linkAnnotTip)
  598. {
  599. isExist = true;
  600. break;
  601. }
  602. }
  603. }
  604. if (isExist == false)
  605. {
  606. region.RequestNavigate(viewContentViewModel.TipContentRegionName, "LinkAnnotTip");
  607. }
  608. //if(string.IsNullOrEmpty(PageNumTextContent))
  609. viewContentViewModel.ShowTip(true);
  610. }
  611. /// <summary>
  612. /// 前往/返回按钮
  613. /// </summary>
  614. /// <param name="obj"></param>
  615. private void BtnGOorBackPageEvent(object obj)
  616. {
  617. if (obj is object[] arry)
  618. {
  619. btnGOorBack = arry[0] as Button;
  620. RadioButton btnLinkPage = arry[1] as RadioButton;
  621. RadioButton btnLinkWeb = arry[2] as RadioButton;
  622. RadioButton btnLinkMail = arry[3] as RadioButton;
  623. if (btnLinkPage != null && btnGOorBack != null && btnLinkWeb != null && btnLinkMail != null)
  624. {
  625. if (btnLinkPage.IsChecked == true)
  626. {
  627. LinkPageGoOrBack();
  628. }
  629. if (btnLinkWeb.IsChecked == true)
  630. {
  631. LinkWebSave();
  632. }
  633. if (btnLinkMail.IsChecked == true)
  634. {
  635. LinkMailSave();
  636. }
  637. }
  638. }
  639. }
  640. /// <summary>
  641. /// 保存邮件链接
  642. /// </summary>
  643. private void LinkMailSave()
  644. {
  645. if (CheckPageMailVaild(PageMailTextContent))
  646. {
  647. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  648. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, "mailto:" + PageMailTextContent.Trim());
  649. //AnnotAttribEvent?.UpdateAnnot();
  650. //LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  651. Process.Start("mailto:?to=" + PageMailTextContent.Trim());
  652. }
  653. }
  654. /// <summary>
  655. /// 保存web链接
  656. /// </summary>
  657. private void LinkWebSave()
  658. {
  659. if (CheckPageWebVaild(PageWebTextContent))
  660. {
  661. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  662. //PageWebTextContent = PageWebTextContent.Trim().ToLower();
  663. //if (!PageWebTextContent.StartsWith("http://") && !PageWebTextContent.StartsWith("https://"))
  664. //{
  665. // PageWebTextContent = "http://" + PageWebTextContent;
  666. //}
  667. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, PageWebTextContent);
  668. //AnnotAttribEvent?.UpdateAnnot();
  669. //LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  670. if (PageWebTextContent.StartsWith("http://") || PageWebTextContent.StartsWith("https://"))
  671. {
  672. Process.Start(PageWebTextContent);
  673. }
  674. }
  675. else
  676. {
  677. BtnGOorBackVisibility = Visibility.Collapsed;
  678. }
  679. }
  680. /// <summary>
  681. /// 页码链接 GoOrBack
  682. /// </summary>
  683. private void LinkPageGoOrBack()
  684. {
  685. int pageIndex = Convert.ToInt32(PageNumTextContent) - 1;
  686. if (btnGOorBack.Tag.ToString() == "GO")
  687. {
  688. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
  689. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageIndex);
  690. //AnnotAttribEvent?.UpdateAnnot();
  691. historyPageIndex = LinkAnnotArgs != null ? LinkAnnotArgs.PageIndex : backPageIndex;
  692. pdfViewer.GoToPage(pageIndex);
  693. ChangeBtnGOorBack("BACK", btnGOorBack);
  694. }
  695. else
  696. {
  697. if (historyPageIndex != -1)
  698. {
  699. SelectAnnotation();
  700. pdfViewer.GoToPage(historyPageIndex);
  701. ChangeBtnGOorBack("GO", btnGOorBack);
  702. }
  703. }
  704. }
  705. /// <summary>
  706. /// 选择注释
  707. /// </summary>
  708. private void SelectAnnotation()
  709. {
  710. if (linkAnnotArgs != null && !isSelected && linkAnnotArgs.AnnotIndex >= 0)
  711. {
  712. pdfViewer.SelectAnnotation(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  713. isSelected = true;
  714. }
  715. else
  716. {
  717. isSelected = false;
  718. }
  719. }
  720. /// <summary>
  721. /// 设置前往/返回按钮的文本
  722. /// </summary>
  723. /// <param name="flag"></param>
  724. /// <param name="button"></param>
  725. private void ChangeBtnGOorBack(string flag, Button button)
  726. {
  727. switch (flag)
  728. {
  729. case "BACK":
  730. button.Tag = "BACK";
  731. button.Content = "BACK";
  732. break;
  733. case "GO":
  734. button.Tag = "GO";
  735. button.Content = "GO";
  736. break;
  737. default:
  738. break;
  739. }
  740. }
  741. /// <summary>
  742. /// 页码格式验证
  743. /// </summary>
  744. /// <param name="pageNum"></param>
  745. /// <param name="text"></param>
  746. /// <returns></returns>
  747. private bool CheckPageNumVaild(out int pageNum, string text)
  748. {
  749. pageNum = -1;
  750. if (string.IsNullOrEmpty(text))
  751. {
  752. return false;
  753. }
  754. if (text.Trim() != string.Empty)
  755. {
  756. if (!int.TryParse(text.Trim(), out pageNum))
  757. {
  758. ShowPageNumTip = Visibility.Visible;
  759. PageNumTipText = " Page number error.";
  760. return false;
  761. }
  762. }
  763. if (pageNum < 1 || pageNum > totalPage)
  764. {
  765. ShowPageNumTip = Visibility.Visible;
  766. PageNumTipText = " Page number out of range.";
  767. return false;
  768. }
  769. else
  770. {
  771. ShowPageNumTip = Visibility.Collapsed;
  772. }
  773. //BtnGOorBackVisibility = Visibility.Visible;
  774. return true;
  775. }
  776. /// <summary>
  777. /// web链接格式验证
  778. /// </summary>
  779. /// <param name="text"></param>
  780. /// <returns></returns>
  781. private bool CheckPageWebVaild(string text)
  782. {
  783. BtnGOorBackVisibility = Visibility.Collapsed;
  784. if (string.IsNullOrEmpty(text))
  785. {
  786. return false;
  787. }
  788. string checkUrl = text.ToLower().TrimStart("http://".ToCharArray()).TrimStart("https://".ToCharArray());
  789. if (!Regex.IsMatch(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+"))
  790. {
  791. ShowPageWebTip = Visibility.Visible;
  792. PageWebTipText = "Invalid link.";
  793. return false;
  794. }
  795. string matchText = Regex.Match(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+").Value;
  796. if (matchText.Length != checkUrl.Length)
  797. {
  798. ShowPageWebTip = Visibility.Visible;
  799. PageWebTipText = "Invalid link.";
  800. return false;
  801. }
  802. else
  803. {
  804. ShowPageWebTip = Visibility.Collapsed;
  805. }
  806. BtnGOorBackVisibility = Visibility.Visible;
  807. return true;
  808. }
  809. /// <summary>
  810. /// 邮箱链接格式验证
  811. /// </summary>
  812. /// <param name="text"></param>
  813. /// <returns></returns>
  814. private bool CheckPageMailVaild(string text)
  815. {
  816. BtnGOorBackVisibility = Visibility.Collapsed;
  817. if (string.IsNullOrEmpty(text))
  818. {
  819. return false;
  820. }
  821. if (!Regex.IsMatch(text, "^[A-Za-z0-9\u4e00-\u9fa5_\\-\\.]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"))
  822. {
  823. ShowPageMailTip = Visibility.Visible;
  824. PageMailTipText = "The email is invalid.Please enter a valid email address.";
  825. return false;
  826. }
  827. else
  828. {
  829. ShowPageMailTip = Visibility.Collapsed;
  830. }
  831. BtnGOorBackVisibility = Visibility.Visible;
  832. return true;
  833. }
  834. /// <summary>
  835. /// 设置图像
  836. /// </summary>
  837. /// <param name="pageIndex"></param>
  838. private void SetImagePreview(int pageIndex)
  839. {
  840. ImagePreviewVisibility = Visibility.Visible;
  841. BtnGOorBackVisibility = Visibility.Visible;
  842. BtnLocationIsEnabled = true;
  843. int dpiHeight = (int)ImagePreviewHeight;
  844. int dpiWidth = (int)ImagePreviewWidth;
  845. if (dpiHeight <= 0 || dpiWidth <= 0)
  846. {
  847. return;
  848. }
  849. //int pageIndex = AnnotArgs.DestIndex;
  850. Rect MediaRect = GetPageRect(document, pageIndex, CPDFDisplayBox.MediaBox);
  851. System.Windows.Size pageSize = GetPageSize(document, pageIndex);
  852. double scale = Math.Min(dpiWidth / MediaRect.Width, dpiHeight / MediaRect.Height);
  853. scale = Math.Min(scale, 1);
  854. int cropWidth = (int)(scale * pageSize.Width);
  855. int cropHeight = (int)(scale * pageSize.Height);
  856. byte[] imageDatas = RenderPDFPageToArray(document, pageIndex, new Rect(0, 0, cropWidth, cropHeight), scale, true, true);
  857. WriteableBitmap WirteBitmap = new WriteableBitmap(cropWidth, cropHeight, 96, 96, PixelFormats.Bgra32, null);
  858. WirteBitmap.WritePixels(new Int32Rect(0, 0, cropWidth, cropHeight), imageDatas, WirteBitmap.BackBufferStride, 0);
  859. PreviewImage = WirteBitmap;
  860. }
  861. /// <summary>
  862. /// 链接画框完成时触发事件
  863. /// </summary>
  864. /// <param name="sender"></param>
  865. /// <param name="e"></param>
  866. private void linkAnnotArgs_LinkDrawFinished(object sender, bool e)
  867. {
  868. SetTextBoxEnableOrNot(e, totalPage);
  869. }
  870. private void Loaded(object obj)
  871. {
  872. if (obj is CompositeCommandParameter composite)
  873. {
  874. if (composite.Parameter is LinkAnnotProperty linkAnnotProperty)
  875. {
  876. linkAnnot = linkAnnotProperty;
  877. }
  878. }
  879. }
  880. public bool IsNavigationTarget(NavigationContext navigationContext)
  881. {
  882. return true;
  883. }
  884. public void OnNavigatedFrom(NavigationContext navigationContext)
  885. {
  886. }
  887. public void OnNavigatedTo(NavigationContext navigationContext)
  888. {
  889. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanel);
  890. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  891. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  892. if (propertyPanel != null && pdfViewer != null)
  893. {
  894. pdfViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
  895. pdfViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
  896. AnnotAttribEvent = propertyPanel.AnnotEvent;
  897. AnnotType = propertyPanel.annot.EventType;
  898. document = pdfViewer.Document;
  899. totalPage = pdfViewer.Document.PageCount;
  900. if (viewContentViewModel.IsRightMenuCreateLink)
  901. {
  902. SetTextBoxEnableOrNot(true, totalPage);
  903. }
  904. else
  905. {
  906. SetTextBoxEnableOrNot(false, totalPage);
  907. }
  908. if (AnnotAttribEvent.IsAnnotCreateReset == false)
  909. {
  910. GetAnnotAttribute();
  911. }
  912. if (isLoaded)
  913. {
  914. if (pdfViewer != null && pdfViewer.ToolManager != null && pdfViewer.ToolManager.CurrentAnnotArgs?.EventType == AnnotArgsType.AnnotLink)
  915. {
  916. if (btnGOorBack != null)
  917. {
  918. ChangeBtnGOorBack("GO", btnGOorBack);
  919. }
  920. if (AnnotAttribEvent.IsAnnotCreateReset)
  921. {
  922. LinkAnnotArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
  923. if (LinkAnnotArgs == null)
  924. {
  925. backPageIndex = pdfViewer.CurrentIndex;
  926. }
  927. else
  928. {
  929. LinkAnnotArgs.PageIndex = pdfViewer.CurrentIndex;
  930. }
  931. }
  932. }
  933. }
  934. if (LinkAnnotArgs == null)
  935. {
  936. LinkAnnotArgs = (LinkAnnotArgs)propertyPanel.annot;
  937. }
  938. }
  939. }
  940. /// <summary>
  941. /// 定位目标范围完成时,触发
  942. /// </summary>
  943. /// <param name="sender"></param>
  944. /// <param name="e"></param>
  945. private async void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
  946. {
  947. if (e.NotifyType == CustomNotifyType.LinkAreaLocate)
  948. {
  949. if (e.NotifyData is AreaLocate areaInfo)
  950. {
  951. if (pdfViewer.ToolManager.CurrentAnnotArgs.EventType == AnnotArgsType.AnnotLink && pdfViewer.MouseMode == MouseModes.AnnotCreate)
  952. {
  953. LinkAnnotArgs linkArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
  954. System.Windows.Size pageSize = pdfViewer.Document.GetPageSize(areaInfo.PageIndex);
  955. linkArgs.IsPositionSet = true;
  956. linkArgs.DestIndex = areaInfo.PageIndex;
  957. linkArgs.DestinationPos = new System.Windows.Point(areaInfo.Area.X, pageSize.Height - areaInfo.Area.Y);
  958. LinkAnnotArgs = linkArgs;
  959. LinkAnnotArgs.PageIndex = historyPageIndex;
  960. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
  961. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
  962. AnnotAttribEvent?.UpdateAnnot();
  963. LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  964. PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
  965. SetImagePreview(areaInfo.PageIndex);
  966. await System.Threading.Tasks.Task.Delay(2);
  967. SelectAnnotation();
  968. pdfViewer.GoToPage(historyPageIndex);
  969. //viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
  970. viewContentViewModel.TipVisible = Visibility.Collapsed;
  971. BtnLocationIsChecked = false;
  972. }
  973. }
  974. }
  975. }
  976. /// <summary>
  977. /// 选择链接后,显示参数
  978. /// </summary>
  979. private void GetAnnotAttribute()
  980. {
  981. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
  982. {
  983. SetLinkType((LINK_TYPE)AnnotAttribEvent.Attribs[AnnotAttrib.LinkType]);
  984. }
  985. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkDestIndx) && !AnnotAttribEvent.IsAnnotCreateReset)
  986. {
  987. SetLinkPageNum((int)AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] + 1);
  988. if (LinkAnnotArgs == null)
  989. {
  990. backPageIndex = pdfViewer.CurrentIndex;
  991. }
  992. else
  993. {
  994. LinkAnnotArgs.PageIndex = pdfViewer.CurrentIndex;
  995. }
  996. }
  997. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkUri))
  998. {
  999. string linkUrl = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri];
  1000. if (!string.IsNullOrEmpty(linkUrl))
  1001. {
  1002. if (linkUrl.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
  1003. {
  1004. SetLinkType(LINK_TYPE.URI, true);
  1005. if (AnnotAttribEvent.IsAnnotCreateReset)
  1006. {
  1007. SetLinkEmail("");
  1008. }
  1009. else
  1010. {
  1011. SetLinkEmail(linkUrl.ToLower().TrimStart("mailto:".ToCharArray()));
  1012. }
  1013. }
  1014. else
  1015. {
  1016. if (AnnotAttribEvent.IsAnnotCreateReset)
  1017. {
  1018. SetLinkUrl("");
  1019. }
  1020. else
  1021. {
  1022. SetLinkUrl(linkUrl);
  1023. }
  1024. }
  1025. }
  1026. }
  1027. }
  1028. private void SetLinkUrl(string url)
  1029. {
  1030. PageWebTextContent = url;
  1031. PageWebTextIsEnabled = true;
  1032. }
  1033. private void SetLinkEmail(string email)
  1034. {
  1035. PageMailTextContent = email;
  1036. PageMailTextIsEnabled = true;
  1037. }
  1038. /// <summary>
  1039. /// 设置页码的数据
  1040. /// </summary>
  1041. /// <param name="pageNum"></param>
  1042. private void SetLinkPageNum(int pageNum)
  1043. {
  1044. if (pageNum > 0 && pageNum <= totalPage)
  1045. {
  1046. PageNumTextContent = pageNum.ToString();
  1047. BtnLocationIsEnabled = true;
  1048. PageNumTextIsEnabled = true;
  1049. ImagePreviewVisibility = Visibility.Visible;
  1050. SetImagePreview(pageNum - 1);
  1051. BtnLocationIsEnabled = true;
  1052. //if (btnGOorBack != null)
  1053. //{
  1054. // ChangeBtnGOorBack("GO", btnGOorBack);
  1055. //}
  1056. }
  1057. }
  1058. /// <summary>
  1059. /// 根据链接类型显示模块
  1060. /// </summary>
  1061. /// <param name="linkType"></param>
  1062. /// <param name="isMail"></param>
  1063. public void SetLinkType(LINK_TYPE linkType, bool isMail = false)
  1064. {
  1065. BtnLinkPageIsChecked = false;
  1066. BtnLinkMailIsChecked = false;
  1067. BtnLinkWebIsChecked = false;
  1068. switch (linkType)
  1069. {
  1070. case LINK_TYPE.GOTO:
  1071. BtnLinkPageIsChecked = true;
  1072. break;
  1073. case LINK_TYPE.URI:
  1074. if (this.isMail || isMail)
  1075. {
  1076. BtnLinkMailIsChecked = true;
  1077. }
  1078. else
  1079. {
  1080. BtnLinkWebIsChecked = true;
  1081. }
  1082. break;
  1083. default:
  1084. BtnLinkPageIsChecked = true;
  1085. break;
  1086. }
  1087. }
  1088. /// <summary>
  1089. /// 设置文本框和按钮的属性
  1090. /// </summary>
  1091. /// <param name="enable"></param>
  1092. /// <param name="totalPage"></param>
  1093. private void SetTextBoxEnableOrNot(bool enable, int totalPage)
  1094. {
  1095. this.totalPage = totalPage;
  1096. PageNumTextContent = string.Empty;
  1097. PageWebTextContent = string.Empty;
  1098. PageMailTextContent = string.Empty;
  1099. PageNumTextIsEnabled = enable;
  1100. PageWebTextIsEnabled = enable;
  1101. PageMailTextIsEnabled = enable;
  1102. PageNumPlaceHoldText = PageNumTextIsEnabled ? string.Format($"1-{totalPage}页") : "输入目标页面";
  1103. PageWebPlaceHoldText = PageWebTextIsEnabled ? "https://www.pdfreaderpro.com" : "输入您要跳转的链接";
  1104. PageMailPlaceHoldText = PageMailTextIsEnabled ? "support@pdfreaderpro.com" : "输入您要跳转邮件地址";
  1105. ShowPageNumTip = Visibility.Collapsed;
  1106. ShowPageWebTip = Visibility.Collapsed;
  1107. ShowPageMailTip = Visibility.Collapsed;
  1108. BtnLocationIsEnabled = enable;
  1109. }
  1110. /// <summary>
  1111. /// 将PDF的页面转换成数据流
  1112. /// </summary>
  1113. /// <param name="document"></param>
  1114. /// <param name="pageIndex"></param>
  1115. /// <param name="renderRect"></param>
  1116. /// <param name="currentZoom"></param>
  1117. /// <param name="renderAnnot"></param>
  1118. /// <param name="renderForm"></param>
  1119. /// <returns></returns>
  1120. public byte[] RenderPDFPageToArray(CPDFDocument document, int pageIndex, Rect renderRect, double currentZoom, bool renderAnnot = false, bool renderForm = false)
  1121. {
  1122. if (renderRect.Width <= 0 || renderRect.Height <= 0 || document == null)
  1123. {
  1124. return null;
  1125. }
  1126. try
  1127. {
  1128. byte[] bmpData = new byte[(int)renderRect.Width * (int)renderRect.Height * 4];
  1129. currentZoom = currentZoom * 96 / 72;
  1130. int flag = 0;
  1131. if (renderAnnot)
  1132. {
  1133. flag = 1;
  1134. }
  1135. uint bgColor = 0xFFFFFFFF;
  1136. CPDFPage page = document.PageAtIndex(pageIndex);
  1137. if (page.IsValid())
  1138. {
  1139. page.RenderPageBitmapWithMatrix((float)currentZoom, renderRect, bgColor, bmpData, flag, renderForm);
  1140. }
  1141. return bmpData;
  1142. }
  1143. catch (Exception ex)
  1144. {
  1145. return null;
  1146. }
  1147. }
  1148. /// <summary>
  1149. /// 获取页面的矩形
  1150. /// </summary>
  1151. /// <param name="document"></param>
  1152. /// <param name="pageIndex"></param>
  1153. /// <param name="displayBox"></param>
  1154. /// <returns></returns>
  1155. private Rect GetPageRect(CPDFDocument document, int pageIndex, CPDFDisplayBox displayBox)
  1156. {
  1157. CPDFPage currentPage = document.PageAtIndex(pageIndex);
  1158. Rect boundBox = currentPage.GetBoundsForBox(displayBox);
  1159. Rect boundRect = new Rect((int)(boundBox.Left / 72.0 * 96.0), (int)(boundBox.Top / 72.0 * 96.0),
  1160. (int)(boundBox.Width / 72.0 * 96.0), (int)(boundBox.Height / 72.0 * 96.0));
  1161. return boundRect;
  1162. }
  1163. /// <summary>
  1164. /// 获取页面的尺寸
  1165. /// </summary>
  1166. /// <param name="document"></param>
  1167. /// <param name="pageIndex"></param>
  1168. /// <returns></returns>
  1169. private System.Windows.Size GetPageSize(CPDFDocument document, int pageIndex)
  1170. {
  1171. System.Windows.Size pageSize = document.GetPageSize(pageIndex);
  1172. pageSize.Width = pageSize.Width / 72.0 * 96;
  1173. pageSize.Height = pageSize.Height / 72.0 * 96;
  1174. return pageSize;
  1175. }
  1176. }
  1177. }