LinkAnnotPropertyViewModel.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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. if(string.IsNullOrEmpty(PageNumTextContent))
  598. viewContentViewModel.ShowTip(true);
  599. }
  600. /// <summary>
  601. /// 前往/返回按钮
  602. /// </summary>
  603. /// <param name="obj"></param>
  604. private void BtnGOorBackPageEvent(object obj)
  605. {
  606. if (obj is object[] arry)
  607. {
  608. btnGOorBack = arry[0] as Button;
  609. RadioButton btnLinkPage = arry[1] as RadioButton;
  610. RadioButton btnLinkWeb = arry[2] as RadioButton;
  611. RadioButton btnLinkMail = arry[3] as RadioButton;
  612. if (btnLinkPage != null && btnGOorBack != null && btnLinkWeb != null && btnLinkMail != null)
  613. {
  614. if (btnLinkPage.IsChecked == true)
  615. {
  616. LinkPageGoOrBack();
  617. }
  618. if (btnLinkWeb.IsChecked == true)
  619. {
  620. LinkWebSave();
  621. }
  622. if (btnLinkMail.IsChecked == true)
  623. {
  624. LinkMailSave();
  625. }
  626. }
  627. }
  628. }
  629. /// <summary>
  630. /// 保存邮件链接
  631. /// </summary>
  632. private void LinkMailSave()
  633. {
  634. if (CheckPageMailVaild(PageMailTextContent))
  635. {
  636. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  637. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, "mailto:" + PageMailTextContent.Trim());
  638. //AnnotAttribEvent?.UpdateAnnot();
  639. //LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  640. Process.Start("mailto:?to=" + PageMailTextContent.Trim());
  641. }
  642. }
  643. /// <summary>
  644. /// 保存web链接
  645. /// </summary>
  646. private void LinkWebSave()
  647. {
  648. if (CheckPageWebVaild(PageWebTextContent))
  649. {
  650. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
  651. //PageWebTextContent = PageWebTextContent.Trim().ToLower();
  652. //if (!PageWebTextContent.StartsWith("http://") && !PageWebTextContent.StartsWith("https://"))
  653. //{
  654. // PageWebTextContent = "http://" + PageWebTextContent;
  655. //}
  656. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, PageWebTextContent);
  657. //AnnotAttribEvent?.UpdateAnnot();
  658. //LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
  659. if (PageWebTextContent.StartsWith("http://") || PageWebTextContent.StartsWith("https://"))
  660. {
  661. Process.Start(PageWebTextContent);
  662. }
  663. }
  664. else
  665. {
  666. BtnGOorBackVisibility = Visibility.Collapsed;
  667. }
  668. }
  669. /// <summary>
  670. /// 页码链接 GoOrBack
  671. /// </summary>
  672. private void LinkPageGoOrBack()
  673. {
  674. int pageIndex = Convert.ToInt32(PageNumTextContent) - 1;
  675. if (btnGOorBack.Tag.ToString() == "GO")
  676. {
  677. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
  678. //AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageIndex);
  679. //AnnotAttribEvent?.UpdateAnnot();
  680. historyPageIndex = LinkAnnotArgs != null ? LinkAnnotArgs.PageIndex : backPageIndex;
  681. pdfViewer.GoToPage(pageIndex);
  682. ChangeBtnGOorBack("BACK", btnGOorBack);
  683. }
  684. else
  685. {
  686. if (historyPageIndex != -1)
  687. {
  688. SelectAnnotation();
  689. pdfViewer.GoToPage(historyPageIndex);
  690. ChangeBtnGOorBack("GO", btnGOorBack);
  691. }
  692. }
  693. }
  694. /// <summary>
  695. /// 选择注释
  696. /// </summary>
  697. private void SelectAnnotation()
  698. {
  699. if (linkAnnotArgs != null && !isSelected && linkAnnotArgs.AnnotIndex >= 0)
  700. {
  701. pdfViewer.SelectAnnotation(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  702. isSelected = true;
  703. }
  704. else
  705. {
  706. isSelected = false;
  707. }
  708. }
  709. /// <summary>
  710. /// 设置前往/返回按钮的文本
  711. /// </summary>
  712. /// <param name="flag"></param>
  713. /// <param name="button"></param>
  714. private void ChangeBtnGOorBack(string flag, Button button)
  715. {
  716. switch (flag)
  717. {
  718. case "BACK":
  719. button.Tag = "BACK";
  720. button.Content = "BACK";
  721. break;
  722. case "GO":
  723. button.Tag = "GO";
  724. button.Content = "GO";
  725. break;
  726. default:
  727. break;
  728. }
  729. }
  730. /// <summary>
  731. /// 页码格式验证
  732. /// </summary>
  733. /// <param name="pageNum"></param>
  734. /// <param name="text"></param>
  735. /// <returns></returns>
  736. private bool CheckPageNumVaild(out int pageNum, string text)
  737. {
  738. pageNum = -1;
  739. if (string.IsNullOrEmpty(text))
  740. {
  741. return false;
  742. }
  743. if (text.Trim() != string.Empty)
  744. {
  745. if (!int.TryParse(text.Trim(), out pageNum))
  746. {
  747. ShowPageNumTip = Visibility.Visible;
  748. PageNumTipText = " Page number error.";
  749. return false;
  750. }
  751. }
  752. if (pageNum < 1 || pageNum > totalPage)
  753. {
  754. ShowPageNumTip = Visibility.Visible;
  755. PageNumTipText = " Page number out of range.";
  756. return false;
  757. }
  758. else
  759. {
  760. ShowPageNumTip = Visibility.Collapsed;
  761. }
  762. //BtnGOorBackVisibility = Visibility.Visible;
  763. return true;
  764. }
  765. /// <summary>
  766. /// web链接格式验证
  767. /// </summary>
  768. /// <param name="text"></param>
  769. /// <returns></returns>
  770. private bool CheckPageWebVaild(string text)
  771. {
  772. BtnGOorBackVisibility = Visibility.Collapsed;
  773. if (string.IsNullOrEmpty(text))
  774. {
  775. return false;
  776. }
  777. string checkUrl = text.ToLower().TrimStart("http://".ToCharArray()).TrimStart("https://".ToCharArray());
  778. if (!Regex.IsMatch(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+"))
  779. {
  780. ShowPageWebTip = Visibility.Visible;
  781. PageWebTipText = "Invalid link.";
  782. return false;
  783. }
  784. string matchText = Regex.Match(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+").Value;
  785. if (matchText.Length != checkUrl.Length)
  786. {
  787. ShowPageWebTip = Visibility.Visible;
  788. PageWebTipText = "Invalid link.";
  789. return false;
  790. }
  791. else
  792. {
  793. ShowPageWebTip = Visibility.Collapsed;
  794. }
  795. BtnGOorBackVisibility = Visibility.Visible;
  796. return true;
  797. }
  798. /// <summary>
  799. /// 邮箱链接格式验证
  800. /// </summary>
  801. /// <param name="text"></param>
  802. /// <returns></returns>
  803. private bool CheckPageMailVaild(string text)
  804. {
  805. BtnGOorBackVisibility = Visibility.Collapsed;
  806. if (string.IsNullOrEmpty(text))
  807. {
  808. return false;
  809. }
  810. if (!Regex.IsMatch(text, "^[A-Za-z0-9\u4e00-\u9fa5_\\-\\.]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"))
  811. {
  812. ShowPageMailTip = Visibility.Visible;
  813. PageMailTipText = "The email is invalid.Please enter a valid email address.";
  814. return false;
  815. }
  816. else
  817. {
  818. ShowPageMailTip = Visibility.Collapsed;
  819. }
  820. BtnGOorBackVisibility = Visibility.Visible;
  821. return true;
  822. }
  823. /// <summary>
  824. /// 设置图像
  825. /// </summary>
  826. /// <param name="pageIndex"></param>
  827. private void SetImagePreview(int pageIndex)
  828. {
  829. ImagePreviewVisibility = Visibility.Visible;
  830. BtnGOorBackVisibility = Visibility.Visible;
  831. int dpiHeight = (int)ImagePreviewHeight;
  832. int dpiWidth = (int)ImagePreviewWidth;
  833. if (dpiHeight <= 0 || dpiWidth <= 0)
  834. {
  835. return;
  836. }
  837. //int pageIndex = AnnotArgs.DestIndex;
  838. Rect MediaRect = GetPageRect(document, pageIndex, CPDFDisplayBox.MediaBox);
  839. System.Windows.Size pageSize = GetPageSize(document, pageIndex);
  840. double scale = Math.Min(dpiWidth / MediaRect.Width, dpiHeight / MediaRect.Height);
  841. scale = Math.Min(scale, 1);
  842. int cropWidth = (int)(scale * pageSize.Width);
  843. int cropHeight = (int)(scale * pageSize.Height);
  844. byte[] imageDatas = RenderPDFPageToArray(document, pageIndex, new Rect(0, 0, cropWidth, cropHeight), scale, true, true);
  845. WriteableBitmap WirteBitmap = new WriteableBitmap(cropWidth, cropHeight, 96, 96, PixelFormats.Bgra32, null);
  846. WirteBitmap.WritePixels(new Int32Rect(0, 0, cropWidth, cropHeight), imageDatas, WirteBitmap.BackBufferStride, 0);
  847. PreviewImage = WirteBitmap;
  848. }
  849. /// <summary>
  850. /// 链接画框完成时触发事件
  851. /// </summary>
  852. /// <param name="sender"></param>
  853. /// <param name="e"></param>
  854. private void linkAnnotArgs_LinkDrawFinished(object sender, bool e)
  855. {
  856. SetTextBoxEnableOrNot(e, totalPage);
  857. }
  858. private void Loaded(object obj)
  859. {
  860. if (obj is CompositeCommandParameter composite)
  861. {
  862. if (composite.Parameter is LinkAnnotProperty linkAnnotProperty)
  863. {
  864. linkAnnot = linkAnnotProperty;
  865. }
  866. }
  867. }
  868. public bool IsNavigationTarget(NavigationContext navigationContext)
  869. {
  870. return true;
  871. }
  872. public void OnNavigatedFrom(NavigationContext navigationContext)
  873. {
  874. }
  875. public void OnNavigatedTo(NavigationContext navigationContext)
  876. {
  877. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanel);
  878. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  879. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  880. if (propertyPanel != null && pdfViewer != null)
  881. {
  882. pdfViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
  883. pdfViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
  884. AnnotAttribEvent = propertyPanel.AnnotEvent;
  885. AnnotType = propertyPanel.annot.EventType;
  886. document = pdfViewer.Document;
  887. totalPage = pdfViewer.Document.PageCount;
  888. if (viewContentViewModel.IsRightMenuCreateLink)
  889. {
  890. SetTextBoxEnableOrNot(true, totalPage);
  891. }
  892. else
  893. {
  894. SetTextBoxEnableOrNot(false, totalPage);
  895. }
  896. if (AnnotAttribEvent.IsAnnotCreateReset == false)
  897. {
  898. GetAnnotAttribute();
  899. }
  900. if (isLoaded)
  901. {
  902. if (pdfViewer != null && pdfViewer.ToolManager != null && pdfViewer.ToolManager.CurrentAnnotArgs?.EventType == AnnotArgsType.AnnotLink)
  903. {
  904. if (btnGOorBack != null)
  905. {
  906. ChangeBtnGOorBack("GO", btnGOorBack);
  907. }
  908. if (AnnotAttribEvent.IsAnnotCreateReset)
  909. {
  910. LinkAnnotArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
  911. if (LinkAnnotArgs == null)
  912. {
  913. backPageIndex = pdfViewer.CurrentIndex;
  914. }
  915. else
  916. {
  917. LinkAnnotArgs.PageIndex = pdfViewer.CurrentIndex;
  918. }
  919. }
  920. }
  921. }
  922. if (LinkAnnotArgs == null)
  923. {
  924. LinkAnnotArgs = (LinkAnnotArgs)propertyPanel.annot;
  925. }
  926. }
  927. }
  928. /// <summary>
  929. /// 定位目标范围完成时,触发
  930. /// </summary>
  931. /// <param name="sender"></param>
  932. /// <param name="e"></param>
  933. private async void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
  934. {
  935. if (e.NotifyType == CustomNotifyType.LinkAreaLocate)
  936. {
  937. if (e.NotifyData is AreaLocate areaInfo)
  938. {
  939. if (pdfViewer.ToolManager.CurrentAnnotArgs.EventType == AnnotArgsType.AnnotLink && pdfViewer.MouseMode == MouseModes.AnnotCreate)
  940. {
  941. LinkAnnotArgs linkArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
  942. System.Windows.Size pageSize = pdfViewer.Document.GetPageSize(areaInfo.PageIndex);
  943. linkArgs.IsPositionSet = true;
  944. linkArgs.DestIndex = areaInfo.PageIndex;
  945. linkArgs.DestinationPos = new System.Windows.Point(areaInfo.Area.X, pageSize.Height - areaInfo.Area.Y);
  946. LinkAnnotArgs = linkArgs;
  947. LinkAnnotArgs.PageIndex = historyPageIndex;
  948. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
  949. AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
  950. AnnotAttribEvent?.UpdateAnnot();
  951. LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  952. PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
  953. SetImagePreview(areaInfo.PageIndex);
  954. await System.Threading.Tasks.Task.Delay(2);
  955. SelectAnnotation();
  956. pdfViewer.GoToPage(historyPageIndex);
  957. //viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
  958. viewContentViewModel.TipVisible = Visibility.Collapsed;
  959. }
  960. }
  961. }
  962. }
  963. /// <summary>
  964. /// 选择链接后,显示参数
  965. /// </summary>
  966. private void GetAnnotAttribute()
  967. {
  968. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
  969. {
  970. SetLinkType((LINK_TYPE)AnnotAttribEvent.Attribs[AnnotAttrib.LinkType]);
  971. }
  972. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkDestIndx) && !AnnotAttribEvent.IsAnnotCreateReset)
  973. {
  974. SetLinkPageNum((int)AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] + 1);
  975. if (LinkAnnotArgs == null)
  976. {
  977. backPageIndex = pdfViewer.CurrentIndex;
  978. }
  979. else
  980. {
  981. LinkAnnotArgs.PageIndex = pdfViewer.CurrentIndex;
  982. }
  983. }
  984. if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkUri))
  985. {
  986. string linkUrl = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri];
  987. if (!string.IsNullOrEmpty(linkUrl))
  988. {
  989. if (linkUrl.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
  990. {
  991. SetLinkType(LINK_TYPE.URI, true);
  992. if (AnnotAttribEvent.IsAnnotCreateReset)
  993. {
  994. SetLinkEmail("");
  995. }
  996. else
  997. {
  998. SetLinkEmail(linkUrl.ToLower().TrimStart("mailto:".ToCharArray()));
  999. }
  1000. }
  1001. else
  1002. {
  1003. if (AnnotAttribEvent.IsAnnotCreateReset)
  1004. {
  1005. SetLinkUrl("");
  1006. }
  1007. else
  1008. {
  1009. SetLinkUrl(linkUrl);
  1010. }
  1011. }
  1012. }
  1013. }
  1014. }
  1015. private void SetLinkUrl(string url)
  1016. {
  1017. PageWebTextContent = url;
  1018. PageWebTextIsEnabled = true;
  1019. }
  1020. private void SetLinkEmail(string email)
  1021. {
  1022. PageMailTextContent = email;
  1023. PageMailTextIsEnabled = true;
  1024. }
  1025. /// <summary>
  1026. /// 设置页码的数据
  1027. /// </summary>
  1028. /// <param name="pageNum"></param>
  1029. private void SetLinkPageNum(int pageNum)
  1030. {
  1031. if (pageNum > 0 && pageNum <= totalPage)
  1032. {
  1033. PageNumTextContent = pageNum.ToString();
  1034. BtnLocationIsEnabled = true;
  1035. PageNumTextIsEnabled = true;
  1036. ImagePreviewVisibility = Visibility.Visible;
  1037. SetImagePreview(pageNum - 1);
  1038. BtnLocationIsEnabled = true;
  1039. //if (btnGOorBack != null)
  1040. //{
  1041. // ChangeBtnGOorBack("GO", btnGOorBack);
  1042. //}
  1043. }
  1044. }
  1045. /// <summary>
  1046. /// 根据链接类型显示模块
  1047. /// </summary>
  1048. /// <param name="linkType"></param>
  1049. /// <param name="isMail"></param>
  1050. public void SetLinkType(LINK_TYPE linkType, bool isMail = false)
  1051. {
  1052. BtnLinkPageIsChecked = false;
  1053. BtnLinkMailIsChecked = false;
  1054. BtnLinkWebIsChecked = false;
  1055. switch (linkType)
  1056. {
  1057. case LINK_TYPE.GOTO:
  1058. BtnLinkPageIsChecked = true;
  1059. break;
  1060. case LINK_TYPE.URI:
  1061. if (this.isMail || isMail)
  1062. {
  1063. BtnLinkMailIsChecked = true;
  1064. }
  1065. else
  1066. {
  1067. BtnLinkWebIsChecked = true;
  1068. }
  1069. break;
  1070. default:
  1071. BtnLinkPageIsChecked = true;
  1072. break;
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 设置文本框和按钮的属性
  1077. /// </summary>
  1078. /// <param name="enable"></param>
  1079. /// <param name="totalPage"></param>
  1080. private void SetTextBoxEnableOrNot(bool enable, int totalPage)
  1081. {
  1082. this.totalPage = totalPage;
  1083. PageNumTextContent = string.Empty;
  1084. PageWebTextContent = string.Empty;
  1085. PageMailTextContent = string.Empty;
  1086. PageNumTextIsEnabled = enable;
  1087. PageWebTextIsEnabled = enable;
  1088. PageMailTextIsEnabled = enable;
  1089. PageNumPlaceHoldText = PageNumTextIsEnabled ? string.Format($"1-{totalPage}页") : "输入目标页面";
  1090. PageWebPlaceHoldText = PageWebTextIsEnabled ? "https://www.pdfreaderpro.com" : "输入您要跳转的链接";
  1091. PageMailPlaceHoldText = PageMailTextIsEnabled ? "support@pdfreaderpro.com" : "输入您要跳转邮件地址";
  1092. ShowPageNumTip = Visibility.Collapsed;
  1093. ShowPageWebTip = Visibility.Collapsed;
  1094. ShowPageMailTip = Visibility.Collapsed;
  1095. BtnLocationIsEnabled = enable;
  1096. }
  1097. /// <summary>
  1098. /// 将PDF的页面转换成数据流
  1099. /// </summary>
  1100. /// <param name="document"></param>
  1101. /// <param name="pageIndex"></param>
  1102. /// <param name="renderRect"></param>
  1103. /// <param name="currentZoom"></param>
  1104. /// <param name="renderAnnot"></param>
  1105. /// <param name="renderForm"></param>
  1106. /// <returns></returns>
  1107. public byte[] RenderPDFPageToArray(CPDFDocument document, int pageIndex, Rect renderRect, double currentZoom, bool renderAnnot = false, bool renderForm = false)
  1108. {
  1109. if (renderRect.Width <= 0 || renderRect.Height <= 0 || document == null)
  1110. {
  1111. return null;
  1112. }
  1113. try
  1114. {
  1115. byte[] bmpData = new byte[(int)renderRect.Width * (int)renderRect.Height * 4];
  1116. currentZoom = currentZoom * 96 / 72;
  1117. int flag = 0;
  1118. if (renderAnnot)
  1119. {
  1120. flag = 1;
  1121. }
  1122. uint bgColor = 0xFFFFFFFF;
  1123. CPDFPage page = document.PageAtIndex(pageIndex);
  1124. if (page.IsValid())
  1125. {
  1126. page.RenderPageBitmapWithMatrix((float)currentZoom, renderRect, bgColor, bmpData, flag, renderForm);
  1127. }
  1128. return bmpData;
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. return null;
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// 获取页面的矩形
  1137. /// </summary>
  1138. /// <param name="document"></param>
  1139. /// <param name="pageIndex"></param>
  1140. /// <param name="displayBox"></param>
  1141. /// <returns></returns>
  1142. private Rect GetPageRect(CPDFDocument document, int pageIndex, CPDFDisplayBox displayBox)
  1143. {
  1144. CPDFPage currentPage = document.PageAtIndex(pageIndex);
  1145. Rect boundBox = currentPage.GetBoundsForBox(displayBox);
  1146. Rect boundRect = new Rect((int)(boundBox.Left / 72.0 * 96.0), (int)(boundBox.Top / 72.0 * 96.0),
  1147. (int)(boundBox.Width / 72.0 * 96.0), (int)(boundBox.Height / 72.0 * 96.0));
  1148. return boundRect;
  1149. }
  1150. /// <summary>
  1151. /// 获取页面的尺寸
  1152. /// </summary>
  1153. /// <param name="document"></param>
  1154. /// <param name="pageIndex"></param>
  1155. /// <returns></returns>
  1156. private System.Windows.Size GetPageSize(CPDFDocument document, int pageIndex)
  1157. {
  1158. System.Windows.Size pageSize = document.GetPageSize(pageIndex);
  1159. pageSize.Width = pageSize.Width / 72.0 * 96;
  1160. pageSize.Height = pageSize.Height / 72.0 * 96;
  1161. return pageSize;
  1162. }
  1163. }
  1164. }