AnnotToolContentViewModel.Function.cs 75 KB

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