AnnotToolContentViewModel.Function.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. CreateAnnotFromSelectPageText(linkArgs);
  312. }
  313. }
  314. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  315. return linkArgs;
  316. }
  317. /// <summary>
  318. /// 下划线
  319. /// </summary>
  320. /// <param name="selectedArgs"></param>
  321. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  322. {
  323. TextUnderlineAnnotArgs underlineArgs = null;
  324. if (selectedArgs == null || selectedArgs.Count == 0)
  325. {
  326. underlineArgs = new TextUnderlineAnnotArgs();
  327. underlineArgs.Transparency = UnderLineOpacity;
  328. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  329. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotUnderline] == null)
  330. {
  331. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
  332. if (defaultAnnot == null)
  333. {
  334. defaultAnnot = new DefaultAnnotProperty();
  335. defaultAnnot.AnnotToolType = underlineArgs.EventType;
  336. defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
  337. defaultAnnot.Opacity = 1;
  338. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  339. Settings.Default.Save();
  340. }
  341. UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
  342. }
  343. selectedArgs = new List<AnnotHandlerEventArgs>();
  344. selectedArgs.Add(underlineArgs);
  345. }
  346. else
  347. {
  348. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  349. }
  350. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  351. return underlineArgs;
  352. }
  353. /// <summary>
  354. /// 波浪线
  355. /// </summary>
  356. /// <param name="selectedArgs"></param>
  357. /// <returns></returns>
  358. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  359. {
  360. TextSquigglyAnnotArgs squigglyArgs = null;
  361. if (selectedArgs == null || selectedArgs.Count == 0)
  362. {
  363. squigglyArgs = new TextSquigglyAnnotArgs();
  364. squigglyArgs.Transparency = SquigglyOpacity;
  365. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  366. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquiggly] == null)
  367. {
  368. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
  369. if (defaultAnnot == null)
  370. {
  371. defaultAnnot = new DefaultAnnotProperty();
  372. defaultAnnot.AnnotToolType = squigglyArgs.EventType;
  373. defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
  374. defaultAnnot.Opacity = 1;
  375. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  376. Settings.Default.Save();
  377. }
  378. SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
  379. }
  380. selectedArgs = new List<AnnotHandlerEventArgs>();
  381. selectedArgs.Add(squigglyArgs);
  382. }
  383. else
  384. {
  385. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  386. }
  387. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  388. return squigglyArgs;
  389. }
  390. /// <summary>
  391. /// 删除线
  392. /// </summary>
  393. /// <param name="selectedArgs"></param>
  394. /// <returns></returns>
  395. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  396. {
  397. TextStrikeoutAnnotArgs strikeoutArgs = null;
  398. if (selectedArgs == null || selectedArgs.Count == 0)
  399. {
  400. strikeoutArgs = new TextStrikeoutAnnotArgs();
  401. strikeoutArgs.Transparency = strikeoutOpacity;
  402. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  403. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotStrikeout] == null)
  404. {
  405. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
  406. if (defaultAnnot == null)
  407. {
  408. defaultAnnot = new DefaultAnnotProperty();
  409. defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
  410. defaultAnnot.ForgoundColor = (strikeoutColor as SolidColorBrush).Color;
  411. defaultAnnot.Opacity = 1;
  412. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  413. Settings.Default.Save();
  414. }
  415. strikeoutArgs.Transparency = defaultAnnot.Opacity;
  416. }
  417. selectedArgs = new List<AnnotHandlerEventArgs>();
  418. selectedArgs.Add(strikeoutArgs);
  419. }
  420. else
  421. {
  422. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  423. }
  424. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  425. return strikeoutArgs;
  426. }
  427. /// <summary>
  428. /// 手绘
  429. /// </summary>
  430. /// <param name="selectedArgs"></param>
  431. /// <returns></returns>
  432. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  433. {
  434. FreehandAnnotArgs freehandArgs = null;
  435. if (selectedArgs == null || selectedArgs.Count == 0)
  436. {
  437. freehandArgs = new FreehandAnnotArgs();
  438. var annotate = Settings.Default.AppProperties.Annotate;
  439. if (annotate != null)
  440. {
  441. freehandArgs.InkColor = annotate.FreeHandColor;
  442. }
  443. else
  444. {
  445. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  446. }
  447. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] == null)
  448. {
  449. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
  450. if (defaultAnnot == null)
  451. {
  452. defaultAnnot = new DefaultAnnotProperty();
  453. defaultAnnot.AnnotToolType = freehandArgs.EventType;
  454. defaultAnnot.ForgoundColor = annotate.FreeHandColor;
  455. defaultAnnot.Opacity = 1;
  456. defaultAnnot.Thickness = 2;
  457. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  458. Settings.Default.Save();
  459. }
  460. freehandArgs.Transparency = defaultAnnot.Opacity;
  461. freehandArgs.LineWidth = defaultAnnot.Thickness;
  462. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  463. {
  464. freehandArgs.LineDash = DashStyles.Solid;
  465. }
  466. else
  467. {
  468. var collect = new DoubleCollection();
  469. foreach (var item in defaultAnnot.DashArray)
  470. {
  471. collect.Add(item);
  472. }
  473. if (freehandArgs.LineDash == null)
  474. freehandArgs.LineDash = new DashStyle();
  475. freehandArgs.LineDash.Dashes = collect;
  476. }
  477. }
  478. else
  479. {
  480. freehandArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
  481. }
  482. selectedArgs = new List<AnnotHandlerEventArgs>();
  483. selectedArgs.Add(freehandArgs);
  484. }
  485. else
  486. {
  487. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  488. if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
  489. {
  490. return freehandArgs;
  491. }
  492. }
  493. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  494. return freehandArgs;
  495. }
  496. /// <summary>
  497. /// 文本
  498. /// </summary>
  499. /// <param name="selectedArgs"></param>
  500. /// <returns></returns>
  501. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  502. {
  503. FreeTextAnnotArgs freetextArgs = null;
  504. TextAlignment textAlignment;
  505. if (selectedArgs == null || selectedArgs.Count == 0)
  506. {
  507. freetextArgs = new FreeTextAnnotArgs();
  508. var annotate = Settings.Default.AppProperties.Annotate;
  509. if (annotate != null)
  510. {
  511. freetextArgs.FontColor = annotate.TextAnnoteColor;
  512. }
  513. else
  514. {
  515. freetextArgs.FontColor = Colors.Black;
  516. }
  517. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] == null)
  518. {
  519. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  520. if (defaultAnnot == null)
  521. {
  522. defaultAnnot = new DefaultAnnotProperty();
  523. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  524. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  525. defaultAnnot.BorderColor = Colors.Transparent;
  526. defaultAnnot.BackgroundColor = Colors.Transparent;
  527. defaultAnnot.Opacity = 1;
  528. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  529. defaultAnnot.FontSize = 14;
  530. defaultAnnot.TextAlign = TextAlignment.Left;
  531. defaultAnnot.Thickness = 0;
  532. defaultAnnot.NoteText = string.Empty;
  533. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  534. Settings.Default.Save();
  535. }
  536. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  537. freetextArgs.LineColor = defaultAnnot.BorderColor;
  538. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  539. freetextArgs.Transparency = defaultAnnot.Opacity;
  540. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  541. freetextArgs.FontSize = defaultAnnot.FontSize;
  542. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  543. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  544. freetextArgs.LineWidth = defaultAnnot.Thickness;
  545. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  546. if (align == 0)
  547. textAlignment = TextAlignment.Left;
  548. else if (align == 1)
  549. textAlignment = TextAlignment.Center;
  550. else
  551. textAlignment = TextAlignment.Right;
  552. freetextArgs.Align = textAlignment;
  553. }
  554. else
  555. {
  556. freetextArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] as FreeTextAnnotArgs;
  557. freetextArgs.Content = string.Empty;
  558. freetextArgs.TextContent= string.Empty;
  559. }
  560. if (freetextArgs != null)
  561. {
  562. selectedArgs = new List<AnnotHandlerEventArgs>();
  563. selectedArgs.Add(freetextArgs);
  564. SelectTextCreateAnnot(freetextArgs);
  565. }
  566. }
  567. else
  568. {
  569. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  570. textAlignment = freetextArgs.Align;
  571. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  572. {
  573. return freetextArgs;
  574. }
  575. }
  576. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  577. return freetextArgs;
  578. }
  579. private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
  580. {
  581. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  582. if (selectList != null && selectList.Count > 0)
  583. {
  584. foreach (TextSelectNode selectNode in selectList)
  585. {
  586. FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
  587. Rect clientRect = Rect.Empty;
  588. foreach (Rect rawRect in selectNode.RawRect)
  589. {
  590. clientRect.Union(rawRect);
  591. }
  592. if (clientRect.IsEmpty == false)
  593. {
  594. clientRect = new Rect(
  595. clientRect.Left / 72D * 96D,
  596. clientRect.Top / 72D * 96D,
  597. clientRect.Width / 72D * 96D,
  598. clientRect.Height / 72D * 96D);
  599. textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
  600. //textArgs.Transparency = 1;
  601. //textArgs.BgColor = Colors.Transparent;
  602. //textArgs.LineColor = Colors.Red;
  603. //textArgs.LineWidth = 2;
  604. textArgs.Transparency = freeText.Transparency;
  605. textArgs.BgColor = freeText.BgColor;
  606. textArgs.LineColor = freeText.LineColor;
  607. textArgs.LineWidth = freeText.LineWidth;
  608. textArgs.TextContent = selectNode.SelectText;
  609. PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
  610. }
  611. break;
  612. }
  613. }
  614. }
  615. //获取选中文字内容的区域大小,以及内容内容所在的页码
  616. private Tuple<int, Rect> DrawRectCreateAnnot()
  617. {
  618. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  619. Rect clientRect = Rect.Empty;
  620. int pageIndex = -1;
  621. if (selectList != null && selectList.Count > 0)
  622. {
  623. pageIndex = selectList[0].PageIndex;
  624. }
  625. if (selectList != null && selectList.Count > 0)
  626. {
  627. foreach (TextSelectNode selectNode in selectList)
  628. {
  629. foreach (Rect rawRect in selectNode.RawRect)
  630. {
  631. clientRect.Union(rawRect);
  632. }
  633. int dpi = DpiHelpers.Dpi;
  634. if (clientRect.IsEmpty == false)
  635. {
  636. clientRect = new Rect(
  637. clientRect.Left / 72D * dpi,
  638. clientRect.Top / 72D * dpi,
  639. clientRect.Width / 72D * dpi,
  640. clientRect.Height / 72D * dpi);
  641. }
  642. break;
  643. }
  644. }
  645. if (clientRect != Rect.Empty && pageIndex > -1)
  646. {
  647. return new Tuple<int, Rect>(pageIndex, clientRect);
  648. }
  649. return null;
  650. }
  651. //根据选中的文本内容,来创建指定大小的注释。
  652. private void CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
  653. {
  654. //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
  655. var drawRectTuple = DrawRectCreateAnnot();
  656. if (drawRectTuple != null)
  657. {
  658. annotArgs.ClientRect = drawRectTuple.Item2;
  659. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, annotArgs);
  660. }
  661. }
  662. //Event导航到填写与签名的属性面板
  663. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  664. {
  665. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  666. {
  667. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  668. if (annotFillAndSign != null)
  669. {
  670. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  671. return true;
  672. }
  673. }
  674. return false;
  675. }
  676. private void FromFillAndSign(FillAndSigntEventArgs obj)
  677. {
  678. if (obj != null)
  679. {
  680. if (string.IsNullOrEmpty(obj.Action) == false)
  681. {
  682. if (obj.Action == "Clear")
  683. {
  684. viewContentViewModel.AnnotSignatures.Clear();
  685. }
  686. }
  687. }
  688. }
  689. /// <summary>
  690. /// 便签
  691. /// </summary>
  692. /// <param name="selectedArgs"></param>
  693. /// <returns></returns>
  694. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  695. {
  696. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  697. if (selectedArgs == null || selectedArgs.Count == 0)
  698. {
  699. var annotate = Settings.Default.AppProperties.Annotate;
  700. if (annotate != null)
  701. {
  702. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  703. }
  704. else
  705. {
  706. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  707. }
  708. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  709. {
  710. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  711. if (defaultAnnot == null)
  712. {
  713. defaultAnnot = new DefaultAnnotProperty();
  714. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  715. defaultAnnot.NoteText = string.Empty;
  716. defaultAnnot.Opacity = 1;
  717. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  718. Settings.Default.Save();
  719. }
  720. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  721. }
  722. else
  723. {
  724. stickyAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  725. stickyAnnotArgs.Content=string.Empty;
  726. stickyAnnotArgs.StickyNote= string.Empty;
  727. }
  728. if (stickyAnnotArgs != null)
  729. {
  730. selectedArgs = new List<AnnotHandlerEventArgs>();
  731. selectedArgs.Add(stickyAnnotArgs);
  732. }
  733. }
  734. else
  735. {
  736. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  737. }
  738. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  739. if (stickyAnnotArgs != null)
  740. stickyAnnotArgsList.Add(stickyAnnotArgs);
  741. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  742. return stickyAnnotArgs;
  743. }
  744. /// <summary>
  745. /// 矩形
  746. /// </summary>
  747. /// <param name="selectedArgs"></param>
  748. /// <returns></returns>
  749. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  750. {
  751. SquareAnnotArgs squareArgs = null;
  752. if (selectedArgs == null || selectedArgs.Count == 0)
  753. {
  754. squareArgs = new SquareAnnotArgs();
  755. var annotate = Settings.Default.AppProperties.Annotate;
  756. if (annotate != null)
  757. {
  758. squareArgs.BgColor = annotate.RectangleFillColor;
  759. squareArgs.LineColor = annotate.RectangleBorderColor;
  760. }
  761. else
  762. {
  763. squareArgs.LineColor = Colors.Red;
  764. squareArgs.BgColor = Colors.Red;
  765. }
  766. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  767. {
  768. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  769. if (defaultAnnot == null)
  770. {
  771. defaultAnnot = new DefaultAnnotProperty();
  772. defaultAnnot.AnnotToolType = squareArgs.EventType;
  773. defaultAnnot.Thickness = 1;
  774. defaultAnnot.Opacity = 1;
  775. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  776. Settings.Default.Save();
  777. }
  778. squareArgs.LineWidth = defaultAnnot.Thickness;
  779. squareArgs.Transparency = defaultAnnot.Opacity;
  780. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  781. {
  782. squareArgs.LineDash = DashStyles.Solid;
  783. }
  784. else
  785. {
  786. var collect = new DoubleCollection();
  787. foreach (var item in defaultAnnot.DashArray)
  788. {
  789. collect.Add(item);
  790. }
  791. if (squareArgs.LineDash == null)
  792. squareArgs.LineDash = new DashStyle();
  793. squareArgs.LineDash.Dashes = collect;
  794. }
  795. }
  796. else
  797. {
  798. squareArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  799. }
  800. if (squareArgs != null)
  801. {
  802. selectedArgs = new List<AnnotHandlerEventArgs>();
  803. selectedArgs.Add(squareArgs);
  804. CreateAnnotFromSelectPageText(squareArgs);
  805. }
  806. }
  807. else
  808. {
  809. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  810. }
  811. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  812. return squareArgs;
  813. }
  814. /// <summary>
  815. /// 圆
  816. /// </summary>
  817. /// <param name="selectedArgs"></param>
  818. /// <returns></returns>
  819. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  820. {
  821. CircleAnnotArgs circleAnnotArgs = null;
  822. if (selectedArgs == null || selectedArgs.Count == 0)
  823. {
  824. circleAnnotArgs = new CircleAnnotArgs();
  825. var annotate = Settings.Default.AppProperties.Annotate;
  826. if (annotate != null)
  827. {
  828. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  829. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  830. }
  831. else
  832. {
  833. circleAnnotArgs.LineColor = Colors.Red;
  834. circleAnnotArgs.BgColor = Colors.Red;
  835. }
  836. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  837. {
  838. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  839. if (defaultAnnot == null)
  840. {
  841. defaultAnnot = new DefaultAnnotProperty();
  842. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  843. defaultAnnot.Thickness = 1;
  844. defaultAnnot.Opacity = 1;
  845. defaultAnnot.NoteText = string.Empty;
  846. defaultAnnot.DashArray = null;
  847. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  848. Settings.Default.Save();
  849. }
  850. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  851. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  852. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  853. {
  854. circleAnnotArgs.LineDash = DashStyles.Solid;
  855. }
  856. else
  857. {
  858. var collect = new DoubleCollection();
  859. foreach (var item in defaultAnnot.DashArray)
  860. {
  861. collect.Add(item);
  862. }
  863. if (circleAnnotArgs.LineDash == null)
  864. circleAnnotArgs.LineDash = new DashStyle();
  865. circleAnnotArgs.LineDash.Dashes = collect;
  866. }
  867. }
  868. else
  869. {
  870. circleAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  871. }
  872. if (circleAnnotArgs != null)
  873. {
  874. selectedArgs = new List<AnnotHandlerEventArgs>();
  875. selectedArgs.Add(circleAnnotArgs);
  876. }
  877. }
  878. else
  879. {
  880. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  881. }
  882. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  883. return circleAnnotArgs;
  884. }
  885. /// <summary>
  886. /// 箭头 线
  887. /// </summary>
  888. /// <param name="TagStr"></param>
  889. /// <param name="selectedArgs"></param>
  890. /// <returns></returns>
  891. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  892. {
  893. LineAnnotArgs lineArgs = new LineAnnotArgs();
  894. if (selectedArgs == null || selectedArgs.Count == 0)
  895. {
  896. var annotate = Settings.Default.AppProperties.Annotate;
  897. if (annotate != null)
  898. {
  899. lineArgs.LineColor = annotate.LineColor;
  900. }
  901. else
  902. {
  903. lineArgs.LineColor = Colors.Red;
  904. }
  905. lineArgs.LineColor = Colors.Red;
  906. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  907. bool isLastAnnot = false;
  908. if (TagStr == "Line")
  909. {
  910. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  911. isLastAnnot = (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  912. }
  913. else
  914. {
  915. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  916. isLastAnnot = (propertyPanel.LastArrowAnnot != null ? true : false);
  917. }
  918. if (isLastAnnot == false)
  919. {
  920. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  921. if (defaultAnnot == null)
  922. {
  923. defaultAnnot = new DefaultAnnotProperty();
  924. defaultAnnot.AnnotToolType = lineArgs.EventType;
  925. defaultAnnot.Thickness = 1;
  926. defaultAnnot.Opacity = 1;
  927. defaultAnnot.NoteText = string.Empty;
  928. defaultAnnot.DashArray = null;
  929. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  930. Settings.Default.Save();
  931. }
  932. lineArgs.LineDash = DashStyles.Solid;
  933. lineArgs.LineWidth = defaultAnnot.Thickness;
  934. lineArgs.Transparency = defaultAnnot.Opacity;
  935. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  936. {
  937. lineArgs.LineDash = DashStyles.Solid;
  938. }
  939. else
  940. {
  941. var collect = new DoubleCollection();
  942. foreach (var item in defaultAnnot.DashArray)
  943. {
  944. collect.Add(item);
  945. }
  946. if (lineArgs.LineDash == null)
  947. lineArgs.LineDash = new DashStyle();
  948. lineArgs.LineDash.Dashes = collect;
  949. }
  950. }
  951. else
  952. {
  953. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  954. {
  955. lineArgs = propertyPanel.LastArrowAnnot as LineAnnotArgs;
  956. }
  957. else
  958. {
  959. lineArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  960. }
  961. }
  962. if (lineArgs != null)
  963. {
  964. selectedArgs = new List<AnnotHandlerEventArgs>();
  965. selectedArgs.Add(lineArgs);
  966. }
  967. }
  968. else
  969. {
  970. lineArgs = selectedArgs[0] as LineAnnotArgs;
  971. }
  972. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  973. return lineArgs;
  974. }
  975. /// <summary>
  976. /// 图章
  977. /// </summary>
  978. /// <returns></returns>
  979. private AnnotHandlerEventArgs GetStamp()
  980. {
  981. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  982. stampAnnotArgs.Opacity = 1;
  983. stampAnnotArgs.StampText = "APPROVED";
  984. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  985. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  986. if (stampAnnotArgs != null)
  987. stampAnnotArgsList.Add(stampAnnotArgs);
  988. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  989. return stampAnnotArgs;
  990. }
  991. /// <summary>
  992. /// 签名
  993. /// </summary>
  994. /// <returns></returns>
  995. private AnnotHandlerEventArgs GetSignature()
  996. {
  997. AddToPropertyPanel("SignatureAnnotProperty");
  998. return null;
  999. }
  1000. private AnnotHandlerEventArgs GetImage()
  1001. {
  1002. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1003. stampArgs.Opacity = 1;
  1004. stampArgs.Type = StampType.IMAGE_STAMP;
  1005. OpenFileDialog openFileDialog = new OpenFileDialog();
  1006. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1007. if (openFileDialog.ShowDialog() == true)
  1008. {
  1009. stampArgs.ImagePath = openFileDialog.FileName;
  1010. }
  1011. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1012. if (stampArgs != null)
  1013. stampArgsList.Add(stampArgs);
  1014. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1015. return stampArgs;
  1016. }
  1017. /// <summary>
  1018. /// 内容选择
  1019. /// </summary>
  1020. /// <param name="annotBtn"></param>
  1021. /// <returns></returns>
  1022. private AnnotHandlerEventArgs GetSnapshotEdit()
  1023. {
  1024. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1025. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1026. snapshotArgs.ControlPointColor = Colors.White;
  1027. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1028. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1029. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1030. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1031. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1032. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1033. #region to do
  1034. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1035. //snapshotArgs.ToolPanel = snapMenu;
  1036. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1037. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1038. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1039. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1040. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1041. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1042. #endregion to do
  1043. return snapshotArgs;
  1044. }
  1045. #endregion 注释工具
  1046. #region 菜单
  1047. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  1048. {
  1049. if (viewContentViewModel.mainViewModel.IsBookMode)
  1050. {
  1051. menuItem.IsEnabled = false;
  1052. return true;
  1053. }
  1054. else
  1055. {
  1056. menuItem.IsEnabled = true;
  1057. return false;
  1058. }
  1059. }
  1060. private void ExportPicture_MenuItemClick()
  1061. {
  1062. //图片提取
  1063. try
  1064. {
  1065. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1066. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1067. foreach (int pageIndex in imageDict.Keys)
  1068. {
  1069. imageList = imageDict[pageIndex];
  1070. }
  1071. string path = PDFViewer.Document.FileName;
  1072. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1073. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1074. {
  1075. int i = 1;
  1076. int pagenum = 1;
  1077. string choosePath = folderDialog.SelectedPath;
  1078. string sPath = choosePath + "\\" + path + "_Extract Image";
  1079. sPath = GetExportPathName(sPath);
  1080. if (!Directory.Exists(sPath))
  1081. {
  1082. Directory.CreateDirectory(sPath);
  1083. }
  1084. if (Directory.Exists(sPath))
  1085. {
  1086. foreach (System.Drawing.Bitmap image in imageList)
  1087. {
  1088. foreach (var item in imageDict.Keys)
  1089. {
  1090. pagenum = item;
  1091. }
  1092. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1093. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1094. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1095. i++;
  1096. }
  1097. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1098. }
  1099. }
  1100. }
  1101. catch (Exception ex) { }
  1102. }
  1103. public string GetExportPathName(string path)
  1104. {
  1105. int i = 1;
  1106. string outpath = path;
  1107. while (Directory.Exists(outpath))
  1108. {
  1109. outpath = path + $"({i.ToString()})";
  1110. i++;
  1111. }
  1112. return outpath;
  1113. }
  1114. private string GetNum(int num)
  1115. {
  1116. if (num % 10 < 1)
  1117. {
  1118. return "00" + num.ToString();
  1119. }
  1120. if (num % 10 >= 1 && num % 10 < 10)
  1121. {
  1122. return "0" + num.ToString();
  1123. }
  1124. else
  1125. {
  1126. return num.ToString();
  1127. }
  1128. }
  1129. #endregion 菜单
  1130. }
  1131. }