LinkAnnotPropertyViewModel.cs 48 KB

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