AnnotToolContentViewModel.Function.cs 53 KB

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