AnnotToolContentViewModel.Function.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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. //更改颜色
  950. private void AnnotColorPalette_Menu(object obj)
  951. {
  952. if (obj as CusMenuItem != null)
  953. {
  954. var menu = obj as CusMenuItem;
  955. var annot = menu.Parameter as AnnotHandlerEventArgs;
  956. if (annot != null)
  957. {
  958. var item = new ColorDropBoxPop();
  959. item.DataContext = annot;
  960. item.ColorSelected -= AnnotMenu_ColorSelected;
  961. item.ColorSelected += AnnotMenu_ColorSelected;
  962. System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();
  963. popup.Child = item;
  964. popup.PlacementRectangle = new Rect(Mouse.GetPosition(App.Current.MainWindow), new Size(item.Width, item.Height));
  965. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  966. popup.IsOpen = true;
  967. }
  968. }
  969. }
  970. private void AnnotMenu_ColorSelected(object sender, Color e)
  971. {
  972. if (sender != null)
  973. {
  974. var annot = (sender as FrameworkElement).DataContext as AnnotHandlerEventArgs;
  975. if (annot != null)
  976. {
  977. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  978. {
  979. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  980. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  981. AnnotEvent?.UpdateAnnot();
  982. }
  983. else if (annot is FreeTextAnnotArgs)
  984. {
  985. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  986. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  987. AnnotEvent?.UpdateAnnot();
  988. }
  989. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  990. {
  991. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  992. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  993. AnnotEvent?.UpdateAnnot();
  994. }
  995. }
  996. }
  997. }
  998. //添加笔记
  999. private void AnnotAddNoteText_Menu(object obj)
  1000. {
  1001. if (obj as CusMenuItem != null)
  1002. {
  1003. var menu = obj as CusMenuItem;
  1004. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1005. if (annot != null)
  1006. {
  1007. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1008. args.ClientRect = annot.ClientRect;
  1009. args.AnnotHandlerEventArgs = annot;
  1010. args.PageIndex = annot.PageIndex;
  1011. args.AnnotIndex = annot.AnnotIndex;
  1012. args.EventType = annot.EventType;
  1013. args.CreateTime = annot.CreateTime;
  1014. args.UpdateTime = annot.UpdateTime;
  1015. args.Content = annot.Content;
  1016. args.MarkupContent = annot.MarkupContent;
  1017. args.Author = annot.Author;
  1018. args.Locked = annot.Locked;
  1019. args.ReadOnly = annot.ReadOnly;
  1020. args.FormField = annot.FormField;
  1021. args.Document = PDFViewer.Document;
  1022. DialogParameters value = new DialogParameters();
  1023. value.Add(ParameterNames.Annotation, args);
  1024. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1025. {
  1026. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1027. {
  1028. PDFViewer.UndoManager.CanSave = true;
  1029. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1030. {
  1031. }
  1032. }
  1033. });
  1034. }
  1035. }
  1036. }
  1037. //手绘
  1038. private void FreeHandLineStyle_Menu(object obj)
  1039. {
  1040. if (obj as CusMenuItem != null)
  1041. {
  1042. var menu = obj as CusMenuItem;
  1043. var annot = menu.Parameter as FreehandAnnotArgs;
  1044. if (annot != null)
  1045. {
  1046. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1047. if (menu.tag.ToString() == "Solid")
  1048. {
  1049. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  1050. }
  1051. else
  1052. {
  1053. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  1054. }
  1055. AnnotEvent?.UpdateAnnot();
  1056. }
  1057. }
  1058. }
  1059. //文本
  1060. private void FreeTextFontFamily_Menu(object obj)
  1061. {
  1062. if (obj as CusMenuItem != null)
  1063. {
  1064. var menu = obj as CusMenuItem;
  1065. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1066. if (annot != null)
  1067. {
  1068. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1069. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1070. AnnotEvent?.UpdateAnnot();
  1071. }
  1072. }
  1073. }
  1074. private void FreeTextAglin_Menu(object obj)
  1075. {
  1076. if (obj as CusMenuItem != null)
  1077. {
  1078. var menu = obj as CusMenuItem;
  1079. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1080. var tag = menu.control.Tag;
  1081. if (annot != null && tag != null)
  1082. {
  1083. var strTag = tag.ToString();
  1084. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1085. if (strTag == "Left")
  1086. {
  1087. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1088. }
  1089. else if (strTag == "Center")
  1090. {
  1091. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1092. }
  1093. else if (strTag == "Right")
  1094. {
  1095. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1096. }
  1097. AnnotEvent?.UpdateAnnot();
  1098. }
  1099. }
  1100. }
  1101. //便签
  1102. private void StrikeNoteEditStrike_Menu(object obj)
  1103. {
  1104. if (obj as CusMenuItem != null)
  1105. {
  1106. var menu = obj as CusMenuItem;
  1107. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1108. if (annot != null)
  1109. {
  1110. List<AnnotHandlerEventArgs> list = new List<AnnotHandlerEventArgs>();
  1111. list.Add(annot);
  1112. GetStickyNote(list);
  1113. annot.Author = Settings.Default.AppProperties.Description.Author;
  1114. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1115. PDFViewer.SetToolParam(annot);
  1116. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1117. //isRightMenuAddAnnot = false;
  1118. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1119. }
  1120. }
  1121. }
  1122. //形状
  1123. private void ShapeLineStyle_Menu(object obj)
  1124. {
  1125. if (obj as CusMenuItem != null)
  1126. {
  1127. var menu = obj as CusMenuItem;
  1128. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1129. var tag = menu.control.Tag;
  1130. if (annot != null && tag != null)
  1131. {
  1132. var strTag = tag.ToString();
  1133. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1134. if (strTag == "Solid")
  1135. {
  1136. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1137. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1138. }
  1139. else
  1140. {
  1141. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1142. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1143. }
  1144. AnnotEvent?.UpdateAnnot();
  1145. }
  1146. }
  1147. }
  1148. private void ShapeLineDirect_Menu(object obj)
  1149. {
  1150. if (obj as CusMenuItem != null)
  1151. {
  1152. var menu = obj as CusMenuItem;
  1153. var annot = menu.Parameter as LineAnnotArgs;
  1154. var tag = menu.control.Tag;
  1155. if (annot != null && tag != null)
  1156. {
  1157. var strTag = tag.ToString();
  1158. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1159. if (strTag == "ver")
  1160. {
  1161. annot.SetLineVertical();
  1162. }
  1163. else
  1164. {
  1165. annot.SetLineHorizontal();
  1166. }
  1167. }
  1168. }
  1169. }
  1170. //图章
  1171. private void StampExportPicture_Menu(object obj)
  1172. {
  1173. if (obj as CusMenuItem != null)
  1174. {
  1175. var menu = obj as CusMenuItem;
  1176. var annot = menu.Parameter as StampAnnotArgs;
  1177. if (annot != null)
  1178. {
  1179. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1180. var format = menu.tag.ToString();
  1181. if (format == "PDF")
  1182. dlg.Filter = "PDF|*.pdf";
  1183. else
  1184. dlg.Filter = format + "|*." + format.ToLower();
  1185. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1186. dlg.FileName = PDFViewer.Document.FileName;
  1187. if (dlg.ShowDialog() == true)
  1188. {
  1189. var stampPicture = dlg.FileName;
  1190. if (menu.tag.ToString() == "PDF")
  1191. {
  1192. var writeStamp = annot.GetStampDrawing();
  1193. var tempDoc = new CPDFViewer();
  1194. tempDoc.CreateDocument();
  1195. if (tempDoc.Document == null)
  1196. {
  1197. AlertsMessage alertsMessage = new AlertsMessage();
  1198. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1199. return;
  1200. }
  1201. byte[] buffer;
  1202. var encoder = new PngBitmapEncoder();
  1203. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1204. using (var memoryStream = new MemoryStream())
  1205. {
  1206. encoder.Save(memoryStream);
  1207. buffer = memoryStream.ToArray();
  1208. }
  1209. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1210. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1211. if (result)
  1212. {
  1213. }
  1214. }
  1215. else
  1216. {
  1217. var writeStamp = annot.GetStampDrawing();
  1218. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1219. {
  1220. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1221. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1222. encoder5.Save(stream5);
  1223. }
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. #endregion 注释右键菜单事件
  1230. #endregion 菜单
  1231. }
  1232. }