AnnotToolContentViewModel.Function.cs 55 KB

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