AnnotToolContentViewModel.Function.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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. if (annotArgs is LinkAnnotArgs linkAnnot)
  681. {
  682. //annotArgs.PageIndex = drawRectTuple.Item1;
  683. //annotArgs.ClientRect = drawRectTuple.Item2;
  684. //PDFViewer.CreatePageAnnot(drawRectTuple.Item1, annotArgs);
  685. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  686. linkArgs.ClientRect = drawRectTuple.Item2;
  687. linkArgs.URI = string.Empty;
  688. linkArgs.LinkType = LINK_TYPE.GOTO;
  689. linkArgs.DestIndex = drawRectTuple.Item1;
  690. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, linkArgs);
  691. //BtnLinkIsChecked = true;
  692. //List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  693. //lists.Add(linkArgs);
  694. //propertyPanel.IsAddLink = true;
  695. //annotArgs = GetLink(lists);
  696. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  697. //PDFViewer.SetToolParam(annotArgs);
  698. //viewContentViewModel.IsPropertyOpen = true;
  699. }
  700. if (annotArgs is SquareAnnotArgs squareAnnot)
  701. {
  702. squareAnnot.ClientRect = drawRectTuple.Item2;
  703. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, squareAnnot);
  704. }
  705. }
  706. }
  707. //Event导航到填写与签名的属性面板
  708. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  709. {
  710. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  711. {
  712. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  713. if (annotFillAndSign != null)
  714. {
  715. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  716. return true;
  717. }
  718. }
  719. return false;
  720. }
  721. private void FromFillAndSign(FillAndSigntEventArgs obj)
  722. {
  723. if (obj != null)
  724. {
  725. if (string.IsNullOrEmpty(obj.Action) == false)
  726. {
  727. if (obj.Action == "Clear")
  728. {
  729. viewContentViewModel.AnnotSignatures.Clear();
  730. }
  731. }
  732. }
  733. }
  734. /// <summary>
  735. /// 便签
  736. /// </summary>
  737. /// <param name="selectedArgs"></param>
  738. /// <returns></returns>
  739. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  740. {
  741. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  742. if (selectedArgs == null || selectedArgs.Count == 0)
  743. {
  744. var annotate = Settings.Default.AppProperties.Annotate;
  745. if (annotate != null)
  746. {
  747. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  748. }
  749. else
  750. {
  751. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  752. }
  753. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  754. {
  755. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  756. if (defaultAnnot == null)
  757. {
  758. defaultAnnot = new DefaultAnnotProperty();
  759. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  760. defaultAnnot.NoteText = string.Empty;
  761. defaultAnnot.Opacity = 1;
  762. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  763. Settings.Default.Save();
  764. }
  765. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  766. }
  767. else
  768. {
  769. stickyAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  770. stickyAnnotArgs.Content = string.Empty;
  771. stickyAnnotArgs.StickyNote = string.Empty;
  772. }
  773. if (stickyAnnotArgs != null)
  774. {
  775. selectedArgs = new List<AnnotHandlerEventArgs>();
  776. selectedArgs.Add(stickyAnnotArgs);
  777. }
  778. }
  779. else
  780. {
  781. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  782. }
  783. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  784. if (stickyAnnotArgs != null)
  785. stickyAnnotArgsList.Add(stickyAnnotArgs);
  786. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  787. return stickyAnnotArgs;
  788. }
  789. /// <summary>
  790. /// 矩形
  791. /// </summary>
  792. /// <param name="selectedArgs"></param>
  793. /// <returns></returns>
  794. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  795. {
  796. SquareAnnotArgs squareArgs = null;
  797. if (selectedArgs == null || selectedArgs.Count == 0)
  798. {
  799. squareArgs = new SquareAnnotArgs();
  800. var annotate = Settings.Default.AppProperties.Annotate;
  801. if (annotate != null)
  802. {
  803. squareArgs.BgColor = annotate.RectangleFillColor;
  804. squareArgs.LineColor = annotate.RectangleBorderColor;
  805. }
  806. else
  807. {
  808. squareArgs.LineColor = Colors.Red;
  809. squareArgs.BgColor = Colors.Red;
  810. }
  811. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  812. {
  813. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  814. if (defaultAnnot == null)
  815. {
  816. defaultAnnot = new DefaultAnnotProperty();
  817. defaultAnnot.AnnotToolType = squareArgs.EventType;
  818. defaultAnnot.Thickness = 1;
  819. defaultAnnot.Opacity = 1;
  820. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  821. Settings.Default.Save();
  822. }
  823. squareArgs.LineWidth = defaultAnnot.Thickness;
  824. squareArgs.Transparency = defaultAnnot.Opacity;
  825. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  826. {
  827. squareArgs.LineDash = DashStyles.Solid;
  828. }
  829. else
  830. {
  831. var collect = new DoubleCollection();
  832. foreach (var item in defaultAnnot.DashArray)
  833. {
  834. collect.Add(item);
  835. }
  836. if (squareArgs.LineDash == null)
  837. squareArgs.LineDash = new DashStyle();
  838. squareArgs.LineDash.Dashes = collect;
  839. }
  840. }
  841. else
  842. {
  843. squareArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  844. }
  845. if (squareArgs != null)
  846. {
  847. selectedArgs = new List<AnnotHandlerEventArgs>();
  848. selectedArgs.Add(squareArgs);
  849. CreateAnnotFromSelectPageText(squareArgs);
  850. }
  851. }
  852. else
  853. {
  854. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  855. }
  856. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  857. return squareArgs;
  858. }
  859. /// <summary>
  860. /// 圆
  861. /// </summary>
  862. /// <param name="selectedArgs"></param>
  863. /// <returns></returns>
  864. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  865. {
  866. CircleAnnotArgs circleAnnotArgs = null;
  867. if (selectedArgs == null || selectedArgs.Count == 0)
  868. {
  869. circleAnnotArgs = new CircleAnnotArgs();
  870. var annotate = Settings.Default.AppProperties.Annotate;
  871. if (annotate != null)
  872. {
  873. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  874. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  875. }
  876. else
  877. {
  878. circleAnnotArgs.LineColor = Colors.Red;
  879. circleAnnotArgs.BgColor = Colors.Red;
  880. }
  881. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  882. {
  883. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  884. if (defaultAnnot == null)
  885. {
  886. defaultAnnot = new DefaultAnnotProperty();
  887. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  888. defaultAnnot.Thickness = 1;
  889. defaultAnnot.Opacity = 1;
  890. defaultAnnot.NoteText = string.Empty;
  891. defaultAnnot.DashArray = null;
  892. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  893. Settings.Default.Save();
  894. }
  895. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  896. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  897. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  898. {
  899. circleAnnotArgs.LineDash = DashStyles.Solid;
  900. }
  901. else
  902. {
  903. var collect = new DoubleCollection();
  904. foreach (var item in defaultAnnot.DashArray)
  905. {
  906. collect.Add(item);
  907. }
  908. if (circleAnnotArgs.LineDash == null)
  909. circleAnnotArgs.LineDash = new DashStyle();
  910. circleAnnotArgs.LineDash.Dashes = collect;
  911. }
  912. }
  913. else
  914. {
  915. circleAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  916. }
  917. if (circleAnnotArgs != null)
  918. {
  919. selectedArgs = new List<AnnotHandlerEventArgs>();
  920. selectedArgs.Add(circleAnnotArgs);
  921. }
  922. }
  923. else
  924. {
  925. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  926. }
  927. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  928. return circleAnnotArgs;
  929. }
  930. /// <summary>
  931. /// 箭头 线
  932. /// </summary>
  933. /// <param name="TagStr"></param>
  934. /// <param name="selectedArgs"></param>
  935. /// <returns></returns>
  936. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  937. {
  938. LineAnnotArgs lineArgs = new LineAnnotArgs();
  939. if (selectedArgs == null || selectedArgs.Count == 0)
  940. {
  941. var annotate = Settings.Default.AppProperties.Annotate;
  942. if (annotate != null)
  943. {
  944. lineArgs.LineColor = annotate.LineColor;
  945. }
  946. else
  947. {
  948. lineArgs.LineColor = Colors.Red;
  949. }
  950. lineArgs.LineColor = Colors.Red;
  951. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  952. bool isLastAnnot = false;
  953. if (TagStr == "Line")
  954. {
  955. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  956. isLastAnnot = (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  957. }
  958. else
  959. {
  960. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  961. isLastAnnot = (propertyPanel.LastArrowAnnot != null ? true : false);
  962. }
  963. if (isLastAnnot == false)
  964. {
  965. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  966. if (defaultAnnot == null)
  967. {
  968. defaultAnnot = new DefaultAnnotProperty();
  969. defaultAnnot.AnnotToolType = lineArgs.EventType;
  970. defaultAnnot.Thickness = 1;
  971. defaultAnnot.Opacity = 1;
  972. defaultAnnot.NoteText = string.Empty;
  973. defaultAnnot.DashArray = null;
  974. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  975. Settings.Default.Save();
  976. }
  977. lineArgs.LineDash = DashStyles.Solid;
  978. lineArgs.LineWidth = defaultAnnot.Thickness;
  979. lineArgs.Transparency = defaultAnnot.Opacity;
  980. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  981. {
  982. lineArgs.LineDash = DashStyles.Solid;
  983. }
  984. else
  985. {
  986. var collect = new DoubleCollection();
  987. foreach (var item in defaultAnnot.DashArray)
  988. {
  989. collect.Add(item);
  990. }
  991. if (lineArgs.LineDash == null)
  992. lineArgs.LineDash = new DashStyle();
  993. lineArgs.LineDash.Dashes = collect;
  994. }
  995. }
  996. else
  997. {
  998. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  999. {
  1000. lineArgs = propertyPanel.LastArrowAnnot as LineAnnotArgs;
  1001. }
  1002. else
  1003. {
  1004. lineArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  1005. }
  1006. }
  1007. if (lineArgs != null)
  1008. {
  1009. selectedArgs = new List<AnnotHandlerEventArgs>();
  1010. selectedArgs.Add(lineArgs);
  1011. }
  1012. }
  1013. else
  1014. {
  1015. lineArgs = selectedArgs[0] as LineAnnotArgs;
  1016. }
  1017. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  1018. return lineArgs;
  1019. }
  1020. /// <summary>
  1021. /// 图章
  1022. /// </summary>
  1023. /// <returns></returns>
  1024. private AnnotHandlerEventArgs GetStamp()
  1025. {
  1026. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  1027. stampAnnotArgs.Opacity = 1;
  1028. stampAnnotArgs.StampText = "APPROVED";
  1029. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1030. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1031. if (stampAnnotArgs != null)
  1032. stampAnnotArgsList.Add(stampAnnotArgs);
  1033. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1034. return stampAnnotArgs;
  1035. }
  1036. /// <summary>
  1037. /// 签名
  1038. /// </summary>
  1039. /// <returns></returns>
  1040. private AnnotHandlerEventArgs GetSignature()
  1041. {
  1042. AddToPropertyPanel("SignatureAnnotProperty");
  1043. return null;
  1044. }
  1045. private AnnotHandlerEventArgs GetImage()
  1046. {
  1047. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1048. stampArgs.Opacity = 1;
  1049. stampArgs.Type = StampType.IMAGE_STAMP;
  1050. OpenFileDialog openFileDialog = new OpenFileDialog();
  1051. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1052. if (openFileDialog.ShowDialog() == true)
  1053. {
  1054. stampArgs.ImagePath = openFileDialog.FileName;
  1055. }
  1056. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1057. if (stampArgs != null)
  1058. stampArgsList.Add(stampArgs);
  1059. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1060. return stampArgs;
  1061. }
  1062. /// <summary>
  1063. /// 内容选择
  1064. /// </summary>
  1065. /// <param name="annotBtn"></param>
  1066. /// <returns></returns>
  1067. private AnnotHandlerEventArgs GetSnapshotEdit()
  1068. {
  1069. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1070. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1071. snapshotArgs.ControlPointColor = Colors.White;
  1072. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1073. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1074. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1075. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1076. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1077. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1078. #region to do
  1079. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1080. //snapshotArgs.ToolPanel = snapMenu;
  1081. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1082. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1083. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1084. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1085. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1086. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1087. #endregion to do
  1088. return snapshotArgs;
  1089. }
  1090. #endregion 注释工具
  1091. #region 菜单
  1092. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  1093. {
  1094. if (viewContentViewModel.mainViewModel.IsBookMode)
  1095. {
  1096. menuItem.IsEnabled = false;
  1097. return true;
  1098. }
  1099. else
  1100. {
  1101. menuItem.IsEnabled = true;
  1102. return false;
  1103. }
  1104. }
  1105. private void ExportPicture_MenuItemClick()
  1106. {
  1107. //图片提取
  1108. try
  1109. {
  1110. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1111. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1112. foreach (int pageIndex in imageDict.Keys)
  1113. {
  1114. imageList = imageDict[pageIndex];
  1115. }
  1116. string path = PDFViewer.Document.FileName;
  1117. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1118. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1119. {
  1120. int i = 1;
  1121. int pagenum = 1;
  1122. string choosePath = folderDialog.SelectedPath;
  1123. string sPath = choosePath + "\\" + path + "_Extract Image";
  1124. sPath = GetExportPathName(sPath);
  1125. if (!Directory.Exists(sPath))
  1126. {
  1127. Directory.CreateDirectory(sPath);
  1128. }
  1129. if (Directory.Exists(sPath))
  1130. {
  1131. foreach (System.Drawing.Bitmap image in imageList)
  1132. {
  1133. foreach (var item in imageDict.Keys)
  1134. {
  1135. pagenum = item;
  1136. }
  1137. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1138. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1139. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1140. i++;
  1141. }
  1142. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1143. }
  1144. }
  1145. }
  1146. catch (Exception ex) { }
  1147. }
  1148. public string GetExportPathName(string path)
  1149. {
  1150. int i = 1;
  1151. string outpath = path;
  1152. while (Directory.Exists(outpath))
  1153. {
  1154. outpath = path + $"({i.ToString()})";
  1155. i++;
  1156. }
  1157. return outpath;
  1158. }
  1159. private string GetNum(int num)
  1160. {
  1161. if (num % 10 < 1)
  1162. {
  1163. return "00" + num.ToString();
  1164. }
  1165. if (num % 10 >= 1 && num % 10 < 10)
  1166. {
  1167. return "0" + num.ToString();
  1168. }
  1169. else
  1170. {
  1171. return num.ToString();
  1172. }
  1173. }
  1174. #endregion 菜单
  1175. }
  1176. }