AnnotToolContentViewModel.Function.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Office.Core;
  7. using Microsoft.Win32;
  8. using PDF_Office.CustomControl;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Model;
  11. using PDF_Office.Model.BOTA;
  12. using PDF_Office.Properties;
  13. using PDF_Office.ViewModels.BOTA;
  14. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  15. using PDF_Office.Views.BOTA;
  16. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  17. using PDFSettings;
  18. using Prism.Mvvm;
  19. using Prism.Regions;
  20. using Prism.Services.Dialogs;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.IO;
  24. using System.Linq;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. using System.Windows;
  28. using System.Windows.Controls;
  29. using System.Windows.Forms;
  30. using System.Windows.Input;
  31. using System.Windows.Media;
  32. using System.Windows.Media.Imaging;
  33. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  34. using ContextMenu = System.Windows.Controls.ContextMenu;
  35. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  36. using MenuItem = System.Windows.Controls.MenuItem;
  37. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  38. namespace PDF_Office.ViewModels.Tools
  39. {
  40. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  41. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  42. {
  43. #region 初始化
  44. #region 初始化数据
  45. //初始化注释的属性值,并存在本地缓存数据集里
  46. private void InitDefaultValue()
  47. {
  48. InitAnnotHighlight();
  49. InitAnnotUnderline();
  50. InitAnnotSquiggly();
  51. InitAnnotStrikeout();
  52. }
  53. private void InitAnnotHighlight()
  54. {
  55. var annotate = Settings.Default.AppProperties.Annotate;
  56. if(annotate != null)
  57. {
  58. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  59. HighLightOpacity = 1;
  60. }
  61. else
  62. {
  63. HighLightColor = new SolidColorBrush(Colors.Red);
  64. HighLightOpacity = 1;
  65. }
  66. }
  67. private void InitAnnotUnderline()
  68. {
  69. var annotate = Settings.Default.AppProperties.Annotate;
  70. if (annotate != null)
  71. {
  72. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  73. HighLightOpacity = 1;
  74. }
  75. else
  76. {
  77. UnderLineColor = new SolidColorBrush(Colors.Red);
  78. UnderLineOpacity = 1;
  79. }
  80. }
  81. private void InitAnnotSquiggly()
  82. {
  83. var annotate = Settings.Default.AppProperties.Annotate;
  84. if (annotate != null)
  85. {
  86. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  87. SquigglyOpacity = 1;
  88. }
  89. else
  90. {
  91. SquigglyColor = new SolidColorBrush(Colors.Red);
  92. SquigglyOpacity = 1;
  93. }
  94. }
  95. private void InitAnnotStrikeout()
  96. {
  97. var annotate = Settings.Default.AppProperties.Annotate;
  98. if (annotate != null)
  99. {
  100. StrikeoutColor = new SolidColorBrush(annotate.NoteAnnoteColor);
  101. StrikeoutOpacity = 1;
  102. }
  103. else
  104. {
  105. StrikeoutColor = new SolidColorBrush(Colors.Red);
  106. StrikeoutOpacity = 1;
  107. }
  108. }
  109. //用来记录选中和创建注释的标识
  110. private void InitToolDict()
  111. {
  112. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  113. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  114. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  115. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  116. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  117. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  118. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  119. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  120. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  121. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  122. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  123. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  124. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  125. }
  126. #endregion 初始化数据
  127. #endregion 初始化
  128. #region 注释工具
  129. //注释工具
  130. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  131. {
  132. switch (tag)
  133. {
  134. case "SnapshotEdit"://内容选择
  135. annotArgs = GetSnapshotEdit();
  136. break;
  137. case "HighLight"://字体高亮
  138. annotArgs = GetHighLight();
  139. break;
  140. case "UnderLine"://下划线
  141. annotArgs = GetUnderLine();
  142. break;
  143. case "Squiggly"://波浪线
  144. annotArgs = GetSquiggly();
  145. break;
  146. case "Strikeout"://删除线
  147. annotArgs = GetStrikeout();
  148. break;
  149. case "Freehand"://手绘
  150. annotArgs = GetFreehand();
  151. break;
  152. case "Freetext"://文本
  153. annotArgs = GetFreetext();
  154. break;
  155. case "StickyNote"://便签
  156. annotArgs = GetStickyNote();
  157. break;
  158. case "Rect"://矩形
  159. annotArgs = GetRect();
  160. break;
  161. case "Circle"://圆
  162. annotArgs = GetCircle();
  163. break;
  164. case "Arrow"://箭头
  165. case "Line"://线
  166. annotArgs = GetArrowLine(tag);
  167. break;
  168. case "Stamp"://图章
  169. annotArgs = GetStamp();
  170. break;
  171. case "Image":
  172. annotArgs = GetImage();
  173. break;
  174. case "Signature"://签名
  175. annotArgs = GetSignature();
  176. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  177. break;
  178. case "Link"://链接
  179. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  180. annotArgs = GetLink();
  181. break;
  182. }
  183. }
  184. /// <summary>
  185. /// 高亮注释
  186. /// </summary>
  187. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  188. {
  189. TextHighlightAnnotArgs highlightArgs = null;
  190. if (selectedArgs == null || selectedArgs.Count == 0)
  191. {
  192. highlightArgs = new TextHighlightAnnotArgs();
  193. highlightArgs.Transparency = highLightOpacity;
  194. highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
  195. if (highlightArgs != null)
  196. {
  197. selectedArgs = new List<AnnotHandlerEventArgs>();
  198. selectedArgs.Add(highlightArgs);
  199. }
  200. }
  201. else
  202. {
  203. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  204. }
  205. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
  206. return highlightArgs;
  207. }
  208. /// <summary>
  209. /// 链接
  210. /// </summary>
  211. /// <param name="selectedArgs">所选中的注释</param>
  212. /// <param name="annotAttribEvent">注释属性列表</param>
  213. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  214. {
  215. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  216. if (selectedArgs != null && selectedArgs.Count > 1)
  217. {
  218. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  219. }
  220. else
  221. {
  222. linkArgs.URI = string.Empty;
  223. linkArgs.LinkType = LINK_TYPE.GOTO;
  224. linkArgs.DestIndex = -1;
  225. if (linkArgs != null)
  226. {
  227. selectedArgs = new List<AnnotHandlerEventArgs>();
  228. selectedArgs.Add(linkArgs);
  229. }
  230. }
  231. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  232. return linkArgs;
  233. }
  234. /// <summary>
  235. /// 下划线
  236. /// </summary>
  237. /// <param name="selectedArgs"></param>
  238. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  239. {
  240. TextUnderlineAnnotArgs underlineArgs = null;
  241. if (selectedArgs == null || selectedArgs.Count == 0)
  242. {
  243. underlineArgs = new TextUnderlineAnnotArgs();
  244. underlineArgs.Transparency = UnderLineOpacity;
  245. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  246. if (underlineArgs != null)
  247. {
  248. selectedArgs = new List<AnnotHandlerEventArgs>();
  249. selectedArgs.Add(underlineArgs);
  250. }
  251. }
  252. else
  253. {
  254. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  255. }
  256. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  257. return underlineArgs;
  258. }
  259. /// <summary>
  260. /// 波浪线
  261. /// </summary>
  262. /// <param name="selectedArgs"></param>
  263. /// <returns></returns>
  264. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  265. {
  266. TextSquigglyAnnotArgs squigglyArgs = null;
  267. if (selectedArgs == null || selectedArgs.Count == 0)
  268. {
  269. squigglyArgs = new TextSquigglyAnnotArgs();
  270. squigglyArgs.Transparency = SquigglyOpacity;
  271. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  272. if (squigglyArgs != null)
  273. {
  274. selectedArgs = new List<AnnotHandlerEventArgs>();
  275. selectedArgs.Add(squigglyArgs);
  276. }
  277. }
  278. else
  279. {
  280. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  281. }
  282. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  283. return squigglyArgs;
  284. }
  285. /// <summary>
  286. /// 删除线
  287. /// </summary>
  288. /// <param name="selectedArgs"></param>
  289. /// <returns></returns>
  290. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  291. {
  292. TextStrikeoutAnnotArgs strikeoutArgs = null;
  293. if (selectedArgs == null || selectedArgs.Count == 0)
  294. {
  295. strikeoutArgs = new TextStrikeoutAnnotArgs();
  296. strikeoutArgs.Transparency = strikeoutOpacity;
  297. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  298. if (strikeoutArgs != null)
  299. {
  300. selectedArgs = new List<AnnotHandlerEventArgs>();
  301. selectedArgs.Add(strikeoutArgs);
  302. }
  303. }
  304. else
  305. {
  306. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  307. }
  308. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  309. return strikeoutArgs;
  310. }
  311. /// <summary>
  312. /// 手绘
  313. /// </summary>
  314. /// <param name="selectedArgs"></param>
  315. /// <returns></returns>
  316. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  317. {
  318. FreehandAnnotArgs freehandArgs = null;
  319. if (selectedArgs == null || selectedArgs.Count == 0)
  320. {
  321. freehandArgs = new FreehandAnnotArgs();
  322. var annotate = Settings.Default.AppProperties.Annotate;
  323. if(annotate != null)
  324. {
  325. freehandArgs.InkColor = annotate.FreeHandColor;
  326. }
  327. else
  328. {
  329. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  330. }
  331. freehandArgs.Transparency = 1;
  332. freehandArgs.LineWidth = 2;
  333. if (freehandArgs != null)
  334. {
  335. selectedArgs = new List<AnnotHandlerEventArgs>();
  336. selectedArgs.Add(freehandArgs);
  337. }
  338. }
  339. else
  340. {
  341. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  342. }
  343. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  344. return freehandArgs;
  345. }
  346. /// <summary>
  347. /// 文本
  348. /// </summary>
  349. /// <param name="selectedArgs"></param>
  350. /// <returns></returns>
  351. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  352. {
  353. FreeTextAnnotArgs freetextArgs = null;
  354. TextAlignment textAlignment;
  355. if (selectedArgs == null || selectedArgs.Count == 0)
  356. {
  357. freetextArgs = new FreeTextAnnotArgs();
  358. var annotate = Settings.Default.AppProperties.Annotate;
  359. if (annotate != null)
  360. {
  361. freetextArgs.FontColor = annotate.TextAnnoteColor;
  362. }
  363. else
  364. {
  365. freetextArgs.FontColor = Colors.Black;
  366. }
  367. freetextArgs.Align = TextAlignment.Left;
  368. freetextArgs.BgColor = Colors.Transparent;
  369. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  370. freetextArgs.FontColor = Colors.Black;
  371. freetextArgs.FontSize = 14;
  372. freetextArgs.Transparency = 1;
  373. freetextArgs.LineColor = Colors.Black;
  374. freetextArgs.LineWidth = 0;
  375. freetextArgs.TextContent = string.Empty;
  376. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  377. if (align == 0)
  378. textAlignment = TextAlignment.Left;
  379. else if (align == 1)
  380. textAlignment = TextAlignment.Center;
  381. else
  382. textAlignment = TextAlignment.Right;
  383. if (freetextArgs != null)
  384. {
  385. selectedArgs = new List<AnnotHandlerEventArgs>();
  386. selectedArgs.Add(freetextArgs);
  387. }
  388. }
  389. else
  390. {
  391. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  392. textAlignment = freetextArgs.Align;
  393. }
  394. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  395. return freetextArgs;
  396. }
  397. /// <summary>
  398. /// 便签
  399. /// </summary>
  400. /// <param name="selectedArgs"></param>
  401. /// <returns></returns>
  402. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  403. {
  404. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  405. if (selectedArgs == null || selectedArgs.Count == 0)
  406. {
  407. var annotate = Settings.Default.AppProperties.Annotate;
  408. if (annotate != null)
  409. {
  410. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  411. }
  412. else
  413. {
  414. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  415. }
  416. stickyAnnotArgs.StickyNote = string.Empty;
  417. stickyAnnotArgs.Transparency = 1;
  418. if (stickyAnnotArgs != null)
  419. {
  420. selectedArgs = new List<AnnotHandlerEventArgs>();
  421. selectedArgs.Add(stickyAnnotArgs);
  422. }
  423. }
  424. else
  425. {
  426. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  427. }
  428. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  429. if (stickyAnnotArgs != null)
  430. stickyAnnotArgsList.Add(stickyAnnotArgs);
  431. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  432. return stickyAnnotArgs;
  433. }
  434. /// <summary>
  435. /// 矩形
  436. /// </summary>
  437. /// <param name="selectedArgs"></param>
  438. /// <returns></returns>
  439. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  440. {
  441. SquareAnnotArgs squareArgs = null;
  442. if (selectedArgs == null || selectedArgs.Count == 0)
  443. {
  444. squareArgs = new SquareAnnotArgs();
  445. var annotate = Settings.Default.AppProperties.Annotate;
  446. if (annotate != null)
  447. {
  448. squareArgs.BgColor = annotate.RectangleFillColor;
  449. squareArgs.LineColor = annotate.RectangleBorderColor;
  450. }
  451. else
  452. {
  453. squareArgs.LineColor = Colors.Red;
  454. squareArgs.BgColor = Colors.Red;
  455. }
  456. squareArgs.LineWidth = 1;
  457. squareArgs.Transparency = 1;
  458. squareArgs.LineDash = DashStyles.Solid;
  459. squareArgs.Content = string.Empty;
  460. if (squareArgs != null)
  461. {
  462. selectedArgs = new List<AnnotHandlerEventArgs>();
  463. selectedArgs.Add(squareArgs);
  464. }
  465. }
  466. else
  467. {
  468. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  469. }
  470. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  471. return squareArgs;
  472. }
  473. /// <summary>
  474. /// 圆
  475. /// </summary>
  476. /// <param name="selectedArgs"></param>
  477. /// <returns></returns>
  478. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  479. {
  480. CircleAnnotArgs circleAnnotArgs = null;
  481. if (selectedArgs == null || selectedArgs.Count == 0)
  482. {
  483. circleAnnotArgs = new CircleAnnotArgs();
  484. var annotate = Settings.Default.AppProperties.Annotate;
  485. if (annotate != null)
  486. {
  487. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  488. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  489. }
  490. else
  491. {
  492. circleAnnotArgs.LineColor = Colors.Red;
  493. circleAnnotArgs.BgColor = Colors.Red;
  494. }
  495. circleAnnotArgs.LineWidth = 1;
  496. circleAnnotArgs.Transparency = 1;
  497. circleAnnotArgs.LineDash = DashStyles.Solid;
  498. circleAnnotArgs.Content = string.Empty;
  499. if (circleAnnotArgs != null)
  500. {
  501. selectedArgs = new List<AnnotHandlerEventArgs>();
  502. selectedArgs.Add(circleAnnotArgs);
  503. }
  504. }
  505. else
  506. {
  507. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  508. }
  509. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  510. return circleAnnotArgs;
  511. }
  512. /// <summary>
  513. /// 箭头 线
  514. /// </summary>
  515. /// <param name="TagStr"></param>
  516. /// <param name="selectedArgs"></param>
  517. /// <returns></returns>
  518. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  519. {
  520. LineAnnotArgs lineArgs = new LineAnnotArgs();
  521. if (selectedArgs == null || selectedArgs.Count == 0)
  522. {
  523. var annotate = Settings.Default.AppProperties.Annotate;
  524. if (annotate != null)
  525. {
  526. lineArgs.LineColor = annotate.LineColor;
  527. }
  528. else
  529. {
  530. lineArgs.LineColor = Colors.Red;
  531. }
  532. lineArgs.LineColor = Colors.Red;
  533. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  534. if (TagStr == "Line")
  535. {
  536. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  537. }
  538. else
  539. {
  540. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  541. }
  542. lineArgs.LineDash = DashStyles.Solid;
  543. lineArgs.LineWidth = 1;
  544. lineArgs.Transparency = 1;
  545. lineArgs.Content = string.Empty;
  546. if (lineArgs != null)
  547. {
  548. selectedArgs = new List<AnnotHandlerEventArgs>();
  549. selectedArgs.Add(lineArgs);
  550. }
  551. }
  552. else
  553. {
  554. lineArgs = selectedArgs[0] as LineAnnotArgs;
  555. }
  556. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  557. return lineArgs;
  558. }
  559. /// <summary>
  560. /// 图章
  561. /// </summary>
  562. /// <returns></returns>
  563. private AnnotHandlerEventArgs GetStamp()
  564. {
  565. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  566. stampAnnotArgs.Opacity = 1;
  567. stampAnnotArgs.StampText = "APPROVED";
  568. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  569. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  570. if (stampAnnotArgs != null)
  571. stampAnnotArgsList.Add(stampAnnotArgs);
  572. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  573. return stampAnnotArgs;
  574. }
  575. /// <summary>
  576. /// 签名
  577. /// </summary>
  578. /// <returns></returns>
  579. private AnnotHandlerEventArgs GetSignature()
  580. {
  581. AddToPropertyPanel("SignatureAnnotProperty");
  582. return null;
  583. }
  584. private AnnotHandlerEventArgs GetImage()
  585. {
  586. StampAnnotArgs stampArgs = new StampAnnotArgs();
  587. stampArgs.Opacity = 1;
  588. stampArgs.Type = StampType.IMAGE_STAMP;
  589. OpenFileDialog openFileDialog = new OpenFileDialog();
  590. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  591. if (openFileDialog.ShowDialog() == true)
  592. {
  593. stampArgs.ImagePath = openFileDialog.FileName;
  594. }
  595. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  596. if (stampArgs != null)
  597. stampArgsList.Add(stampArgs);
  598. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  599. return stampArgs;
  600. }
  601. /// <summary>
  602. /// 内容选择
  603. /// </summary>
  604. /// <param name="annotBtn"></param>
  605. /// <returns></returns>
  606. private AnnotHandlerEventArgs GetSnapshotEdit()
  607. {
  608. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  609. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  610. snapshotArgs.ControlPointColor = Colors.White;
  611. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  612. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  613. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  614. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  615. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  616. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  617. #region to do
  618. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  619. //snapshotArgs.ToolPanel = snapMenu;
  620. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  621. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  622. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  623. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  624. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  625. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  626. #endregion to do
  627. return snapshotArgs;
  628. }
  629. #endregion 注释工具
  630. #region 菜单
  631. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  632. {
  633. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  634. {
  635. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  636. switch (clickMenu.Tag.ToString())
  637. {
  638. case "HighLight"://字体高亮
  639. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  640. highlightArgs.ClientRect = annotCommand.TextRect;
  641. highlightArgs.Content = annotCommand.Text;
  642. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  643. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  644. PDFViewer.SetToolParam(highlightArgs);
  645. PDFViewer.SetMouseMode(MouseModes.PanTool);
  646. break;
  647. case "UnderLine"://下划线
  648. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  649. underlineArgs.ClientRect = annotCommand.TextRect;
  650. underlineArgs.Content = annotCommand.Text;
  651. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  652. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  653. PDFViewer.SetToolParam(underlineArgs);
  654. PDFViewer.SetMouseMode(MouseModes.PanTool);
  655. break;
  656. case "Strikeout"://删除线
  657. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  658. strikeoutArgs.ClientRect = annotCommand.TextRect;
  659. strikeoutArgs.Content = annotCommand.Text;
  660. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  661. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  662. PDFViewer.SetToolParam(strikeoutArgs);
  663. PDFViewer.SetMouseMode(MouseModes.PanTool);
  664. break;
  665. case "Freetext"://文本
  666. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  667. textArgs.ClientRect = annotCommand.TextRect;
  668. //textArgs.Transparency = 1;
  669. //textArgs.BgColor = Colors.Transparent;
  670. //textArgs.LineColor = Colors.Red;
  671. //textArgs.LineWidth = 2;
  672. textArgs.TextContent = annotCommand.Text;
  673. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  674. break;
  675. case "StickyNote"://便签
  676. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  677. stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  678. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  679. break;
  680. case "Rect"://矩形
  681. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  682. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  683. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  684. break;
  685. case "Circle"://圆
  686. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  687. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  688. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  689. break;
  690. case "Line"://线
  691. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  692. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  693. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  694. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  695. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  696. break;
  697. case "Link"://链接
  698. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  699. linkArgs.ClientRect = annotCommand.TextRect;
  700. linkArgs.URI = string.Empty;
  701. linkArgs.LinkType = LINK_TYPE.GOTO;
  702. linkArgs.DestIndex = annotCommand.PageIndex;
  703. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  704. BtnLinkIsChecked = true;
  705. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  706. lists.Add(linkArgs);
  707. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  708. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  709. PDFViewer.SetToolParam(annotArgs);
  710. viewContentViewModel.IsPropertyOpen = true;
  711. break;
  712. case "OutLine":
  713. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  714. if (isTabItemAnnotation == false)
  715. {
  716. bOTAContent.TabItemOutLine.IsSelected = true;
  717. }
  718. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  719. if (outLineControlViewModel != null && outLineControl != null)
  720. {
  721. string str = null;
  722. if (string.IsNullOrEmpty(annotCommand.Text))
  723. {
  724. str = (annotCommand.PageIndex + 1).ToString();
  725. }
  726. else
  727. {
  728. str = annotCommand.Text;
  729. }
  730. OutlineNode outline = outLineControl.AddOutlineNode(str);
  731. CPDFOutline result = outline.Outline;
  732. if (result != null)
  733. {
  734. outLineControlViewModel.SetTitle(result, str);
  735. outLineControlViewModel.Updata(false);
  736. //outLineControl.IsReName = true;
  737. //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
  738. //{
  739. // outLineControl.ReNameOutlineNode = outline;
  740. //}
  741. }
  742. }
  743. break;
  744. case "ExportPicture":
  745. ExportPicture_MenuItemClick();
  746. break;
  747. }
  748. //ShowPropertyPanel(false);
  749. }
  750. }
  751. private void ExportPicture_MenuItemClick()
  752. {
  753. //图片提取
  754. try
  755. {
  756. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  757. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  758. foreach (int pageIndex in imageDict.Keys)
  759. {
  760. imageList = imageDict[pageIndex];
  761. }
  762. string path = PDFViewer.Document.FileName;
  763. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  764. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  765. {
  766. int i = 1;
  767. int pagenum = 1;
  768. string choosePath = folderDialog.SelectedPath;
  769. string sPath = choosePath + "\\" + path + "_Extract Image";
  770. sPath = GetExportPathName(sPath);
  771. if (!Directory.Exists(sPath))
  772. {
  773. Directory.CreateDirectory(sPath);
  774. }
  775. if (Directory.Exists(sPath))
  776. {
  777. foreach (System.Drawing.Bitmap image in imageList)
  778. {
  779. foreach (var item in imageDict.Keys)
  780. {
  781. pagenum = item;
  782. }
  783. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  784. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  785. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  786. i++;
  787. }
  788. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  789. }
  790. }
  791. }
  792. catch (Exception ex) { }
  793. }
  794. public string GetExportPathName(string path)
  795. {
  796. int i = 1;
  797. string outpath = path;
  798. while (Directory.Exists(outpath))
  799. {
  800. outpath = path + $"({i.ToString()})";
  801. i++;
  802. }
  803. return outpath;
  804. }
  805. private string GetNum(int num)
  806. {
  807. if (num % 10 < 1)
  808. {
  809. return "00" + num.ToString();
  810. }
  811. if (num % 10 >= 1 && num % 10 < 10)
  812. {
  813. return "0" + num.ToString();
  814. }
  815. else
  816. {
  817. return num.ToString();
  818. }
  819. }
  820. #region 注释右键菜单事件
  821. //高亮、下划线、删除
  822. private void HightAnnotCopyText_Menu(object obj)
  823. {
  824. if (obj as CusMenuItem != null)
  825. {
  826. var menu = obj as CusMenuItem;
  827. var annot = menu.Parameter as AnnotHandlerEventArgs;
  828. if(annot != null)
  829. {
  830. System.Windows.Clipboard.SetText(annot.Content);
  831. }
  832. }
  833. }
  834. //更改为当前注释属性默认值
  835. private void AnnotDefaultValues_Menu(object obj)
  836. {
  837. if (obj as CusMenuItem != null)
  838. {
  839. var menu = obj as CusMenuItem;
  840. var annot = menu.Parameter as AnnotHandlerEventArgs;
  841. if (annot != null)
  842. {
  843. if (annot is TextHighlightAnnotArgs)
  844. {
  845. var color = (annot as TextHighlightAnnotArgs).Color;
  846. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  847. HighLightColor = new SolidColorBrush(color);
  848. }
  849. else if (annot is TextUnderlineAnnotArgs)
  850. {
  851. var color = (annot as TextHighlightAnnotArgs).Color;
  852. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  853. UnderLineColor = new SolidColorBrush(color);
  854. }
  855. else if (annot is TextStrikeoutAnnotArgs)
  856. {
  857. var color = (annot as TextHighlightAnnotArgs).Color;
  858. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  859. StrikeoutColor = new SolidColorBrush(color);
  860. }
  861. else if (annot is FreehandAnnotArgs)
  862. {
  863. var color = (annot as FreehandAnnotArgs).InkColor;
  864. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  865. }
  866. else if (annot is FreeTextAnnotArgs)
  867. {
  868. var freeText = annot as FreeTextAnnotArgs;
  869. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  870. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  871. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  872. }
  873. else if (annot is StickyAnnotArgs)
  874. {
  875. var color = (annot as StickyAnnotArgs).Color;
  876. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  877. }
  878. else if (annot is SquareAnnotArgs)
  879. {
  880. var bgColor = (annot as SquareAnnotArgs).BgColor;
  881. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  882. var borderColor = (annot as SquareAnnotArgs).LineColor;
  883. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  884. }
  885. else if (annot is CircleAnnotArgs)
  886. {
  887. var bgColor = (annot as CircleAnnotArgs).BgColor;
  888. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  889. var borderColor = (annot as CircleAnnotArgs).LineColor;
  890. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  891. }
  892. else if (annot is LineAnnotArgs)
  893. {
  894. var color = (annot as LineAnnotArgs).LineColor;
  895. Settings.Default.AppProperties.Annotate.LineColor = color;
  896. }
  897. Settings.Default.Save();
  898. }
  899. }
  900. }
  901. //更改颜色
  902. private void AnnotColorPalette_Menu(object obj)
  903. {
  904. if (obj as CusMenuItem != null)
  905. {
  906. var menu = obj as CusMenuItem;
  907. var annot = menu.Parameter as AnnotHandlerEventArgs;
  908. if (annot != null)
  909. {
  910. var item = new ColorDropBoxPop();
  911. item.DataContext = annot;
  912. item.ColorSelected -= AnnotMenu_ColorSelected;
  913. item.ColorSelected += AnnotMenu_ColorSelected;
  914. System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();
  915. popup.Child = item;
  916. popup.PlacementRectangle = new Rect(Mouse.GetPosition(App.Current.MainWindow), new Size(item.Width, item.Height));
  917. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  918. popup.IsOpen = true;
  919. }
  920. }
  921. }
  922. private void AnnotMenu_ColorSelected(object sender, Color e)
  923. {
  924. if (sender != null)
  925. {
  926. var annot = (sender as FrameworkElement).DataContext as AnnotHandlerEventArgs;
  927. if (annot != null)
  928. {
  929. if(annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  930. {
  931. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  932. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  933. AnnotEvent?.UpdateAnnot();
  934. }
  935. else if(annot is FreeTextAnnotArgs)
  936. {
  937. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  938. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  939. AnnotEvent?.UpdateAnnot();
  940. }
  941. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  942. {
  943. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  944. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  945. AnnotEvent?.UpdateAnnot();
  946. }
  947. }
  948. }
  949. }
  950. //添加笔记
  951. private void AnnotAddNoteText_Menu(object obj)
  952. {
  953. if (obj as CusMenuItem != null)
  954. {
  955. var menu = obj as CusMenuItem;
  956. var annot = menu.Parameter as AnnotHandlerEventArgs;
  957. if (annot != null)
  958. {
  959. DialogParameters value = new DialogParameters();
  960. value.Add(ParameterNames.Annotation, annot);
  961. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  962. {
  963. if (e.Result == ButtonResult.OK && e.Parameters != null)
  964. {
  965. PDFViewer.UndoManager.CanSave = true;
  966. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  967. {
  968. }
  969. }
  970. });
  971. }
  972. }
  973. }
  974. //手绘
  975. private void FreeHandLineStyle_Menu(object obj)
  976. {
  977. if (obj as CusMenuItem != null)
  978. {
  979. var menu = obj as CusMenuItem;
  980. var annot = menu.Parameter as FreehandAnnotArgs;
  981. if (annot != null)
  982. {
  983. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  984. if(menu.tag.ToString() == "Solid")
  985. {
  986. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  987. }
  988. else
  989. {
  990. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  991. }
  992. AnnotEvent?.UpdateAnnot();
  993. }
  994. }
  995. }
  996. //文本
  997. private void FreeTextFontFamily_Menu(object obj)
  998. {
  999. if (obj as CusMenuItem != null)
  1000. {
  1001. var menu = obj as CusMenuItem;
  1002. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1003. if (annot != null)
  1004. {
  1005. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1006. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1007. AnnotEvent?.UpdateAnnot();
  1008. }
  1009. }
  1010. }
  1011. private void FreeTextAglin_Menu(object obj)
  1012. {
  1013. if (obj as CusMenuItem != null)
  1014. {
  1015. var menu = obj as CusMenuItem;
  1016. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1017. var tag = menu.control.Tag;
  1018. if (annot != null && tag != null)
  1019. {
  1020. var strTag = tag.ToString();
  1021. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1022. if (strTag == "Left")
  1023. {
  1024. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1025. }
  1026. else if (strTag == "Center")
  1027. {
  1028. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1029. }
  1030. else if (strTag == "Right")
  1031. {
  1032. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1033. }
  1034. AnnotEvent?.UpdateAnnot();
  1035. }
  1036. }
  1037. }
  1038. //便签
  1039. private void StrikeNoteEditStrike_Menu(object obj)
  1040. {
  1041. if (obj as CusMenuItem != null)
  1042. {
  1043. var menu = obj as CusMenuItem;
  1044. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1045. if (annot != null)
  1046. {
  1047. List<AnnotHandlerEventArgs> list = new List<AnnotHandlerEventArgs>();
  1048. list.Add(annot);
  1049. GetStickyNote(list);
  1050. annot.Author = Settings.Default.AppProperties.Description.Author;
  1051. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1052. PDFViewer.SetToolParam(annot);
  1053. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1054. //isRightMenuAddAnnot = false;
  1055. #endregion
  1056. }
  1057. }
  1058. }
  1059. //形状
  1060. private void ShapeLineStyle_Menu(object obj)
  1061. {
  1062. if (obj as CusMenuItem != null)
  1063. {
  1064. var menu = obj as CusMenuItem;
  1065. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1066. var tag = menu.control.Tag;
  1067. if (annot != null && tag != null)
  1068. {
  1069. var strTag = tag.ToString();
  1070. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1071. if (strTag == "Solid")
  1072. {
  1073. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1074. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1075. }
  1076. else
  1077. {
  1078. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1079. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1080. }
  1081. AnnotEvent?.UpdateAnnot();
  1082. }
  1083. }
  1084. }
  1085. private void ShapeLineDirect_Menu(object obj)
  1086. {
  1087. if (obj as CusMenuItem != null)
  1088. {
  1089. var menu = obj as CusMenuItem;
  1090. var annot = menu.Parameter as LineAnnotArgs;
  1091. var tag = menu.control.Tag;
  1092. if (annot != null && tag != null)
  1093. {
  1094. var strTag = tag.ToString();
  1095. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1096. if (strTag == "ver")
  1097. {
  1098. annot.SetLineVertical();
  1099. }
  1100. else
  1101. {
  1102. annot.SetLineHorizontal();
  1103. }
  1104. }
  1105. }
  1106. }
  1107. //图章
  1108. private void StampExportPicture_Menu(object obj)
  1109. {
  1110. if (obj as CusMenuItem != null)
  1111. {
  1112. var menu = obj as CusMenuItem;
  1113. var annot = menu.Parameter as StampAnnotArgs;
  1114. if (annot != null)
  1115. {
  1116. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1117. var format = menu.tag.ToString();
  1118. if (format == "PDF")
  1119. dlg.Filter = "PDF|*.pdf";
  1120. else
  1121. dlg.Filter = format + "|*." + format.ToLower();
  1122. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1123. dlg.FileName = PDFViewer.Document.FileName;
  1124. if (dlg.ShowDialog() == true)
  1125. {
  1126. var stampPicture = dlg.FileName;
  1127. if(menu.tag.ToString() == "PDF")
  1128. {
  1129. var writeStamp = annot.GetStampDrawing();
  1130. var tempDoc = new CPDFViewer();
  1131. tempDoc.CreateDocument();
  1132. if (tempDoc.Document == null)
  1133. {
  1134. AlertsMessage alertsMessage = new AlertsMessage();
  1135. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1136. return;
  1137. }
  1138. byte[] buffer;
  1139. var encoder = new PngBitmapEncoder();
  1140. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1141. using (var memoryStream = new MemoryStream())
  1142. {
  1143. encoder.Save(memoryStream);
  1144. buffer = memoryStream.ToArray();
  1145. }
  1146. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1147. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1148. if (result)
  1149. {
  1150. }
  1151. }
  1152. else
  1153. {
  1154. var writeStamp = annot.GetStampDrawing();
  1155. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1156. {
  1157. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1158. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1159. encoder5.Save(stream5);
  1160. }
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. #endregion 注释右键菜单事件
  1167. #endregion 菜单
  1168. }
  1169. }