AnnotToolContentViewModel.Function.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. #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 > 0)
  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. /// <summary>
  632. /// 选择文本、图片,右键菜单
  633. /// </summary>
  634. /// <param name="sender"></param>
  635. /// <param name="e"></param>
  636. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  637. {
  638. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  639. {
  640. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  641. switch (clickMenu.Tag.ToString())
  642. {
  643. case "HighLight"://字体高亮
  644. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  645. highlightArgs.ClientRect = annotCommand.TextRect;
  646. highlightArgs.Content = annotCommand.Text;
  647. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  648. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  649. PDFViewer.SetToolParam(highlightArgs);
  650. PDFViewer.SetMouseMode(MouseModes.PanTool);
  651. break;
  652. case "UnderLine"://下划线
  653. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  654. underlineArgs.ClientRect = annotCommand.TextRect;
  655. underlineArgs.Content = annotCommand.Text;
  656. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  657. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  658. PDFViewer.SetToolParam(underlineArgs);
  659. PDFViewer.SetMouseMode(MouseModes.PanTool);
  660. break;
  661. case "Strikeout"://删除线
  662. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  663. strikeoutArgs.ClientRect = annotCommand.TextRect;
  664. strikeoutArgs.Content = annotCommand.Text;
  665. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  666. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  667. PDFViewer.SetToolParam(strikeoutArgs);
  668. PDFViewer.SetMouseMode(MouseModes.PanTool);
  669. break;
  670. case "Freetext"://文本
  671. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  672. textArgs.ClientRect = annotCommand.TextRect;
  673. //textArgs.Transparency = 1;
  674. //textArgs.BgColor = Colors.Transparent;
  675. //textArgs.LineColor = Colors.Red;
  676. //textArgs.LineWidth = 2;
  677. textArgs.TextContent = annotCommand.Text;
  678. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  679. break;
  680. case "StickyNote"://便签
  681. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  682. stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  683. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  684. break;
  685. case "Rect"://矩形
  686. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  687. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  688. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  689. break;
  690. case "Circle"://圆
  691. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  692. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  693. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  694. break;
  695. case "Line"://线
  696. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  697. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  698. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  699. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  700. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  701. break;
  702. case "Link"://链接
  703. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  704. linkArgs.ClientRect = annotCommand.TextRect;
  705. linkArgs.URI = string.Empty;
  706. linkArgs.LinkType = LINK_TYPE.GOTO;
  707. linkArgs.DestIndex = annotCommand.PageIndex;
  708. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  709. BtnLinkIsChecked = true;
  710. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  711. lists.Add(linkArgs);
  712. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  713. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  714. PDFViewer.SetToolParam(annotArgs);
  715. viewContentViewModel.IsPropertyOpen = true;
  716. break;
  717. case "OutLine":
  718. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  719. if (isTabItemAnnotation == false)
  720. {
  721. bOTAContent.TabItemOutLine.IsSelected = true;
  722. }
  723. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  724. if (outLineControlViewModel != null && outLineControl != null)
  725. {
  726. string str = null;
  727. if (string.IsNullOrEmpty(annotCommand.Text))
  728. {
  729. str = (annotCommand.PageIndex + 1).ToString();
  730. }
  731. else
  732. {
  733. str = annotCommand.Text;
  734. }
  735. OutlineNode outline = outLineControl.AddOutlineNode(str);
  736. CPDFOutline result = outline.Outline;
  737. if (result != null)
  738. {
  739. outLineControlViewModel.SetTitle(result, str);
  740. outLineControlViewModel.Updata(false);
  741. //outLineControl.IsReName = true;
  742. //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
  743. //{
  744. // outLineControl.ReNameOutlineNode = outline;
  745. //}
  746. }
  747. }
  748. break;
  749. case "ExportPicture":
  750. ExportPicture_MenuItemClick();
  751. break;
  752. }
  753. //ShowPropertyPanel(false);
  754. }
  755. }
  756. private void ExportPicture_MenuItemClick()
  757. {
  758. //图片提取
  759. try
  760. {
  761. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  762. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  763. foreach (int pageIndex in imageDict.Keys)
  764. {
  765. imageList = imageDict[pageIndex];
  766. }
  767. string path = PDFViewer.Document.FileName;
  768. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  769. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  770. {
  771. int i = 1;
  772. int pagenum = 1;
  773. string choosePath = folderDialog.SelectedPath;
  774. string sPath = choosePath + "\\" + path + "_Extract Image";
  775. sPath = GetExportPathName(sPath);
  776. if (!Directory.Exists(sPath))
  777. {
  778. Directory.CreateDirectory(sPath);
  779. }
  780. if (Directory.Exists(sPath))
  781. {
  782. foreach (System.Drawing.Bitmap image in imageList)
  783. {
  784. foreach (var item in imageDict.Keys)
  785. {
  786. pagenum = item;
  787. }
  788. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  789. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  790. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  791. i++;
  792. }
  793. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  794. }
  795. }
  796. }
  797. catch (Exception ex) { }
  798. }
  799. public string GetExportPathName(string path)
  800. {
  801. int i = 1;
  802. string outpath = path;
  803. while (Directory.Exists(outpath))
  804. {
  805. outpath = path + $"({i.ToString()})";
  806. i++;
  807. }
  808. return outpath;
  809. }
  810. private string GetNum(int num)
  811. {
  812. if (num % 10 < 1)
  813. {
  814. return "00" + num.ToString();
  815. }
  816. if (num % 10 >= 1 && num % 10 < 10)
  817. {
  818. return "0" + num.ToString();
  819. }
  820. else
  821. {
  822. return num.ToString();
  823. }
  824. }
  825. #region 注释右键菜单事件
  826. //高亮、下划线、删除
  827. private void HightAnnotCopyText_Menu(object obj)
  828. {
  829. if (obj as CusMenuItem != null)
  830. {
  831. var menu = obj as CusMenuItem;
  832. var annot = menu.Parameter as AnnotHandlerEventArgs;
  833. if (annot != null)
  834. {
  835. System.Windows.Clipboard.SetText(annot.Content);
  836. }
  837. }
  838. }
  839. //更改为当前注释属性默认值
  840. private void AnnotDefaultValues_Menu(object obj)
  841. {
  842. if (obj as CusMenuItem != null)
  843. {
  844. var menu = obj as CusMenuItem;
  845. var annot = menu.Parameter as AnnotHandlerEventArgs;
  846. if (annot != null)
  847. {
  848. if (annot is TextHighlightAnnotArgs)
  849. {
  850. var color = (annot as TextHighlightAnnotArgs).Color;
  851. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  852. HighLightColor = new SolidColorBrush(color);
  853. }
  854. else if (annot is TextUnderlineAnnotArgs)
  855. {
  856. var color = (annot as TextHighlightAnnotArgs).Color;
  857. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  858. UnderLineColor = new SolidColorBrush(color);
  859. }
  860. else if (annot is TextStrikeoutAnnotArgs)
  861. {
  862. var color = (annot as TextHighlightAnnotArgs).Color;
  863. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  864. StrikeoutColor = new SolidColorBrush(color);
  865. }
  866. else if (annot is FreehandAnnotArgs)
  867. {
  868. var color = (annot as FreehandAnnotArgs).InkColor;
  869. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  870. }
  871. else if (annot is FreeTextAnnotArgs)
  872. {
  873. var freeText = annot as FreeTextAnnotArgs;
  874. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  875. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  876. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  877. }
  878. else if (annot is StickyAnnotArgs)
  879. {
  880. var color = (annot as StickyAnnotArgs).Color;
  881. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  882. }
  883. else if (annot is SquareAnnotArgs)
  884. {
  885. var bgColor = (annot as SquareAnnotArgs).BgColor;
  886. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  887. var borderColor = (annot as SquareAnnotArgs).LineColor;
  888. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  889. }
  890. else if (annot is CircleAnnotArgs)
  891. {
  892. var bgColor = (annot as CircleAnnotArgs).BgColor;
  893. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  894. var borderColor = (annot as CircleAnnotArgs).LineColor;
  895. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  896. }
  897. else if (annot is LineAnnotArgs)
  898. {
  899. var color = (annot as LineAnnotArgs).LineColor;
  900. Settings.Default.AppProperties.Annotate.LineColor = color;
  901. }
  902. Settings.Default.Save();
  903. }
  904. }
  905. }
  906. //更改颜色
  907. private void AnnotColorPalette_Menu(object obj)
  908. {
  909. if (obj as CusMenuItem != null)
  910. {
  911. var menu = obj as CusMenuItem;
  912. var annot = menu.Parameter as AnnotHandlerEventArgs;
  913. if (annot != null)
  914. {
  915. var item = new ColorDropBoxPop();
  916. item.DataContext = annot;
  917. item.ColorSelected -= AnnotMenu_ColorSelected;
  918. item.ColorSelected += AnnotMenu_ColorSelected;
  919. System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();
  920. popup.Child = item;
  921. popup.PlacementRectangle = new Rect(Mouse.GetPosition(App.Current.MainWindow), new Size(item.Width, item.Height));
  922. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  923. popup.IsOpen = true;
  924. }
  925. }
  926. }
  927. private void AnnotMenu_ColorSelected(object sender, Color e)
  928. {
  929. if (sender != null)
  930. {
  931. var annot = (sender as FrameworkElement).DataContext as AnnotHandlerEventArgs;
  932. if (annot != null)
  933. {
  934. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  935. {
  936. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  937. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  938. AnnotEvent?.UpdateAnnot();
  939. }
  940. else if (annot is FreeTextAnnotArgs)
  941. {
  942. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  943. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  944. AnnotEvent?.UpdateAnnot();
  945. }
  946. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  947. {
  948. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  949. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  950. AnnotEvent?.UpdateAnnot();
  951. }
  952. }
  953. }
  954. }
  955. //添加笔记
  956. private void AnnotAddNoteText_Menu(object obj)
  957. {
  958. if (obj as CusMenuItem != null)
  959. {
  960. var menu = obj as CusMenuItem;
  961. var annot = menu.Parameter as AnnotHandlerEventArgs;
  962. if (annot != null)
  963. {
  964. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  965. args.ClientRect = annot.ClientRect;
  966. args.AnnotHandlerEventArgs = annot;
  967. args.PageIndex = annot.PageIndex;
  968. args.AnnotIndex = annot.AnnotIndex;
  969. args.EventType = annot.EventType;
  970. args.CreateTime = annot.CreateTime;
  971. args.UpdateTime = annot.UpdateTime;
  972. args.Content = annot.Content;
  973. args.MarkupContent = annot.MarkupContent;
  974. args.Author = annot.Author;
  975. args.Locked = annot.Locked;
  976. args.ReadOnly = annot.ReadOnly;
  977. args.FormField = annot.FormField;
  978. args.Document = PDFViewer.Document;
  979. DialogParameters value = new DialogParameters();
  980. value.Add(ParameterNames.Annotation, args);
  981. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  982. {
  983. if (e.Result == ButtonResult.OK && e.Parameters != null)
  984. {
  985. PDFViewer.UndoManager.CanSave = true;
  986. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  987. {
  988. }
  989. }
  990. });
  991. }
  992. }
  993. }
  994. //手绘
  995. private void FreeHandLineStyle_Menu(object obj)
  996. {
  997. if (obj as CusMenuItem != null)
  998. {
  999. var menu = obj as CusMenuItem;
  1000. var annot = menu.Parameter as FreehandAnnotArgs;
  1001. if (annot != null)
  1002. {
  1003. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1004. if (menu.tag.ToString() == "Solid")
  1005. {
  1006. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  1007. }
  1008. else
  1009. {
  1010. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  1011. }
  1012. AnnotEvent?.UpdateAnnot();
  1013. }
  1014. }
  1015. }
  1016. //文本
  1017. private void FreeTextFontFamily_Menu(object obj)
  1018. {
  1019. if (obj as CusMenuItem != null)
  1020. {
  1021. var menu = obj as CusMenuItem;
  1022. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1023. if (annot != null)
  1024. {
  1025. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1026. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1027. AnnotEvent?.UpdateAnnot();
  1028. }
  1029. }
  1030. }
  1031. private void FreeTextAglin_Menu(object obj)
  1032. {
  1033. if (obj as CusMenuItem != null)
  1034. {
  1035. var menu = obj as CusMenuItem;
  1036. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1037. var tag = menu.control.Tag;
  1038. if (annot != null && tag != null)
  1039. {
  1040. var strTag = tag.ToString();
  1041. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1042. if (strTag == "Left")
  1043. {
  1044. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1045. }
  1046. else if (strTag == "Center")
  1047. {
  1048. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1049. }
  1050. else if (strTag == "Right")
  1051. {
  1052. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1053. }
  1054. AnnotEvent?.UpdateAnnot();
  1055. }
  1056. }
  1057. }
  1058. //便签
  1059. private void StrikeNoteEditStrike_Menu(object obj)
  1060. {
  1061. if (obj as CusMenuItem != null)
  1062. {
  1063. var menu = obj as CusMenuItem;
  1064. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1065. if (annot != null)
  1066. {
  1067. List<AnnotHandlerEventArgs> list = new List<AnnotHandlerEventArgs>();
  1068. list.Add(annot);
  1069. GetStickyNote(list);
  1070. annot.Author = Settings.Default.AppProperties.Description.Author;
  1071. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1072. PDFViewer.SetToolParam(annot);
  1073. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1074. //isRightMenuAddAnnot = false;
  1075. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1076. }
  1077. }
  1078. }
  1079. //形状
  1080. private void ShapeLineStyle_Menu(object obj)
  1081. {
  1082. if (obj as CusMenuItem != null)
  1083. {
  1084. var menu = obj as CusMenuItem;
  1085. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1086. var tag = menu.control.Tag;
  1087. if (annot != null && tag != null)
  1088. {
  1089. var strTag = tag.ToString();
  1090. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1091. if (strTag == "Solid")
  1092. {
  1093. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1094. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1095. }
  1096. else
  1097. {
  1098. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1099. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1100. }
  1101. AnnotEvent?.UpdateAnnot();
  1102. }
  1103. }
  1104. }
  1105. private void ShapeLineDirect_Menu(object obj)
  1106. {
  1107. if (obj as CusMenuItem != null)
  1108. {
  1109. var menu = obj as CusMenuItem;
  1110. var annot = menu.Parameter as LineAnnotArgs;
  1111. var tag = menu.control.Tag;
  1112. if (annot != null && tag != null)
  1113. {
  1114. var strTag = tag.ToString();
  1115. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1116. if (strTag == "ver")
  1117. {
  1118. annot.SetLineVertical();
  1119. }
  1120. else
  1121. {
  1122. annot.SetLineHorizontal();
  1123. }
  1124. }
  1125. }
  1126. }
  1127. //图章
  1128. private void StampExportPicture_Menu(object obj)
  1129. {
  1130. if (obj as CusMenuItem != null)
  1131. {
  1132. var menu = obj as CusMenuItem;
  1133. var annot = menu.Parameter as StampAnnotArgs;
  1134. if (annot != null)
  1135. {
  1136. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1137. var format = menu.tag.ToString();
  1138. if (format == "PDF")
  1139. dlg.Filter = "PDF|*.pdf";
  1140. else
  1141. dlg.Filter = format + "|*." + format.ToLower();
  1142. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1143. dlg.FileName = PDFViewer.Document.FileName;
  1144. if (dlg.ShowDialog() == true)
  1145. {
  1146. var stampPicture = dlg.FileName;
  1147. if (menu.tag.ToString() == "PDF")
  1148. {
  1149. var writeStamp = annot.GetStampDrawing();
  1150. var tempDoc = new CPDFViewer();
  1151. tempDoc.CreateDocument();
  1152. if (tempDoc.Document == null)
  1153. {
  1154. AlertsMessage alertsMessage = new AlertsMessage();
  1155. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1156. return;
  1157. }
  1158. byte[] buffer;
  1159. var encoder = new PngBitmapEncoder();
  1160. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1161. using (var memoryStream = new MemoryStream())
  1162. {
  1163. encoder.Save(memoryStream);
  1164. buffer = memoryStream.ToArray();
  1165. }
  1166. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1167. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1168. if (result)
  1169. {
  1170. }
  1171. }
  1172. else
  1173. {
  1174. var writeStamp = annot.GetStampDrawing();
  1175. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1176. {
  1177. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1178. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1179. encoder5.Save(stream5);
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. #endregion 注释右键菜单事件
  1187. #endregion 菜单
  1188. }
  1189. }