AnnotToolContentViewModel.Function.cs 48 KB

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