AnnotToolContentViewModel.Function.cs 51 KB

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