AnnotToolContentViewModel.Function.cs 53 KB

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