AnnotToolContentViewModel.Function.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Office.Core;
  7. using Microsoft.Win32;
  8. using PDF_Office.CustomControl;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Model.BOTA;
  11. using PDF_Office.Properties;
  12. using PDF_Office.ViewModels.BOTA;
  13. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  14. using PDF_Office.Views.BOTA;
  15. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  16. using PDFSettings;
  17. using Prism.Mvvm;
  18. using Prism.Regions;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Threading.Tasks;
  25. using System.Windows;
  26. using System.Windows.Controls;
  27. using System.Windows.Forms;
  28. using System.Windows.Input;
  29. using System.Windows.Media;
  30. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  31. using ContextMenu = System.Windows.Controls.ContextMenu;
  32. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  33. using MenuItem = System.Windows.Controls.MenuItem;
  34. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  35. namespace PDF_Office.ViewModels.Tools
  36. {
  37. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  38. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  39. {
  40. #region 初始化
  41. #region 初始化数据
  42. //初始化注释的属性值,并存在本地缓存数据集里
  43. private void InitDefaultValue()
  44. {
  45. InitAnnotHighlight();
  46. InitAnnotUnderline();
  47. InitAnnotSquiggly();
  48. InitAnnotStrikeout();
  49. }
  50. private void InitAnnotHighlight()
  51. {
  52. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  53. if (annotProperty == null)
  54. {
  55. annotProperty = new DefaultAnnotProperty();
  56. annotProperty.AnnotToolType = AnnotArgsType.AnnotHighlight;
  57. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  58. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  59. annotProperty.Opacity = 0.5;
  60. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  61. }
  62. else
  63. {
  64. HighLightColor = new SolidColorBrush(annotProperty.BackgroundColor);
  65. HighLightOpacity = annotProperty.Opacity;
  66. }
  67. }
  68. private void InitAnnotUnderline()
  69. {
  70. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  71. if (annotProperty == null)
  72. {
  73. annotProperty = new DefaultAnnotProperty();
  74. annotProperty.AnnotToolType = AnnotArgsType.AnnotUnderline;
  75. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  76. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  77. annotProperty.Opacity = 0.5;
  78. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  79. }
  80. else
  81. {
  82. UnderLineColor = new SolidColorBrush(annotProperty.BackgroundColor);
  83. UnderLineOpacity = annotProperty.Opacity;
  84. }
  85. }
  86. private void InitAnnotSquiggly()
  87. {
  88. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  89. if (annotProperty == null)
  90. {
  91. annotProperty = new DefaultAnnotProperty();
  92. annotProperty.AnnotToolType = AnnotArgsType.AnnotSquiggly;
  93. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  94. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  95. annotProperty.Opacity = 0.5;
  96. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  97. }
  98. else
  99. {
  100. SquigglyColor = new SolidColorBrush(annotProperty.BackgroundColor);
  101. SquigglyOpacity = annotProperty.Opacity;
  102. }
  103. }
  104. private void InitAnnotStrikeout()
  105. {
  106. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  107. if (annotProperty == null)
  108. {
  109. annotProperty = new DefaultAnnotProperty();
  110. annotProperty.AnnotToolType = AnnotArgsType.AnnotStrikeout;
  111. annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  112. annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
  113. annotProperty.Opacity = 0.5;
  114. SettingHelper.SetAnnotDefaultProperty(annotProperty);
  115. }
  116. else
  117. {
  118. StrikeoutColor = new SolidColorBrush(annotProperty.BackgroundColor);
  119. StrikeoutOpacity = annotProperty.Opacity;
  120. }
  121. }
  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. #endregion 初始化数据
  140. #endregion 初始化
  141. #region 注释工具
  142. //注释工具
  143. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  144. {
  145. switch (tag)
  146. {
  147. case "SnapshotEdit"://内容选择
  148. annotArgs = GetSnapshotEdit();
  149. break;
  150. case "HighLight"://字体高亮
  151. annotArgs = GetHighLight();
  152. break;
  153. case "UnderLine"://下划线
  154. annotArgs = GetUnderLine();
  155. break;
  156. case "Squiggly"://波浪线
  157. annotArgs = GetSquiggly();
  158. break;
  159. case "Strikeout"://删除线
  160. annotArgs = GetStrikeout();
  161. break;
  162. case "Freehand"://手绘
  163. annotArgs = GetFreehand();
  164. break;
  165. case "Freetext"://文本
  166. annotArgs = GetFreetext();
  167. break;
  168. case "StickyNote"://便签
  169. annotArgs = GetStickyNote();
  170. break;
  171. case "Rect"://矩形
  172. annotArgs = GetRect();
  173. break;
  174. case "Circle"://圆
  175. annotArgs = GetCircle();
  176. break;
  177. case "Arrow"://箭头
  178. case "Line"://线
  179. annotArgs = GetArrowLine(tag);
  180. break;
  181. case "Stamp"://图章
  182. annotArgs = GetStamp();
  183. break;
  184. case "Image":
  185. annotArgs = GetImage();
  186. break;
  187. case "Signature"://签名
  188. annotArgs = GetSignature();
  189. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  190. break;
  191. case "Link"://链接
  192. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  193. annotArgs = GetLink();
  194. break;
  195. }
  196. }
  197. /// <summary>
  198. /// 高亮注释
  199. /// </summary>
  200. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  201. {
  202. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  203. TextHighlightAnnotArgs highlightArgs = null;
  204. if (selectedArgs == null || selectedArgs.Count == 0)
  205. {
  206. highlightArgs = new TextHighlightAnnotArgs();
  207. highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
  208. highlightArgs.Transparency = 0.5;
  209. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  210. if (annotProperty != null)
  211. {
  212. highlightArgs.Color = annotProperty.ForgoundColor;
  213. highlightArgs.Transparency = annotProperty.Opacity;
  214. highlightArgs.Content = annotProperty.NoteText;
  215. }
  216. if (highlightArgs != null)
  217. {
  218. selectedArgs = new List<AnnotHandlerEventArgs>();
  219. selectedArgs.Add(highlightArgs);
  220. }
  221. }
  222. else
  223. {
  224. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  225. }
  226. annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
  227. annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
  228. annotAttribsList[AnnotAttrib.NoteText] = highlightArgs.Content;
  229. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs, annotAttribsList);
  230. return highlightArgs;
  231. }
  232. /// <summary>
  233. /// 链接
  234. /// </summary>
  235. /// <param name="selectedArgs">所选中的注释</param>
  236. /// <param name="annotAttribEvent">注释属性列表</param>
  237. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  238. {
  239. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  240. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  241. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLink);
  242. if (annotProperty != null)
  243. {
  244. }
  245. if (selectedArgs != null && selectedArgs.Count > 1)
  246. {
  247. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  248. }
  249. else
  250. {
  251. linkArgs.URI = string.Empty;
  252. linkArgs.LinkType = LINK_TYPE.GOTO;
  253. linkArgs.DestIndex = -1;
  254. if (linkArgs != null)
  255. {
  256. selectedArgs = new List<AnnotHandlerEventArgs>();
  257. selectedArgs.Add(linkArgs);
  258. }
  259. }
  260. annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
  261. annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
  262. annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
  263. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribsList, annotAttribEvent);
  264. return linkArgs;
  265. }
  266. /// <summary>
  267. /// 下划线
  268. /// </summary>
  269. /// <param name="selectedArgs"></param>
  270. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  271. {
  272. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  273. TextUnderlineAnnotArgs underlineArgs = null;
  274. if (selectedArgs == null || selectedArgs.Count == 0)
  275. {
  276. underlineArgs = new TextUnderlineAnnotArgs();
  277. underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
  278. underlineArgs.Transparency = 1;
  279. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
  280. if (annotProperty != null)
  281. {
  282. underlineArgs.Color = annotProperty.ForgoundColor;
  283. underlineArgs.Transparency = annotProperty.Opacity;
  284. underlineArgs.Content = annotProperty.NoteText;
  285. }
  286. if (underlineArgs != null)
  287. {
  288. selectedArgs = new List<AnnotHandlerEventArgs>();
  289. selectedArgs.Add(underlineArgs);
  290. }
  291. }
  292. else
  293. {
  294. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  295. }
  296. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  297. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  298. annotAttribsList[AnnotAttrib.NoteText] = underlineArgs.Content;
  299. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs, annotAttribsList);
  300. return underlineArgs;
  301. }
  302. /// <summary>
  303. /// 波浪线
  304. /// </summary>
  305. /// <param name="selectedArgs"></param>
  306. /// <returns></returns>
  307. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  308. {
  309. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  310. TextSquigglyAnnotArgs squigglyArgs = null;
  311. if (selectedArgs == null || selectedArgs.Count == 0)
  312. {
  313. squigglyArgs = new TextSquigglyAnnotArgs();
  314. squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
  315. squigglyArgs.Transparency = 1;
  316. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
  317. if (annotProperty != null)
  318. {
  319. squigglyArgs.Color = annotProperty.ForgoundColor;
  320. squigglyArgs.Transparency = annotProperty.Opacity;
  321. squigglyArgs.Content = annotProperty.NoteText;
  322. }
  323. if (squigglyArgs != null)
  324. {
  325. selectedArgs = new List<AnnotHandlerEventArgs>();
  326. selectedArgs.Add(squigglyArgs);
  327. }
  328. }
  329. else
  330. {
  331. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  332. }
  333. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  334. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  335. annotAttribsList[AnnotAttrib.NoteText] = squigglyArgs.Content;
  336. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs, annotAttribsList);
  337. return squigglyArgs;
  338. }
  339. /// <summary>
  340. /// 删除线
  341. /// </summary>
  342. /// <param name="selectedArgs"></param>
  343. /// <returns></returns>
  344. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  345. {
  346. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  347. TextStrikeoutAnnotArgs strikeoutArgs = null;
  348. if (selectedArgs == null || selectedArgs.Count == 0)
  349. {
  350. strikeoutArgs = new TextStrikeoutAnnotArgs();
  351. strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
  352. strikeoutArgs.Transparency = 1;
  353. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
  354. if (annotProperty != null)
  355. {
  356. strikeoutArgs.Color = annotProperty.ForgoundColor;
  357. strikeoutArgs.Transparency = annotProperty.Opacity;
  358. strikeoutArgs.Content = annotProperty.NoteText;
  359. }
  360. if (strikeoutArgs != null)
  361. {
  362. selectedArgs = new List<AnnotHandlerEventArgs>();
  363. selectedArgs.Add(strikeoutArgs);
  364. }
  365. }
  366. else
  367. {
  368. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  369. }
  370. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  371. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  372. annotAttribsList[AnnotAttrib.NoteText] = strikeoutArgs.Content;
  373. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs, annotAttribsList);
  374. return strikeoutArgs;
  375. }
  376. /// <summary>
  377. /// 手绘
  378. /// </summary>
  379. /// <param name="selectedArgs"></param>
  380. /// <returns></returns>
  381. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  382. {
  383. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  384. FreehandAnnotArgs freehandArgs = null;
  385. if (selectedArgs == null || selectedArgs.Count == 0)
  386. {
  387. freehandArgs = new FreehandAnnotArgs();
  388. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  389. freehandArgs.Transparency = 1;
  390. freehandArgs.LineWidth = 2;
  391. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
  392. if (annotProperty != null)
  393. {
  394. freehandArgs.InkColor = annotProperty.ForgoundColor;
  395. freehandArgs.Transparency = annotProperty.Opacity;
  396. freehandArgs.LineWidth = annotProperty.Thickness;
  397. freehandArgs.Content = annotProperty.NoteText;
  398. }
  399. if (freehandArgs != null)
  400. {
  401. selectedArgs = new List<AnnotHandlerEventArgs>();
  402. selectedArgs.Add(freehandArgs);
  403. }
  404. }
  405. else
  406. {
  407. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  408. }
  409. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  410. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  411. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  412. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  413. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs, annotAttribsList);
  414. return freehandArgs;
  415. }
  416. /// <summary>
  417. /// 文本
  418. /// </summary>
  419. /// <param name="selectedArgs"></param>
  420. /// <returns></returns>
  421. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  422. {
  423. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  424. FreeTextAnnotArgs freetextArgs = null;
  425. TextAlignment textAlignment;
  426. if (selectedArgs == null || selectedArgs.Count == 0)
  427. {
  428. freetextArgs = new FreeTextAnnotArgs();
  429. freetextArgs.Align = TextAlignment.Left;
  430. freetextArgs.BgColor = Colors.Transparent;
  431. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  432. freetextArgs.FontColor = Colors.Black;
  433. freetextArgs.FontSize = 14;
  434. freetextArgs.Transparency = 1;
  435. freetextArgs.LineColor = Colors.Black;
  436. freetextArgs.LineWidth = 0;
  437. freetextArgs.TextContent = string.Empty;
  438. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  439. if (annotProperty != null)
  440. {
  441. freetextArgs.Align = annotProperty.TextAlign;
  442. freetextArgs.BgColor = annotProperty.BackgroundColor;
  443. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  444. freetextArgs.FontColor = annotProperty.ForgoundColor;
  445. freetextArgs.FontSize = annotProperty.FontSize;
  446. freetextArgs.Transparency = annotProperty.Opacity;
  447. freetextArgs.LineColor = annotProperty.BorderColor;
  448. freetextArgs.LineWidth = annotProperty.Thickness;
  449. freetextArgs.TextContent = annotProperty.NoteText;
  450. freetextArgs.FontWeight = annotProperty.FontWeight;
  451. freetextArgs.FontStyle = annotProperty.FontStyle;
  452. }
  453. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  454. if (align == 0)
  455. textAlignment = TextAlignment.Left;
  456. else if (align == 1)
  457. textAlignment = TextAlignment.Center;
  458. else
  459. textAlignment = TextAlignment.Right;
  460. if (freetextArgs != null)
  461. {
  462. selectedArgs = new List<AnnotHandlerEventArgs>();
  463. selectedArgs.Add(freetextArgs);
  464. }
  465. }
  466. else
  467. {
  468. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  469. textAlignment = freetextArgs.Align;
  470. }
  471. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  472. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  473. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  474. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  475. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  476. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  477. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  478. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  479. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  480. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  481. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  482. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  483. return freetextArgs;
  484. }
  485. /// <summary>
  486. /// 便签
  487. /// </summary>
  488. /// <param name="selectedArgs"></param>
  489. /// <returns></returns>
  490. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  491. {
  492. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  493. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  494. if (selectedArgs == null || selectedArgs.Count == 0)
  495. {
  496. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  497. stickyAnnotArgs.StickyNote = string.Empty;
  498. stickyAnnotArgs.Transparency = 1;
  499. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
  500. if (annotProperty != null)
  501. {
  502. stickyAnnotArgs.Color = annotProperty.ForgoundColor;
  503. stickyAnnotArgs.StickyNote = annotProperty.NoteText;
  504. stickyAnnotArgs.Transparency = annotProperty.Opacity;
  505. }
  506. if (stickyAnnotArgs != null)
  507. {
  508. selectedArgs = new List<AnnotHandlerEventArgs>();
  509. selectedArgs.Add(stickyAnnotArgs);
  510. }
  511. }
  512. else
  513. {
  514. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  515. }
  516. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  517. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  518. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  519. annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
  520. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  521. if (stickyAnnotArgs != null)
  522. stickyAnnotArgsList.Add(stickyAnnotArgs);
  523. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs, annotAttribsList);
  524. return stickyAnnotArgs;
  525. }
  526. /// <summary>
  527. /// 矩形
  528. /// </summary>
  529. /// <param name="selectedArgs"></param>
  530. /// <returns></returns>
  531. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  532. {
  533. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  534. SquareAnnotArgs squareArgs = null;
  535. if (selectedArgs == null || selectedArgs.Count == 0)
  536. {
  537. squareArgs = new SquareAnnotArgs();
  538. squareArgs.LineColor = Colors.Red;
  539. squareArgs.BgColor = Colors.Transparent;
  540. squareArgs.LineWidth = 1;
  541. squareArgs.Transparency = 1;
  542. squareArgs.LineDash = DashStyles.Solid;
  543. squareArgs.Content = string.Empty;
  544. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
  545. if (annotProperty != null)
  546. {
  547. squareArgs.LineColor = annotProperty.BorderColor;
  548. squareArgs.BgColor = annotProperty.BackgroundColor;
  549. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  550. {
  551. squareArgs.LineDash = DashStyles.Solid;
  552. }
  553. else
  554. {
  555. DashStyle dash = new DashStyle();
  556. foreach (var offset in annotProperty.DashArray)
  557. {
  558. dash.Dashes.Add(offset);
  559. }
  560. squareArgs.LineDash = dash;
  561. }
  562. squareArgs.LineWidth = annotProperty.Thickness;
  563. squareArgs.Transparency = annotProperty.Opacity;
  564. squareArgs.Content = annotProperty.NoteText;
  565. }
  566. if (squareArgs != null)
  567. {
  568. selectedArgs = new List<AnnotHandlerEventArgs>();
  569. selectedArgs.Add(squareArgs);
  570. }
  571. }
  572. else
  573. {
  574. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  575. }
  576. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  577. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  578. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  579. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  580. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  581. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  582. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs, annotAttribsList);
  583. return squareArgs;
  584. }
  585. /// <summary>
  586. /// 圆
  587. /// </summary>
  588. /// <param name="selectedArgs"></param>
  589. /// <returns></returns>
  590. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  591. {
  592. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  593. CircleAnnotArgs circleAnnotArgs = null;
  594. if (selectedArgs == null || selectedArgs.Count == 0)
  595. {
  596. circleAnnotArgs = new CircleAnnotArgs();
  597. circleAnnotArgs.LineColor = Colors.Red;
  598. circleAnnotArgs.BgColor = Colors.Transparent;
  599. circleAnnotArgs.LineWidth = 1;
  600. circleAnnotArgs.Transparency = 1;
  601. circleAnnotArgs.LineDash = DashStyles.Solid;
  602. circleAnnotArgs.Content = string.Empty;
  603. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
  604. if (annotProperty != null)
  605. {
  606. circleAnnotArgs.LineColor = annotProperty.BorderColor;
  607. circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
  608. if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
  609. {
  610. circleAnnotArgs.LineDash = DashStyles.Solid;
  611. }
  612. else
  613. {
  614. DashStyle dash = new DashStyle();
  615. foreach (var offset in annotProperty.DashArray)
  616. {
  617. dash.Dashes.Add(offset);
  618. }
  619. circleAnnotArgs.LineDash = dash;
  620. }
  621. circleAnnotArgs.LineWidth = annotProperty.Thickness;
  622. circleAnnotArgs.Transparency = annotProperty.Opacity;
  623. circleAnnotArgs.Content = annotProperty.NoteText;
  624. }
  625. if (circleAnnotArgs != null)
  626. {
  627. selectedArgs = new List<AnnotHandlerEventArgs>();
  628. selectedArgs.Add(circleAnnotArgs);
  629. }
  630. }
  631. else
  632. {
  633. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  634. }
  635. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  636. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  637. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  638. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  639. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  640. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  641. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs, annotAttribsList);
  642. return circleAnnotArgs;
  643. }
  644. /// <summary>
  645. /// 箭头 线
  646. /// </summary>
  647. /// <param name="TagStr"></param>
  648. /// <param name="selectedArgs"></param>
  649. /// <returns></returns>
  650. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  651. {
  652. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  653. LineAnnotArgs lineArgs = new LineAnnotArgs();
  654. if (selectedArgs == null || selectedArgs.Count == 0)
  655. {
  656. lineArgs.LineColor = Colors.Red;
  657. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  658. if (TagStr == "Line")
  659. {
  660. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  661. }
  662. else
  663. {
  664. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  665. }
  666. lineArgs.LineDash = DashStyles.Solid;
  667. lineArgs.LineWidth = 1;
  668. lineArgs.Transparency = 1;
  669. lineArgs.Content = string.Empty;
  670. if (lineArgs != null)
  671. {
  672. selectedArgs = new List<AnnotHandlerEventArgs>();
  673. selectedArgs.Add(lineArgs);
  674. }
  675. }
  676. else
  677. {
  678. lineArgs = selectedArgs[0] as LineAnnotArgs;
  679. }
  680. DefaultAnnotProperty annotProperty = null;
  681. if (TagStr == "Line")
  682. {
  683. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
  684. if (annotProperty != null)
  685. {
  686. annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  687. annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  688. }
  689. }
  690. else
  691. {
  692. annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
  693. }
  694. if (annotProperty != null)
  695. {
  696. lineArgs.LineColor = annotProperty.BorderColor;
  697. lineArgs.HeadLineType = annotProperty.HeadLineType;
  698. lineArgs.TailLineType = annotProperty.TailLineType;
  699. DashStyle dash = new DashStyle();
  700. foreach (var offset in annotProperty.DashArray)
  701. {
  702. dash.Dashes.Add(offset);
  703. }
  704. lineArgs.LineDash = dash;
  705. lineArgs.LineWidth = annotProperty.Thickness;
  706. lineArgs.Transparency = annotProperty.Opacity;
  707. lineArgs.Content = annotProperty.NoteText;
  708. }
  709. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  710. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  711. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  712. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  713. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  714. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  715. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  716. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs, annotAttribsList);
  717. return lineArgs;
  718. }
  719. /// <summary>
  720. /// 图章
  721. /// </summary>
  722. /// <returns></returns>
  723. private AnnotHandlerEventArgs GetStamp()
  724. {
  725. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  726. stampAnnotArgs.Opacity = 1;
  727. stampAnnotArgs.StampText = "APPROVED";
  728. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  729. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  730. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  731. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  732. if (stampAnnotArgs != null)
  733. stampAnnotArgsList.Add(stampAnnotArgs);
  734. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList, annotAttribsList);
  735. return stampAnnotArgs;
  736. }
  737. /// <summary>
  738. /// 签名
  739. /// </summary>
  740. /// <returns></returns>
  741. private AnnotHandlerEventArgs GetSignature()
  742. {
  743. AddToPropertyPanel("SignatureAnnotProperty");
  744. return null;
  745. }
  746. private AnnotHandlerEventArgs GetImage()
  747. {
  748. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  749. StampAnnotArgs stampArgs = new StampAnnotArgs();
  750. stampArgs.Opacity = 1;
  751. stampArgs.Type = StampType.IMAGE_STAMP;
  752. OpenFileDialog openFileDialog = new OpenFileDialog();
  753. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  754. if (openFileDialog.ShowDialog() == true)
  755. {
  756. stampArgs.ImagePath = openFileDialog.FileName;
  757. }
  758. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  759. if (stampArgs != null)
  760. stampArgsList.Add(stampArgs);
  761. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList, annotAttribsList);
  762. return stampArgs;
  763. }
  764. /// <summary>
  765. /// 内容选择
  766. /// </summary>
  767. /// <param name="annotBtn"></param>
  768. /// <returns></returns>
  769. private AnnotHandlerEventArgs GetSnapshotEdit()
  770. {
  771. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  772. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  773. snapshotArgs.ControlPointColor = Colors.White;
  774. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  775. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  776. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  777. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  778. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  779. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  780. #region to do
  781. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  782. //snapshotArgs.ToolPanel = snapMenu;
  783. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  784. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  785. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  786. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  787. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  788. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  789. #endregion to do
  790. return snapshotArgs;
  791. }
  792. #endregion 注释工具
  793. #region 菜单
  794. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  795. {
  796. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  797. {
  798. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  799. switch (clickMenu.Tag.ToString())
  800. {
  801. case "HighLight"://字体高亮
  802. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  803. highlightArgs.ClientRect = annotCommand.TextRect;
  804. highlightArgs.Content = annotCommand.Text;
  805. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  806. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  807. PDFViewer.SetToolParam(highlightArgs);
  808. PDFViewer.SetMouseMode(MouseModes.PanTool);
  809. break;
  810. case "UnderLine"://下划线
  811. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  812. underlineArgs.ClientRect = annotCommand.TextRect;
  813. underlineArgs.Content = annotCommand.Text;
  814. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  815. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  816. PDFViewer.SetToolParam(underlineArgs);
  817. PDFViewer.SetMouseMode(MouseModes.PanTool);
  818. break;
  819. case "Strikeout"://删除线
  820. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  821. strikeoutArgs.ClientRect = annotCommand.TextRect;
  822. strikeoutArgs.Content = annotCommand.Text;
  823. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  824. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  825. PDFViewer.SetToolParam(strikeoutArgs);
  826. PDFViewer.SetMouseMode(MouseModes.PanTool);
  827. break;
  828. case "Freetext"://文本
  829. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  830. textArgs.ClientRect = annotCommand.TextRect;
  831. //textArgs.Transparency = 1;
  832. //textArgs.BgColor = Colors.Transparent;
  833. //textArgs.LineColor = Colors.Red;
  834. //textArgs.LineWidth = 2;
  835. textArgs.TextContent = annotCommand.Text;
  836. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  837. break;
  838. case "StickyNote"://便签
  839. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  840. stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  841. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  842. break;
  843. case "Rect"://矩形
  844. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  845. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  846. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  847. break;
  848. case "Circle"://圆
  849. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  850. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  851. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  852. break;
  853. case "Line"://线
  854. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  855. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  856. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  857. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  858. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  859. break;
  860. case "Link"://链接
  861. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  862. linkArgs.ClientRect = annotCommand.TextRect;
  863. linkArgs.URI = string.Empty;
  864. linkArgs.LinkType = LINK_TYPE.GOTO;
  865. linkArgs.DestIndex = annotCommand.PageIndex;
  866. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  867. BtnLinkIsChecked = true;
  868. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  869. lists.Add(linkArgs);
  870. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  871. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  872. PDFViewer.SetToolParam(annotArgs);
  873. viewContentViewModel.IsPropertyOpen = true;
  874. break;
  875. case "OutLine":
  876. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  877. if (isTabItemAnnotation == false)
  878. {
  879. bOTAContent.TabItemOutLine.IsSelected = true;
  880. }
  881. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  882. if (outLineControlViewModel != null && outLineControl != null)
  883. {
  884. string str = null;
  885. if (string.IsNullOrEmpty(annotCommand.Text))
  886. {
  887. str = (annotCommand.PageIndex + 1).ToString();
  888. }
  889. else
  890. {
  891. str = annotCommand.Text;
  892. }
  893. OutlineNode outline = outLineControl.AddOutlineNode(str);
  894. CPDFOutline result = outline.Outline;
  895. if (result != null)
  896. {
  897. outLineControlViewModel.SetTitle(result, str);
  898. outLineControlViewModel.Updata(false);
  899. //outLineControl.IsReName = true;
  900. //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
  901. //{
  902. // outLineControl.ReNameOutlineNode = outline;
  903. //}
  904. }
  905. }
  906. break;
  907. case "ExportPicture":
  908. ExportPicture_MenuItemClick();
  909. break;
  910. }
  911. //ShowPropertyPanel(false);
  912. }
  913. }
  914. private void ExportPicture_MenuItemClick()
  915. {
  916. //图片提取
  917. try
  918. {
  919. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  920. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  921. foreach (int pageIndex in imageDict.Keys)
  922. {
  923. imageList = imageDict[pageIndex];
  924. }
  925. string path = PDFViewer.Document.FileName;
  926. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  927. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  928. {
  929. int i = 1;
  930. int pagenum = 1;
  931. string choosePath = folderDialog.SelectedPath;
  932. string sPath = choosePath + "\\" + path + "_Extract Image";
  933. sPath = GetExportPathName(sPath);
  934. if (!Directory.Exists(sPath))
  935. {
  936. Directory.CreateDirectory(sPath);
  937. }
  938. if (Directory.Exists(sPath))
  939. {
  940. foreach (System.Drawing.Bitmap image in imageList)
  941. {
  942. foreach (var item in imageDict.Keys)
  943. {
  944. pagenum = item;
  945. }
  946. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  947. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  948. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  949. i++;
  950. }
  951. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  952. }
  953. }
  954. }
  955. catch (Exception ex) { }
  956. }
  957. public string GetExportPathName(string path)
  958. {
  959. int i = 1;
  960. string outpath = path;
  961. while (Directory.Exists(outpath))
  962. {
  963. outpath = path + $"({i.ToString()})";
  964. i++;
  965. }
  966. return outpath;
  967. }
  968. private string GetNum(int num)
  969. {
  970. if (num % 10 < 1)
  971. {
  972. return "00" + num.ToString();
  973. }
  974. if (num % 10 >= 1 && num % 10 < 10)
  975. {
  976. return "0" + num.ToString();
  977. }
  978. else
  979. {
  980. return num.ToString();
  981. }
  982. }
  983. #endregion 菜单
  984. }
  985. }