AnnotToolContentViewModel.Function.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  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.EventAggregators;
  10. using PDF_Office.Helper;
  11. using PDF_Office.Model;
  12. using PDF_Office.Model.BOTA;
  13. using PDF_Office.Properties;
  14. using PDF_Office.ViewModels.BOTA;
  15. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  16. using PDF_Office.Views.BOTA;
  17. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  18. using PDFSettings;
  19. using Prism.Mvvm;
  20. using Prism.Regions;
  21. using Prism.Services.Dialogs;
  22. using System;
  23. using System.Collections.Generic;
  24. using System.IO;
  25. using System.Linq;
  26. using System.Text;
  27. using System.Threading.Tasks;
  28. using System.Windows;
  29. using System.Windows.Controls;
  30. using System.Windows.Documents;
  31. using System.Windows.Forms;
  32. using System.Windows.Input;
  33. using System.Windows.Media;
  34. using System.Windows.Media.Imaging;
  35. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  36. using ContextMenu = System.Windows.Controls.ContextMenu;
  37. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  38. using MenuItem = System.Windows.Controls.MenuItem;
  39. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  40. namespace PDF_Office.ViewModels.Tools
  41. {
  42. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  43. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  44. {
  45. #region 初始化
  46. #region 初始化数据
  47. //初始化注释的属性值,并存在本地缓存数据集里
  48. private void InitDefaultValue()
  49. {
  50. InitToolBtnUI();
  51. }
  52. //注释工具按钮初始化时的属性值
  53. private void InitToolBtnUI()
  54. {
  55. InitAnnotHighlight();
  56. InitAnnotUnderline();
  57. InitAnnotSquiggly();
  58. InitAnnotStrikeout();
  59. }
  60. private void InitAnnotHighlight()
  61. {
  62. var annotate = Settings.Default.AppProperties.Annotate;
  63. if (annotate != null && annotate.HighLightColor != Colors.Transparent)
  64. {
  65. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  66. HighLightOpacity = 1;
  67. }
  68. else
  69. {
  70. HighLightColor = new SolidColorBrush(Colors.Red);
  71. HighLightOpacity = 1;
  72. }
  73. }
  74. private void InitAnnotUnderline()
  75. {
  76. var annotate = Settings.Default.AppProperties.Annotate;
  77. //避免默认值为透明度
  78. if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
  79. {
  80. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  81. HighLightOpacity = 1;
  82. }
  83. else
  84. {
  85. UnderLineColor = new SolidColorBrush(Colors.Red);
  86. UnderLineOpacity = 1;
  87. }
  88. }
  89. private void InitAnnotSquiggly()
  90. {
  91. var annotate = Settings.Default.AppProperties.Annotate;
  92. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  93. {
  94. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  95. SquigglyOpacity = 1;
  96. }
  97. else
  98. {
  99. SquigglyColor = new SolidColorBrush(Colors.Red);
  100. SquigglyOpacity = 1;
  101. }
  102. }
  103. private void InitAnnotStrikeout()
  104. {
  105. var annotate = Settings.Default.AppProperties.Annotate;
  106. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  107. {
  108. StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
  109. StrikeoutOpacity = 1;
  110. }
  111. else
  112. {
  113. StrikeoutColor = new SolidColorBrush(Colors.Red);
  114. StrikeoutOpacity = 1;
  115. }
  116. }
  117. //在xaml里引用
  118. public Dictionary<string, string> GetToolTipDict
  119. { get { return ToolTipDict; } }
  120. //用来记录选中、创建注释的标识
  121. private void InitToolDict()
  122. {
  123. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  124. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  125. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  126. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  127. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  128. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  129. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  130. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  131. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  132. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  133. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  134. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  135. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  136. }
  137. //注释工具按钮悬浮文案
  138. private void InitToolTipDict()
  139. {
  140. ToolTipDict.Add("Hand", "滚动工具");
  141. ToolTipDict.Add("BtnSelecttool", "内容选择工具");
  142. ToolTipDict.Add("SnapshotEdit", "内容选择工具");
  143. ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
  144. ToolTipDict.Add("UnderLine", "高亮" + " | Ctrl+Alt+U");
  145. ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
  146. ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
  147. ToolTipDict.Add("Freehand", "手绘");
  148. ToolTipDict.Add("Freetext", "文字");
  149. ToolTipDict.Add("StickyNote", "便签");
  150. ToolTipDict.Add("Rect", "矩形");
  151. ToolTipDict.Add("Circle", "圆");
  152. ToolTipDict.Add("Arrow", "箭头");
  153. ToolTipDict.Add("Line", "线条");
  154. ToolTipDict.Add("Link", "超链接");
  155. ToolTipDict.Add("Stamp", "图章");
  156. ToolTipDict.Add("Image", "图片");
  157. ToolTipDict.Add("Signature", "签名");
  158. ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
  159. }
  160. //便签批注弹窗
  161. private void LoaedStickyNotePopup()
  162. {
  163. if (PDFViewer == null) return;
  164. if (customStickyPopup == null)
  165. {
  166. customStickyPopup = new StickyNotePopup();
  167. PDFViewer.SetStickyNotePop(customStickyPopup);
  168. }
  169. }
  170. #endregion 初始化数据
  171. #endregion 初始化
  172. #region 注释工具
  173. //注释工具
  174. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  175. {
  176. switch (tag)
  177. {
  178. case "SnapshotEdit"://内容选择
  179. annotArgs = GetSnapshotEdit();
  180. break;
  181. case "HighLight"://字体高亮
  182. annotArgs = GetHighLight();
  183. break;
  184. case "UnderLine"://下划线
  185. annotArgs = GetUnderLine();
  186. break;
  187. case "Squiggly"://波浪线
  188. annotArgs = GetSquiggly();
  189. break;
  190. case "Strikeout"://删除线
  191. annotArgs = GetStrikeout();
  192. break;
  193. case "Freehand"://手绘
  194. annotArgs = GetFreehand();
  195. break;
  196. case "Freetext"://文本
  197. annotArgs = GetFreetext();
  198. break;
  199. case "StickyNote"://便签
  200. annotArgs = GetStickyNote();
  201. break;
  202. case "Rect"://矩形
  203. annotArgs = GetRect();
  204. break;
  205. case "Circle"://圆
  206. annotArgs = GetCircle();
  207. break;
  208. case "Arrow"://箭头
  209. case "Line"://线
  210. annotArgs = GetArrowLine(tag);
  211. break;
  212. case "Stamp"://图章
  213. annotArgs = GetStamp();
  214. break;
  215. case "Image":
  216. annotArgs = GetImage();
  217. break;
  218. case "Signature"://签名
  219. annotArgs = GetSignature();
  220. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  221. break;
  222. case "Link"://链接
  223. propertyPanel.IsAddLink = true;
  224. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  225. annotArgs = GetLink();
  226. break;
  227. }
  228. if (annotArgs != null)
  229. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  230. }
  231. /// <summary>
  232. /// 高亮注释
  233. /// </summary>
  234. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  235. {
  236. TextHighlightAnnotArgs highlightArgs = null;
  237. if (selectedArgs == null || selectedArgs.Count == 0)
  238. {
  239. highlightArgs = new TextHighlightAnnotArgs();
  240. highlightArgs.Transparency = highLightOpacity;
  241. highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
  242. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
  243. if (defaultAnnot == null)
  244. {
  245. defaultAnnot = new DefaultAnnotProperty();
  246. defaultAnnot.AnnotToolType = highlightArgs.EventType;
  247. defaultAnnot.ForgoundColor = (highLightColor as SolidColorBrush).Color;
  248. defaultAnnot.Opacity = 1;
  249. Settings.Default.Save();
  250. }
  251. highLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
  252. selectedArgs = new List<AnnotHandlerEventArgs>();
  253. selectedArgs.Add(highlightArgs);
  254. }
  255. else
  256. {
  257. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  258. }
  259. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
  260. return highlightArgs;
  261. }
  262. /// <summary>
  263. /// 链接
  264. /// </summary>
  265. /// <param name="selectedArgs">所选中的注释</param>
  266. /// <param name="annotAttribEvent">注释属性列表</param>
  267. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  268. {
  269. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  270. if (selectedArgs != null && selectedArgs.Count > 0)
  271. {
  272. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  273. }
  274. else
  275. {
  276. linkArgs.URI = string.Empty;
  277. linkArgs.LinkType = LINK_TYPE.GOTO;
  278. linkArgs.DestIndex = -1;
  279. if (linkArgs != null)
  280. {
  281. selectedArgs = new List<AnnotHandlerEventArgs>();
  282. selectedArgs.Add(linkArgs);
  283. }
  284. }
  285. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  286. return linkArgs;
  287. }
  288. /// <summary>
  289. /// 下划线
  290. /// </summary>
  291. /// <param name="selectedArgs"></param>
  292. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  293. {
  294. TextUnderlineAnnotArgs underlineArgs = null;
  295. if (selectedArgs == null || selectedArgs.Count == 0)
  296. {
  297. underlineArgs = new TextUnderlineAnnotArgs();
  298. underlineArgs.Transparency = UnderLineOpacity;
  299. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  300. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
  301. if (defaultAnnot == null)
  302. {
  303. defaultAnnot = new DefaultAnnotProperty();
  304. defaultAnnot.AnnotToolType = underlineArgs.EventType;
  305. defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
  306. defaultAnnot.Opacity = 1;
  307. Settings.Default.Save();
  308. }
  309. UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
  310. selectedArgs = new List<AnnotHandlerEventArgs>();
  311. selectedArgs.Add(underlineArgs);
  312. }
  313. else
  314. {
  315. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  316. }
  317. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  318. return underlineArgs;
  319. }
  320. /// <summary>
  321. /// 波浪线
  322. /// </summary>
  323. /// <param name="selectedArgs"></param>
  324. /// <returns></returns>
  325. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  326. {
  327. TextSquigglyAnnotArgs squigglyArgs = null;
  328. if (selectedArgs == null || selectedArgs.Count == 0)
  329. {
  330. squigglyArgs = new TextSquigglyAnnotArgs();
  331. squigglyArgs.Transparency = SquigglyOpacity;
  332. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  333. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
  334. if (defaultAnnot == null)
  335. {
  336. defaultAnnot = new DefaultAnnotProperty();
  337. defaultAnnot.AnnotToolType = squigglyArgs.EventType;
  338. defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
  339. defaultAnnot.Opacity = 1;
  340. Settings.Default.Save();
  341. }
  342. SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
  343. selectedArgs = new List<AnnotHandlerEventArgs>();
  344. selectedArgs.Add(squigglyArgs);
  345. }
  346. else
  347. {
  348. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  349. }
  350. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  351. return squigglyArgs;
  352. }
  353. /// <summary>
  354. /// 删除线
  355. /// </summary>
  356. /// <param name="selectedArgs"></param>
  357. /// <returns></returns>
  358. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  359. {
  360. TextStrikeoutAnnotArgs strikeoutArgs = null;
  361. if (selectedArgs == null || selectedArgs.Count == 0)
  362. {
  363. strikeoutArgs = new TextStrikeoutAnnotArgs();
  364. strikeoutArgs.Transparency = strikeoutOpacity;
  365. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  366. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
  367. if (defaultAnnot == null)
  368. {
  369. defaultAnnot = new DefaultAnnotProperty();
  370. defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
  371. defaultAnnot.ForgoundColor = (strikeoutColor as SolidColorBrush).Color;
  372. defaultAnnot.Opacity = 1;
  373. Settings.Default.Save();
  374. }
  375. strikeoutArgs.Transparency = defaultAnnot.Opacity;
  376. selectedArgs = new List<AnnotHandlerEventArgs>();
  377. selectedArgs.Add(strikeoutArgs);
  378. }
  379. else
  380. {
  381. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  382. }
  383. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  384. return strikeoutArgs;
  385. }
  386. /// <summary>
  387. /// 手绘
  388. /// </summary>
  389. /// <param name="selectedArgs"></param>
  390. /// <returns></returns>
  391. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  392. {
  393. FreehandAnnotArgs freehandArgs = null;
  394. if (selectedArgs == null || selectedArgs.Count == 0)
  395. {
  396. freehandArgs = new FreehandAnnotArgs();
  397. var annotate = Settings.Default.AppProperties.Annotate;
  398. if (annotate != null)
  399. {
  400. freehandArgs.InkColor = annotate.FreeHandColor;
  401. }
  402. else
  403. {
  404. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  405. }
  406. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
  407. if (defaultAnnot == null)
  408. {
  409. defaultAnnot = new DefaultAnnotProperty();
  410. defaultAnnot.AnnotToolType = freehandArgs.EventType;
  411. defaultAnnot.ForgoundColor = annotate.FreeHandColor;
  412. defaultAnnot.Opacity = 1;
  413. Settings.Default.Save();
  414. }
  415. freehandArgs.Transparency = defaultAnnot.Opacity;
  416. freehandArgs.LineWidth = defaultAnnot.Thickness;
  417. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  418. {
  419. freehandArgs.LineDash = DashStyles.Solid;
  420. }
  421. else
  422. {
  423. var collect = new DoubleCollection();
  424. foreach (var item in defaultAnnot.DashArray)
  425. {
  426. collect.Add(item);
  427. }
  428. if (freehandArgs.LineDash == null)
  429. freehandArgs.LineDash = new DashStyle();
  430. freehandArgs.LineDash.Dashes = collect;
  431. }
  432. selectedArgs = new List<AnnotHandlerEventArgs>();
  433. selectedArgs.Add(freehandArgs);
  434. }
  435. else
  436. {
  437. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  438. }
  439. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  440. return freehandArgs;
  441. }
  442. /// <summary>
  443. /// 文本
  444. /// </summary>
  445. /// <param name="selectedArgs"></param>
  446. /// <returns></returns>
  447. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  448. {
  449. FreeTextAnnotArgs freetextArgs = null;
  450. TextAlignment textAlignment;
  451. if (selectedArgs == null || selectedArgs.Count == 0)
  452. {
  453. freetextArgs = new FreeTextAnnotArgs();
  454. var annotate = Settings.Default.AppProperties.Annotate;
  455. if (annotate != null)
  456. {
  457. freetextArgs.FontColor = annotate.TextAnnoteColor;
  458. }
  459. else
  460. {
  461. freetextArgs.FontColor = Colors.Black;
  462. }
  463. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  464. if (defaultAnnot == null)
  465. {
  466. defaultAnnot = new DefaultAnnotProperty();
  467. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  468. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  469. defaultAnnot.BorderColor = Colors.Transparent;
  470. defaultAnnot.BackgroundColor = Colors.Transparent;
  471. defaultAnnot.Opacity = 1;
  472. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  473. defaultAnnot.FontSize = 14;
  474. defaultAnnot.TextAlign = TextAlignment.Left;
  475. defaultAnnot.Thickness = 0;
  476. defaultAnnot.NoteText = string.Empty;
  477. Settings.Default.Save();
  478. }
  479. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  480. freetextArgs.LineColor = defaultAnnot.BorderColor;
  481. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  482. freetextArgs.Transparency = defaultAnnot.Opacity;
  483. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  484. freetextArgs.FontSize = defaultAnnot.FontSize;
  485. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  486. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  487. freetextArgs.LineWidth = defaultAnnot.Thickness;
  488. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  489. if (align == 0)
  490. textAlignment = TextAlignment.Left;
  491. else if (align == 1)
  492. textAlignment = TextAlignment.Center;
  493. else
  494. textAlignment = TextAlignment.Right;
  495. freetextArgs.Align = textAlignment;
  496. if (freetextArgs != null)
  497. {
  498. selectedArgs = new List<AnnotHandlerEventArgs>();
  499. selectedArgs.Add(freetextArgs);
  500. }
  501. }
  502. else
  503. {
  504. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  505. textAlignment = freetextArgs.Align;
  506. }
  507. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  508. return freetextArgs;
  509. }
  510. /// <summary>
  511. /// 便签
  512. /// </summary>
  513. /// <param name="selectedArgs"></param>
  514. /// <returns></returns>
  515. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  516. {
  517. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  518. if (selectedArgs == null || selectedArgs.Count == 0)
  519. {
  520. var annotate = Settings.Default.AppProperties.Annotate;
  521. if (annotate != null)
  522. {
  523. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  524. }
  525. else
  526. {
  527. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  528. }
  529. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  530. if (defaultAnnot == null)
  531. {
  532. defaultAnnot = new DefaultAnnotProperty();
  533. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  534. defaultAnnot.NoteText = string.Empty;
  535. defaultAnnot.Opacity = 1;
  536. Settings.Default.Save();
  537. }
  538. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  539. if (stickyAnnotArgs != null)
  540. {
  541. selectedArgs = new List<AnnotHandlerEventArgs>();
  542. selectedArgs.Add(stickyAnnotArgs);
  543. }
  544. }
  545. else
  546. {
  547. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  548. }
  549. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  550. if (stickyAnnotArgs != null)
  551. stickyAnnotArgsList.Add(stickyAnnotArgs);
  552. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  553. return stickyAnnotArgs;
  554. }
  555. /// <summary>
  556. /// 矩形
  557. /// </summary>
  558. /// <param name="selectedArgs"></param>
  559. /// <returns></returns>
  560. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  561. {
  562. SquareAnnotArgs squareArgs = null;
  563. if (selectedArgs == null || selectedArgs.Count == 0)
  564. {
  565. squareArgs = new SquareAnnotArgs();
  566. var annotate = Settings.Default.AppProperties.Annotate;
  567. if (annotate != null)
  568. {
  569. squareArgs.BgColor = annotate.RectangleFillColor;
  570. squareArgs.LineColor = annotate.RectangleBorderColor;
  571. }
  572. else
  573. {
  574. squareArgs.LineColor = Colors.Red;
  575. squareArgs.BgColor = Colors.Red;
  576. }
  577. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  578. if (defaultAnnot == null)
  579. {
  580. defaultAnnot = new DefaultAnnotProperty();
  581. defaultAnnot.AnnotToolType = squareArgs.EventType;
  582. defaultAnnot.Thickness = 1;
  583. defaultAnnot.Opacity = 1;
  584. Settings.Default.Save();
  585. }
  586. squareArgs.LineWidth = defaultAnnot.Thickness;
  587. squareArgs.Transparency = defaultAnnot.Opacity;
  588. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  589. {
  590. squareArgs.LineDash = DashStyles.Solid;
  591. }
  592. else
  593. {
  594. var collect = new DoubleCollection();
  595. foreach (var item in defaultAnnot.DashArray)
  596. {
  597. collect.Add(item);
  598. }
  599. if (squareArgs.LineDash == null)
  600. squareArgs.LineDash = new DashStyle();
  601. squareArgs.LineDash.Dashes = collect;
  602. }
  603. if (squareArgs != null)
  604. {
  605. selectedArgs = new List<AnnotHandlerEventArgs>();
  606. selectedArgs.Add(squareArgs);
  607. }
  608. }
  609. else
  610. {
  611. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  612. }
  613. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  614. return squareArgs;
  615. }
  616. /// <summary>
  617. /// 圆
  618. /// </summary>
  619. /// <param name="selectedArgs"></param>
  620. /// <returns></returns>
  621. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  622. {
  623. CircleAnnotArgs circleAnnotArgs = null;
  624. if (selectedArgs == null || selectedArgs.Count == 0)
  625. {
  626. circleAnnotArgs = new CircleAnnotArgs();
  627. var annotate = Settings.Default.AppProperties.Annotate;
  628. if (annotate != null)
  629. {
  630. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  631. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  632. }
  633. else
  634. {
  635. circleAnnotArgs.LineColor = Colors.Red;
  636. circleAnnotArgs.BgColor = Colors.Red;
  637. }
  638. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  639. if (defaultAnnot == null)
  640. {
  641. defaultAnnot = new DefaultAnnotProperty();
  642. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  643. defaultAnnot.Thickness = 1;
  644. defaultAnnot.Opacity = 1;
  645. defaultAnnot.NoteText = string.Empty;
  646. defaultAnnot.DashArray = null;
  647. Settings.Default.Save();
  648. }
  649. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  650. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  651. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  652. {
  653. circleAnnotArgs.LineDash = DashStyles.Solid;
  654. }
  655. else
  656. {
  657. var collect = new DoubleCollection();
  658. foreach (var item in defaultAnnot.DashArray)
  659. {
  660. collect.Add(item);
  661. }
  662. if (circleAnnotArgs.LineDash == null)
  663. circleAnnotArgs.LineDash = new DashStyle();
  664. circleAnnotArgs.LineDash.Dashes = collect;
  665. }
  666. if (circleAnnotArgs != null)
  667. {
  668. selectedArgs = new List<AnnotHandlerEventArgs>();
  669. selectedArgs.Add(circleAnnotArgs);
  670. }
  671. }
  672. else
  673. {
  674. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  675. }
  676. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  677. return circleAnnotArgs;
  678. }
  679. /// <summary>
  680. /// 箭头 线
  681. /// </summary>
  682. /// <param name="TagStr"></param>
  683. /// <param name="selectedArgs"></param>
  684. /// <returns></returns>
  685. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  686. {
  687. LineAnnotArgs lineArgs = new LineAnnotArgs();
  688. if (selectedArgs == null || selectedArgs.Count == 0)
  689. {
  690. var annotate = Settings.Default.AppProperties.Annotate;
  691. if (annotate != null)
  692. {
  693. lineArgs.LineColor = annotate.LineColor;
  694. }
  695. else
  696. {
  697. lineArgs.LineColor = Colors.Red;
  698. }
  699. lineArgs.LineColor = Colors.Red;
  700. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  701. if (TagStr == "Line")
  702. {
  703. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  704. }
  705. else
  706. {
  707. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  708. }
  709. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  710. if (defaultAnnot == null)
  711. {
  712. defaultAnnot = new DefaultAnnotProperty();
  713. defaultAnnot.AnnotToolType = lineArgs.EventType;
  714. defaultAnnot.Thickness = 1;
  715. defaultAnnot.Opacity = 1;
  716. defaultAnnot.NoteText = string.Empty;
  717. defaultAnnot.DashArray = null;
  718. Settings.Default.Save();
  719. }
  720. lineArgs.LineDash = DashStyles.Solid;
  721. lineArgs.LineWidth = defaultAnnot.Thickness;
  722. lineArgs.Transparency = defaultAnnot.Opacity;
  723. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  724. {
  725. lineArgs.LineDash = DashStyles.Solid;
  726. }
  727. else
  728. {
  729. var collect = new DoubleCollection();
  730. foreach (var item in defaultAnnot.DashArray)
  731. {
  732. collect.Add(item);
  733. }
  734. if (lineArgs.LineDash == null)
  735. lineArgs.LineDash = new DashStyle();
  736. lineArgs.LineDash.Dashes = collect;
  737. }
  738. if (lineArgs != null)
  739. {
  740. selectedArgs = new List<AnnotHandlerEventArgs>();
  741. selectedArgs.Add(lineArgs);
  742. }
  743. }
  744. else
  745. {
  746. lineArgs = selectedArgs[0] as LineAnnotArgs;
  747. }
  748. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  749. return lineArgs;
  750. }
  751. /// <summary>
  752. /// 图章
  753. /// </summary>
  754. /// <returns></returns>
  755. private AnnotHandlerEventArgs GetStamp()
  756. {
  757. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  758. stampAnnotArgs.Opacity = 1;
  759. stampAnnotArgs.StampText = "APPROVED";
  760. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  761. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  762. if (stampAnnotArgs != null)
  763. stampAnnotArgsList.Add(stampAnnotArgs);
  764. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  765. return stampAnnotArgs;
  766. }
  767. /// <summary>
  768. /// 签名
  769. /// </summary>
  770. /// <returns></returns>
  771. private AnnotHandlerEventArgs GetSignature()
  772. {
  773. AddToPropertyPanel("SignatureAnnotProperty");
  774. return null;
  775. }
  776. private AnnotHandlerEventArgs GetImage()
  777. {
  778. StampAnnotArgs stampArgs = new StampAnnotArgs();
  779. stampArgs.Opacity = 1;
  780. stampArgs.Type = StampType.IMAGE_STAMP;
  781. OpenFileDialog openFileDialog = new OpenFileDialog();
  782. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  783. if (openFileDialog.ShowDialog() == true)
  784. {
  785. stampArgs.ImagePath = openFileDialog.FileName;
  786. }
  787. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  788. if (stampArgs != null)
  789. stampArgsList.Add(stampArgs);
  790. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  791. return stampArgs;
  792. }
  793. /// <summary>
  794. /// 内容选择
  795. /// </summary>
  796. /// <param name="annotBtn"></param>
  797. /// <returns></returns>
  798. private AnnotHandlerEventArgs GetSnapshotEdit()
  799. {
  800. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  801. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  802. snapshotArgs.ControlPointColor = Colors.White;
  803. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  804. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  805. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  806. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  807. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  808. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  809. #region to do
  810. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  811. //snapshotArgs.ToolPanel = snapMenu;
  812. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  813. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  814. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  815. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  816. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  817. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  818. #endregion to do
  819. return snapshotArgs;
  820. }
  821. #endregion 注释工具
  822. #region 菜单
  823. /// <summary>
  824. /// 空白处-右键菜单-添加注释
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. private void AddAnnotation_Click(object sender)
  828. {
  829. if (sender is MenuItem menuItem)
  830. {
  831. AnnotHandlerEventArgs annotHandler = null;
  832. string str = menuItem.Tag.ToString();
  833. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  834. propertyPanel.IsAddLink = false;
  835. propertyPanel.IsLocationLink = false;
  836. if (str == AddAnnotType.AnnotFreehand.ToString())
  837. {
  838. annotHandler = GetFreehand();
  839. }
  840. if (str == AddAnnotType.AnnotFreeText.ToString())
  841. {
  842. annotHandler = GetFreetext();
  843. }
  844. if (str == AddAnnotType.AnnotSticky.ToString())
  845. {
  846. annotHandler = GetStickyNote();
  847. }
  848. if (str == AddAnnotType.AnnotSquare.ToString())
  849. {
  850. annotHandler = GetRect();
  851. }
  852. if (str == AddAnnotType.AnnotCircle.ToString())
  853. {
  854. annotHandler = GetCircle();
  855. }
  856. if (str == AddAnnotType.AnnotArrow.ToString())
  857. {
  858. annotHandler = GetArrowLine("Arrow");
  859. }
  860. if (str == AddAnnotType.AnnotLine.ToString())
  861. {
  862. annotHandler = GetArrowLine("Line");
  863. }
  864. if (str == AddAnnotType.AnnotLink.ToString())
  865. {
  866. propertyPanel.IsAddLink = true;
  867. annotHandler = GetLink();
  868. }
  869. if (str == AddAnnotType.AnnotStamp.ToString())
  870. {
  871. annotHandler = GetStamp();
  872. }
  873. if (str == AddAnnotType.AnnotAutograph.ToString())
  874. {
  875. annotHandler = GetSignature();
  876. }
  877. if (annotHandler != null)
  878. {
  879. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  880. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  881. PDFViewer.SetToolParam(annotHandler);
  882. //是否展开右侧面板 =>否(链接、图章、签名除外)
  883. ShowPropertyPanel(false);
  884. if (str == AddAnnotType.AnnotLink.ToString()
  885. || str == AddAnnotType.AnnotStamp.ToString()
  886. || str == AddAnnotType.AnnotAutograph.ToString()
  887. )
  888. {
  889. ShowPropertyPanel(true);
  890. }
  891. IsNoSelectMenu = true;
  892. }
  893. }
  894. }
  895. /// <summary>
  896. /// 选择文本、图片,右键菜单
  897. /// </summary>
  898. /// <param name="sender"></param>
  899. /// <param name="e"></param>
  900. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  901. {
  902. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  903. {
  904. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  905. switch (clickMenu.Tag.ToString())
  906. {
  907. case "HighLight"://字体高亮
  908. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  909. highlightArgs.ClientRect = annotCommand.TextRect;
  910. highlightArgs.Content = annotCommand.Text;
  911. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  912. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  913. PDFViewer.SetToolParam(highlightArgs);
  914. PDFViewer.SetMouseMode(MouseModes.PanTool);
  915. break;
  916. case "UnderLine"://下划线
  917. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  918. underlineArgs.ClientRect = annotCommand.TextRect;
  919. underlineArgs.Content = annotCommand.Text;
  920. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  921. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  922. PDFViewer.SetToolParam(underlineArgs);
  923. PDFViewer.SetMouseMode(MouseModes.PanTool);
  924. break;
  925. case "Strikeout"://删除线
  926. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  927. strikeoutArgs.ClientRect = annotCommand.TextRect;
  928. strikeoutArgs.Content = annotCommand.Text;
  929. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  930. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  931. PDFViewer.SetToolParam(strikeoutArgs);
  932. PDFViewer.SetMouseMode(MouseModes.PanTool);
  933. break;
  934. case "Freetext"://文本
  935. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  936. textArgs.ClientRect = annotCommand.TextRect;
  937. //textArgs.Transparency = 1;
  938. //textArgs.BgColor = Colors.Transparent;
  939. //textArgs.LineColor = Colors.Red;
  940. //textArgs.LineWidth = 2;
  941. textArgs.TextContent = annotCommand.Text;
  942. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  943. break;
  944. case "StickyNote"://便签
  945. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  946. //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  947. List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
  948. stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  949. stickyAnnotArgs.StickyNote = annotCommand.Text;
  950. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  951. customStickyPopup = new StickyNotePopup();
  952. PDFViewer.SetStickyNotePop(customStickyPopup);
  953. //customStickyPopup.GetCurrentAnnot = stickyAnnotArgs;
  954. //customStickyPopup.GetPDFViewer = PDFViewer;
  955. //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
  956. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  957. PDFViewer.SetToolParam(stickyAnnotArgs);
  958. PDFViewer.SetMouseMode(MouseModes.PanTool);
  959. break;
  960. case "Rect"://矩形
  961. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  962. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  963. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  964. break;
  965. case "Circle"://圆
  966. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  967. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  968. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  969. break;
  970. case "Line"://线
  971. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  972. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  973. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  974. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  975. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  976. break;
  977. case "Link"://链接
  978. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  979. linkArgs.ClientRect = annotCommand.TextRect;
  980. linkArgs.URI = string.Empty;
  981. linkArgs.LinkType = LINK_TYPE.GOTO;
  982. linkArgs.DestIndex = annotCommand.PageIndex;
  983. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  984. BtnLinkIsChecked = true;
  985. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  986. lists.Add(linkArgs);
  987. propertyPanel.IsAddLink = true;
  988. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  989. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  990. PDFViewer.SetToolParam(annotArgs);
  991. viewContentViewModel.IsPropertyOpen = true;
  992. break;
  993. case "OutLine":
  994. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  995. if (isTabItemAnnotation == false)
  996. {
  997. bOTAContent.TabItemOutLine.IsSelected = true;
  998. }
  999. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  1000. if (outLineControlViewModel != null && outLineControl != null)
  1001. {
  1002. string str = null;
  1003. if (string.IsNullOrEmpty(annotCommand.Text))
  1004. {
  1005. str = (annotCommand.PageIndex + 1).ToString();
  1006. }
  1007. else
  1008. {
  1009. str = annotCommand.Text;
  1010. }
  1011. outLineControl.AddOutlineNode(str);
  1012. }
  1013. break;
  1014. case "ExportPicture":
  1015. ExportPicture_MenuItemClick();
  1016. break;
  1017. }
  1018. //ShowPropertyPanel(false);
  1019. }
  1020. }
  1021. private void ExportPicture_MenuItemClick()
  1022. {
  1023. //图片提取
  1024. try
  1025. {
  1026. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1027. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1028. foreach (int pageIndex in imageDict.Keys)
  1029. {
  1030. imageList = imageDict[pageIndex];
  1031. }
  1032. string path = PDFViewer.Document.FileName;
  1033. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1034. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1035. {
  1036. int i = 1;
  1037. int pagenum = 1;
  1038. string choosePath = folderDialog.SelectedPath;
  1039. string sPath = choosePath + "\\" + path + "_Extract Image";
  1040. sPath = GetExportPathName(sPath);
  1041. if (!Directory.Exists(sPath))
  1042. {
  1043. Directory.CreateDirectory(sPath);
  1044. }
  1045. if (Directory.Exists(sPath))
  1046. {
  1047. foreach (System.Drawing.Bitmap image in imageList)
  1048. {
  1049. foreach (var item in imageDict.Keys)
  1050. {
  1051. pagenum = item;
  1052. }
  1053. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1054. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1055. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1056. i++;
  1057. }
  1058. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1059. }
  1060. }
  1061. }
  1062. catch (Exception ex) { }
  1063. }
  1064. public string GetExportPathName(string path)
  1065. {
  1066. int i = 1;
  1067. string outpath = path;
  1068. while (Directory.Exists(outpath))
  1069. {
  1070. outpath = path + $"({i.ToString()})";
  1071. i++;
  1072. }
  1073. return outpath;
  1074. }
  1075. private string GetNum(int num)
  1076. {
  1077. if (num % 10 < 1)
  1078. {
  1079. return "00" + num.ToString();
  1080. }
  1081. if (num % 10 >= 1 && num % 10 < 10)
  1082. {
  1083. return "0" + num.ToString();
  1084. }
  1085. else
  1086. {
  1087. return num.ToString();
  1088. }
  1089. }
  1090. #region 注释右键菜单事件
  1091. //高亮、下划线、删除
  1092. private void HightAnnotCopyText_Menu(object obj)
  1093. {
  1094. if (obj as CusMenuItem != null)
  1095. {
  1096. var menu = obj as CusMenuItem;
  1097. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1098. if (annot != null)
  1099. {
  1100. System.Windows.Clipboard.SetText(annot.Content);
  1101. }
  1102. }
  1103. }
  1104. //更改为当前注释属性默认值
  1105. private void AnnotDefaultValues_Menu(object obj)
  1106. {
  1107. if (obj as CusMenuItem != null)
  1108. {
  1109. var menu = obj as CusMenuItem;
  1110. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1111. if (annot != null)
  1112. {
  1113. if (annot is TextHighlightAnnotArgs)
  1114. {
  1115. var color = (annot as TextHighlightAnnotArgs).Color;
  1116. HighLightColor = new SolidColorBrush(color);
  1117. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  1118. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  1119. hightlight.ForgoundColor = color;
  1120. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  1121. SettingHelper.SetAnnotDefaultProperty(hightlight);
  1122. }
  1123. else if (annot is TextUnderlineAnnotArgs)
  1124. {
  1125. var color = (annot as TextUnderlineAnnotArgs).Color;
  1126. UnderLineColor = new SolidColorBrush(color);
  1127. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  1128. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  1129. Underline.ForgoundColor = color;
  1130. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  1131. SettingHelper.SetAnnotDefaultProperty(Underline);
  1132. }
  1133. else if (annot is TextStrikeoutAnnotArgs)
  1134. {
  1135. var color = (annot as TextStrikeoutAnnotArgs).Color;
  1136. StrikeoutColor = new SolidColorBrush(color);
  1137. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  1138. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  1139. Strikeout.ForgoundColor = color;
  1140. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  1141. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  1142. }
  1143. else if (annot is FreehandAnnotArgs)
  1144. {
  1145. var freeHand = annot as FreehandAnnotArgs;
  1146. var color = freeHand.InkColor;
  1147. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  1148. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  1149. FreehandDefault.ForgoundColor = color;
  1150. FreehandDefault.Opacity = freeHand.Transparency;
  1151. FreehandDefault.Thickness = freeHand.LineWidth;
  1152. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  1153. if (isSolid)
  1154. {
  1155. FreehandDefault.DashArray = null;
  1156. }
  1157. else
  1158. {
  1159. FreehandDefault.DashArray = new List<double>();
  1160. foreach (var item in freeHand.LineDash.Dashes)
  1161. {
  1162. FreehandDefault.DashArray.Add(item);
  1163. }
  1164. }
  1165. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  1166. }
  1167. else if (annot is FreeTextAnnotArgs)
  1168. {
  1169. var freeText = annot as FreeTextAnnotArgs;
  1170. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  1171. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  1172. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  1173. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  1174. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  1175. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  1176. FreeTextDefalut.TextAlign = freeText.Align;
  1177. FreeTextDefalut.FontSize = freeText.FontSize;
  1178. FreeTextDefalut.FontWeight = freeText.FontWeight;
  1179. FreeTextDefalut.FontStyle = freeText.FontStyle;
  1180. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  1181. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  1182. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  1183. }
  1184. else if (annot is StickyAnnotArgs)
  1185. {
  1186. var color = (annot as StickyAnnotArgs).Color;
  1187. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  1188. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  1189. StickyDefalut.ForgoundColor = color;
  1190. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  1191. }
  1192. else if (annot is SquareAnnotArgs)
  1193. {
  1194. var square = annot as SquareAnnotArgs;
  1195. var bgColor = square.BgColor;
  1196. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  1197. var borderColor = square.LineColor;
  1198. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1199. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1200. SquareDefalut.BorderColor = borderColor;
  1201. SquareDefalut.BackgroundColor = bgColor;
  1202. SquareDefalut.Opacity = square.Transparency;
  1203. SquareDefalut.Thickness = square.LineWidth;
  1204. var isSolid = AnnotPropertyPanel.IsSolidStyle(square.LineDash);
  1205. if (isSolid)
  1206. {
  1207. SquareDefalut.DashArray = null;
  1208. }
  1209. else
  1210. {
  1211. SquareDefalut.DashArray = new List<double>();
  1212. foreach (var item in square.LineDash.Dashes)
  1213. {
  1214. SquareDefalut.DashArray.Add(item);
  1215. }
  1216. }
  1217. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1218. }
  1219. else if (annot is CircleAnnotArgs)
  1220. {
  1221. var circle = annot as CircleAnnotArgs;
  1222. var bgColor = circle.BgColor;
  1223. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1224. var borderColor = circle.LineColor;
  1225. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1226. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1227. CircleDefalut.BorderColor = borderColor;
  1228. CircleDefalut.BackgroundColor = bgColor;
  1229. CircleDefalut.Opacity = circle.Transparency;
  1230. CircleDefalut.Thickness = circle.LineWidth;
  1231. var isSolid = AnnotPropertyPanel.IsSolidStyle(circle.LineDash);
  1232. if (isSolid)
  1233. {
  1234. CircleDefalut.DashArray = null;
  1235. }
  1236. else
  1237. {
  1238. CircleDefalut.DashArray = new List<double>();
  1239. foreach (var item in circle.LineDash.Dashes)
  1240. {
  1241. CircleDefalut.DashArray.Add(item);
  1242. }
  1243. }
  1244. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1245. }
  1246. else if (annot is LineAnnotArgs)
  1247. {
  1248. var line = (annot as LineAnnotArgs);
  1249. var color = (annot as LineAnnotArgs).LineColor;
  1250. Settings.Default.AppProperties.Annotate.LineColor = color;
  1251. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1252. lineDefalut.BorderColor = color;
  1253. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1254. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1255. var isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
  1256. if (isSolid)
  1257. {
  1258. lineDefalut.DashArray = null;
  1259. }
  1260. else
  1261. {
  1262. lineDefalut.DashArray = new List<double>();
  1263. foreach (var item in line.LineDash.Dashes)
  1264. {
  1265. lineDefalut.DashArray.Add(item);
  1266. }
  1267. }
  1268. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1269. }
  1270. Settings.Default.Save();
  1271. }
  1272. }
  1273. }
  1274. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1275. {
  1276. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1277. if (Annot == null)
  1278. {
  1279. Annot = new DefaultAnnotProperty();
  1280. Annot.AnnotToolType = annotArgsType;
  1281. }
  1282. return Annot;
  1283. }
  1284. private System.Windows.Controls.Primitives.Popup popup = null;
  1285. //更改颜色
  1286. private async void AnnotColorPalette_Menu(object obj)
  1287. {
  1288. if (obj as CusMenuItem != null)
  1289. {
  1290. var menu = obj as CusMenuItem;
  1291. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1292. if (annot != null)
  1293. {
  1294. var item = new ColorDropBoxPop();
  1295. item.DataContext = menu;
  1296. item.ColorSelected -= AnnotMenu_ColorSelected;
  1297. item.ColorSelected += AnnotMenu_ColorSelected;
  1298. if (popup == null)
  1299. popup = new System.Windows.Controls.Primitives.Popup();
  1300. ContentControl window = null;
  1301. if (PDFViewer.Parent as ContentControl != null)
  1302. window = PDFViewer.Parent as ContentControl;
  1303. else
  1304. window = App.Current.MainWindow;
  1305. popup.Child = item;
  1306. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1307. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1308. popup.PlacementTarget = window;
  1309. popup.IsOpen = true;
  1310. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1311. if (parentWnd != null)
  1312. {
  1313. parentWnd.MouseDown -= parentWnd_MouseDown;
  1314. parentWnd.MouseDown += parentWnd_MouseDown;
  1315. }
  1316. while (popup.IsOpen)
  1317. await Task.Delay(20);
  1318. parentWnd.MouseDown -= parentWnd_MouseDown;
  1319. popup = null;
  1320. }
  1321. }
  1322. }
  1323. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1324. {
  1325. var ui = Mouse.DirectlyOver as FrameworkElement;
  1326. if (ui != null)
  1327. {
  1328. if (popup != null)
  1329. {
  1330. popup.IsOpen = false;
  1331. }
  1332. }
  1333. }
  1334. private void AnnotMenu_ColorSelected(object sender, Color e)
  1335. {
  1336. if (sender != null)
  1337. {
  1338. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1339. if (menu == null) return;
  1340. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1341. if (annot != null)
  1342. {
  1343. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1344. {
  1345. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1346. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1347. AnnotEvent?.UpdateAnnot();
  1348. }
  1349. else if (annot is FreeTextAnnotArgs)
  1350. {
  1351. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1352. if (menu.tag.ToString() == "FontColor")
  1353. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1354. else
  1355. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1356. AnnotEvent?.UpdateAnnot();
  1357. }
  1358. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1359. {
  1360. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1361. if (menu.tag.ToString() == "FillColor")
  1362. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1363. else
  1364. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1365. AnnotEvent?.UpdateAnnot();
  1366. }
  1367. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1368. {
  1369. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1370. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1371. AnnotEvent?.UpdateAnnot();
  1372. }
  1373. }
  1374. }
  1375. }
  1376. //添加笔记
  1377. private void AnnotAddNoteText_Menu(object obj)
  1378. {
  1379. if (obj as CusMenuItem != null)
  1380. {
  1381. var menu = obj as CusMenuItem;
  1382. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1383. if (annot != null)
  1384. {
  1385. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1386. args.ClientRect = annot.ClientRect;
  1387. args.AnnotHandlerEventArgs = annot;
  1388. args.PageIndex = annot.PageIndex;
  1389. args.AnnotIndex = annot.AnnotIndex;
  1390. args.EventType = annot.EventType;
  1391. args.CreateTime = annot.CreateTime;
  1392. args.UpdateTime = annot.UpdateTime;
  1393. args.Content = annot.Content;
  1394. args.MarkupContent = annot.MarkupContent;
  1395. args.Author = annot.Author;
  1396. args.Locked = annot.Locked;
  1397. args.ReadOnly = annot.ReadOnly;
  1398. args.FormField = annot.FormField;
  1399. args.Document = PDFViewer.Document;
  1400. DialogParameters value = new DialogParameters();
  1401. value.Add(ParameterNames.Annotation, args);
  1402. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1403. {
  1404. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1405. {
  1406. PDFViewer.UndoManager.CanSave = true;
  1407. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1408. {
  1409. }
  1410. }
  1411. });
  1412. }
  1413. }
  1414. }
  1415. //手绘
  1416. private void FreeHandLineStyle_Menu(object obj)
  1417. {
  1418. if (obj as CusMenuItem != null)
  1419. {
  1420. var menu = obj as CusMenuItem;
  1421. var annot = menu.Parameter as FreehandAnnotArgs;
  1422. if (annot != null)
  1423. {
  1424. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1425. if (menu.tag.ToString() == "Solid")
  1426. {
  1427. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  1428. }
  1429. else
  1430. {
  1431. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  1432. }
  1433. AnnotEvent?.UpdateAnnot();
  1434. }
  1435. }
  1436. }
  1437. //文本
  1438. private void FreeTextFontFamily_Menu(object obj)
  1439. {
  1440. if (obj as CusMenuItem != null)
  1441. {
  1442. var menu = obj as CusMenuItem;
  1443. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1444. if (annot != null)
  1445. {
  1446. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1447. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1448. AnnotEvent?.UpdateAnnot();
  1449. }
  1450. }
  1451. }
  1452. private void FreeTextAglin_Menu(object obj)
  1453. {
  1454. if (obj as CusMenuItem != null)
  1455. {
  1456. var menu = obj as CusMenuItem;
  1457. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1458. var tag = menu.control.Tag;
  1459. if (annot != null && tag != null)
  1460. {
  1461. var strTag = tag.ToString();
  1462. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1463. if (strTag == "Left")
  1464. {
  1465. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1466. }
  1467. else if (strTag == "Center")
  1468. {
  1469. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1470. }
  1471. else if (strTag == "Right")
  1472. {
  1473. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1474. }
  1475. else if (strTag == "Justify")
  1476. {
  1477. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1478. }
  1479. AnnotEvent?.UpdateAnnot();
  1480. }
  1481. }
  1482. }
  1483. //便签
  1484. private void StrikeNoteEditStrike_Menu(object obj)
  1485. {
  1486. if (obj as CusMenuItem != null)
  1487. {
  1488. var menu = obj as CusMenuItem;
  1489. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1490. if (annot != null)
  1491. {
  1492. List<AnnotHandlerEventArgs> list = new List<AnnotHandlerEventArgs>();
  1493. list.Add(annot);
  1494. GetStickyNote(list);
  1495. annot.Author = Settings.Default.AppProperties.Description.Author;
  1496. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1497. PDFViewer.SetToolParam(annot);
  1498. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1499. //isRightMenuAddAnnot = false;
  1500. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1501. }
  1502. }
  1503. }
  1504. //形状
  1505. private void ShapeLineStyle_Menu(object obj)
  1506. {
  1507. if (obj as CusMenuItem != null)
  1508. {
  1509. var menu = obj as CusMenuItem;
  1510. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1511. var tag = menu.control.Tag;
  1512. if (annot != null && tag != null)
  1513. {
  1514. var strTag = tag.ToString();
  1515. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1516. if (strTag == "Solid")
  1517. {
  1518. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1519. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1520. }
  1521. else
  1522. {
  1523. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1524. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1525. }
  1526. AnnotEvent?.UpdateAnnot();
  1527. }
  1528. }
  1529. }
  1530. private void ShapeLineDirect_Menu(object obj)
  1531. {
  1532. if (obj as CusMenuItem != null)
  1533. {
  1534. var menu = obj as CusMenuItem;
  1535. var annot = menu.Parameter as LineAnnotArgs;
  1536. var tag = menu.control.Tag;
  1537. if (annot != null && tag != null)
  1538. {
  1539. var strTag = tag.ToString();
  1540. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1541. if (strTag == "Ver")
  1542. {
  1543. annot.SetLineVertical();
  1544. }
  1545. else
  1546. {
  1547. annot.SetLineHorizontal();
  1548. }
  1549. }
  1550. }
  1551. }
  1552. private void Link_Menu(object obj)
  1553. {
  1554. if (obj is CusMenuItem menuItem)
  1555. {
  1556. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1557. {
  1558. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1559. if (result)
  1560. {
  1561. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1562. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1563. if (isTabItemAnnotation)
  1564. {
  1565. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1566. if (viewModel != null)
  1567. {
  1568. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. //图章
  1576. private void StampExportPicture_Menu(object obj)
  1577. {
  1578. if (obj as CusMenuItem != null)
  1579. {
  1580. var menu = obj as CusMenuItem;
  1581. var annot = menu.Parameter as StampAnnotArgs;
  1582. if (annot != null)
  1583. {
  1584. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1585. var format = menu.tag.ToString();
  1586. if (format == "PDF")
  1587. dlg.Filter = "PDF|*.pdf";
  1588. else
  1589. dlg.Filter = format + "|*." + format.ToLower();
  1590. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1591. dlg.FileName = PDFViewer.Document.FileName;
  1592. if (dlg.ShowDialog() == true)
  1593. {
  1594. var stampPicture = dlg.FileName;
  1595. if (menu.tag.ToString() == "PDF")
  1596. {
  1597. var writeStamp = annot.GetStampDrawing();
  1598. var tempDoc = new CPDFViewer();
  1599. tempDoc.CreateDocument();
  1600. if (tempDoc.Document == null)
  1601. {
  1602. AlertsMessage alertsMessage = new AlertsMessage();
  1603. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1604. return;
  1605. }
  1606. byte[] buffer;
  1607. var encoder = new PngBitmapEncoder();
  1608. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1609. using (var memoryStream = new MemoryStream())
  1610. {
  1611. encoder.Save(memoryStream);
  1612. buffer = memoryStream.ToArray();
  1613. }
  1614. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1615. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1616. if (result)
  1617. {
  1618. }
  1619. }
  1620. else
  1621. {
  1622. var writeStamp = annot.GetStampDrawing();
  1623. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1624. {
  1625. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1626. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1627. encoder5.Save(stream5);
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. }
  1634. #endregion 注释右键菜单事件
  1635. #endregion 菜单
  1636. }
  1637. }