AnnotToolContentViewModel.Function.cs 50 KB

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