AnnotToolContentViewModel.Function.cs 49 KB

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