AnnotToolContentViewModel.Function.cs 56 KB

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