AnnotToolContentViewModel.Function.cs 53 KB

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