LinkAnnotPropertyViewModel.cs 44 KB

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