AnnotToolContentViewModel.Function.cs 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  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. ShowPropertyPanel(true);
  881. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  882. //isRightMenuAddAnnot = true;
  883. //if (str != AddAnnotType.AnnotLink.ToString())
  884. //{
  885. // ShowPropertyPanel(false);
  886. //}
  887. //else
  888. //{
  889. // ShowPropertyPanel(true);
  890. //}
  891. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  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. stickyAnnotArgs.ClientRect = new Rect(annotCommand.TextRect.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
  948. stickyAnnotArgs.StickyNote = annotCommand.Text;
  949. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  950. break;
  951. case "Rect"://矩形
  952. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  953. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  954. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  955. break;
  956. case "Circle"://圆
  957. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  958. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  959. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  960. break;
  961. case "Line"://线
  962. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  963. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  964. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  965. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  966. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  967. break;
  968. case "Link"://链接
  969. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  970. linkArgs.ClientRect = annotCommand.TextRect;
  971. linkArgs.URI = string.Empty;
  972. linkArgs.LinkType = LINK_TYPE.GOTO;
  973. linkArgs.DestIndex = annotCommand.PageIndex;
  974. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  975. BtnLinkIsChecked = true;
  976. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  977. lists.Add(linkArgs);
  978. propertyPanel.IsAddLink = true;
  979. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  980. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  981. PDFViewer.SetToolParam(annotArgs);
  982. viewContentViewModel.IsPropertyOpen = true;
  983. break;
  984. case "OutLine":
  985. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  986. if (isTabItemAnnotation == false)
  987. {
  988. bOTAContent.TabItemOutLine.IsSelected = true;
  989. }
  990. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  991. if (outLineControlViewModel != null && outLineControl != null)
  992. {
  993. string str = null;
  994. if (string.IsNullOrEmpty(annotCommand.Text))
  995. {
  996. str = (annotCommand.PageIndex + 1).ToString();
  997. }
  998. else
  999. {
  1000. str = annotCommand.Text;
  1001. }
  1002. //App.Current.Dispatcher.BeginInvoke((System.Action)(() =>
  1003. //{
  1004. // OutlineNode outline = outLineControl.AddOutlineNode(str);
  1005. //}));
  1006. App.Current.Dispatcher.Invoke(() => outLineControl.AddOutlineNode(str));
  1007. //CPDFOutline result = outline.Outline;
  1008. //if (result != null)
  1009. //{
  1010. // outLineControlViewModel.SetTitle(result, str);
  1011. // outLineControlViewModel.Updata(false);
  1012. // //outLineControl.IsReName = true;
  1013. // //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
  1014. // //{
  1015. // // outLineControl.ReNameOutlineNode = outline;
  1016. // //}
  1017. //}
  1018. }
  1019. break;
  1020. case "ExportPicture":
  1021. ExportPicture_MenuItemClick();
  1022. break;
  1023. }
  1024. //ShowPropertyPanel(false);
  1025. }
  1026. }
  1027. private void ExportPicture_MenuItemClick()
  1028. {
  1029. //图片提取
  1030. try
  1031. {
  1032. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1033. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1034. foreach (int pageIndex in imageDict.Keys)
  1035. {
  1036. imageList = imageDict[pageIndex];
  1037. }
  1038. string path = PDFViewer.Document.FileName;
  1039. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1040. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1041. {
  1042. int i = 1;
  1043. int pagenum = 1;
  1044. string choosePath = folderDialog.SelectedPath;
  1045. string sPath = choosePath + "\\" + path + "_Extract Image";
  1046. sPath = GetExportPathName(sPath);
  1047. if (!Directory.Exists(sPath))
  1048. {
  1049. Directory.CreateDirectory(sPath);
  1050. }
  1051. if (Directory.Exists(sPath))
  1052. {
  1053. foreach (System.Drawing.Bitmap image in imageList)
  1054. {
  1055. foreach (var item in imageDict.Keys)
  1056. {
  1057. pagenum = item;
  1058. }
  1059. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1060. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1061. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1062. i++;
  1063. }
  1064. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1065. }
  1066. }
  1067. }
  1068. catch (Exception ex) { }
  1069. }
  1070. public string GetExportPathName(string path)
  1071. {
  1072. int i = 1;
  1073. string outpath = path;
  1074. while (Directory.Exists(outpath))
  1075. {
  1076. outpath = path + $"({i.ToString()})";
  1077. i++;
  1078. }
  1079. return outpath;
  1080. }
  1081. private string GetNum(int num)
  1082. {
  1083. if (num % 10 < 1)
  1084. {
  1085. return "00" + num.ToString();
  1086. }
  1087. if (num % 10 >= 1 && num % 10 < 10)
  1088. {
  1089. return "0" + num.ToString();
  1090. }
  1091. else
  1092. {
  1093. return num.ToString();
  1094. }
  1095. }
  1096. #region 注释右键菜单事件
  1097. //高亮、下划线、删除
  1098. private void HightAnnotCopyText_Menu(object obj)
  1099. {
  1100. if (obj as CusMenuItem != null)
  1101. {
  1102. var menu = obj as CusMenuItem;
  1103. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1104. if (annot != null)
  1105. {
  1106. System.Windows.Clipboard.SetText(annot.Content);
  1107. }
  1108. }
  1109. }
  1110. //更改为当前注释属性默认值
  1111. private void AnnotDefaultValues_Menu(object obj)
  1112. {
  1113. if (obj as CusMenuItem != null)
  1114. {
  1115. var menu = obj as CusMenuItem;
  1116. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1117. if (annot != null)
  1118. {
  1119. if (annot is TextHighlightAnnotArgs)
  1120. {
  1121. var color = (annot as TextHighlightAnnotArgs).Color;
  1122. HighLightColor = new SolidColorBrush(color);
  1123. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  1124. var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  1125. hightlight.ForgoundColor = color;
  1126. hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
  1127. SettingHelper.SetAnnotDefaultProperty(hightlight);
  1128. }
  1129. else if (annot is TextUnderlineAnnotArgs)
  1130. {
  1131. var color = (annot as TextUnderlineAnnotArgs).Color;
  1132. UnderLineColor = new SolidColorBrush(color);
  1133. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  1134. var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  1135. Underline.ForgoundColor = color;
  1136. Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
  1137. SettingHelper.SetAnnotDefaultProperty(Underline);
  1138. }
  1139. else if (annot is TextStrikeoutAnnotArgs)
  1140. {
  1141. var color = (annot as TextStrikeoutAnnotArgs).Color;
  1142. StrikeoutColor = new SolidColorBrush(color);
  1143. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  1144. var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  1145. Strikeout.ForgoundColor = color;
  1146. Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
  1147. SettingHelper.SetAnnotDefaultProperty(Strikeout);
  1148. }
  1149. else if (annot is FreehandAnnotArgs)
  1150. {
  1151. var freeHand = annot as FreehandAnnotArgs;
  1152. var color = freeHand.InkColor;
  1153. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  1154. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  1155. FreehandDefault.ForgoundColor = color;
  1156. FreehandDefault.Opacity = freeHand.Transparency;
  1157. FreehandDefault.Thickness = freeHand.LineWidth;
  1158. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  1159. if (isSolid)
  1160. {
  1161. FreehandDefault.DashArray = null;
  1162. }
  1163. else
  1164. {
  1165. FreehandDefault.DashArray = new List<double>();
  1166. foreach (var item in freeHand.LineDash.Dashes)
  1167. {
  1168. FreehandDefault.DashArray.Add(item);
  1169. }
  1170. }
  1171. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  1172. }
  1173. else if (annot is FreeTextAnnotArgs)
  1174. {
  1175. var freeText = annot as FreeTextAnnotArgs;
  1176. Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
  1177. Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
  1178. Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
  1179. var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  1180. FreeTextDefalut.ForgoundColor = freeText.FontColor;
  1181. FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
  1182. FreeTextDefalut.TextAlign = freeText.Align;
  1183. FreeTextDefalut.FontSize = freeText.FontSize;
  1184. FreeTextDefalut.FontWeight = freeText.FontWeight;
  1185. FreeTextDefalut.FontStyle = freeText.FontStyle;
  1186. FreeTextDefalut.BackgroundColor = freeText.BgColor;
  1187. FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
  1188. SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
  1189. }
  1190. else if (annot is StickyAnnotArgs)
  1191. {
  1192. var color = (annot as StickyAnnotArgs).Color;
  1193. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  1194. var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  1195. StickyDefalut.ForgoundColor = color;
  1196. SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
  1197. }
  1198. else if (annot is SquareAnnotArgs)
  1199. {
  1200. var square = annot as SquareAnnotArgs;
  1201. var bgColor = square.BgColor;
  1202. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  1203. var borderColor = square.LineColor;
  1204. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  1205. var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  1206. SquareDefalut.BorderColor = borderColor;
  1207. SquareDefalut.BackgroundColor = bgColor;
  1208. SquareDefalut.Opacity = square.Transparency;
  1209. SquareDefalut.Thickness = square.LineWidth;
  1210. var isSolid = AnnotPropertyPanel.IsSolidStyle(square.LineDash);
  1211. if (isSolid)
  1212. {
  1213. SquareDefalut.DashArray = null;
  1214. }
  1215. else
  1216. {
  1217. SquareDefalut.DashArray = new List<double>();
  1218. foreach (var item in square.LineDash.Dashes)
  1219. {
  1220. SquareDefalut.DashArray.Add(item);
  1221. }
  1222. }
  1223. SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
  1224. }
  1225. else if (annot is CircleAnnotArgs)
  1226. {
  1227. var circle = annot as CircleAnnotArgs;
  1228. var bgColor = circle.BgColor;
  1229. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  1230. var borderColor = circle.LineColor;
  1231. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  1232. var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
  1233. CircleDefalut.BorderColor = borderColor;
  1234. CircleDefalut.BackgroundColor = bgColor;
  1235. CircleDefalut.Opacity = circle.Transparency;
  1236. CircleDefalut.Thickness = circle.LineWidth;
  1237. var isSolid = AnnotPropertyPanel.IsSolidStyle(circle.LineDash);
  1238. if (isSolid)
  1239. {
  1240. CircleDefalut.DashArray = null;
  1241. }
  1242. else
  1243. {
  1244. CircleDefalut.DashArray = new List<double>();
  1245. foreach (var item in circle.LineDash.Dashes)
  1246. {
  1247. CircleDefalut.DashArray.Add(item);
  1248. }
  1249. }
  1250. SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
  1251. }
  1252. else if (annot is LineAnnotArgs)
  1253. {
  1254. var line = (annot as LineAnnotArgs);
  1255. var color = (annot as LineAnnotArgs).LineColor;
  1256. Settings.Default.AppProperties.Annotate.LineColor = color;
  1257. var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
  1258. lineDefalut.BorderColor = color;
  1259. lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
  1260. lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
  1261. var isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
  1262. if (isSolid)
  1263. {
  1264. lineDefalut.DashArray = null;
  1265. }
  1266. else
  1267. {
  1268. lineDefalut.DashArray = new List<double>();
  1269. foreach (var item in line.LineDash.Dashes)
  1270. {
  1271. lineDefalut.DashArray.Add(item);
  1272. }
  1273. }
  1274. SettingHelper.SetAnnotDefaultProperty(lineDefalut);
  1275. }
  1276. Settings.Default.Save();
  1277. }
  1278. }
  1279. }
  1280. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  1281. {
  1282. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  1283. if (Annot == null)
  1284. {
  1285. Annot = new DefaultAnnotProperty();
  1286. Annot.AnnotToolType = annotArgsType;
  1287. }
  1288. return Annot;
  1289. }
  1290. private System.Windows.Controls.Primitives.Popup popup = null;
  1291. //更改颜色
  1292. private async void AnnotColorPalette_Menu(object obj)
  1293. {
  1294. if (obj as CusMenuItem != null)
  1295. {
  1296. var menu = obj as CusMenuItem;
  1297. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1298. if (annot != null)
  1299. {
  1300. var item = new ColorDropBoxPop();
  1301. item.DataContext = menu;
  1302. item.ColorSelected -= AnnotMenu_ColorSelected;
  1303. item.ColorSelected += AnnotMenu_ColorSelected;
  1304. if (popup == null)
  1305. popup = new System.Windows.Controls.Primitives.Popup();
  1306. ContentControl window = null;
  1307. if (PDFViewer.Parent as ContentControl != null)
  1308. window = PDFViewer.Parent as ContentControl;
  1309. else
  1310. window = App.Current.MainWindow;
  1311. popup.Child = item;
  1312. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  1313. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  1314. popup.PlacementTarget = window;
  1315. popup.IsOpen = true;
  1316. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  1317. if (parentWnd != null)
  1318. {
  1319. parentWnd.MouseDown -= parentWnd_MouseDown;
  1320. parentWnd.MouseDown += parentWnd_MouseDown;
  1321. }
  1322. while (popup.IsOpen)
  1323. await Task.Delay(20);
  1324. parentWnd.MouseDown -= parentWnd_MouseDown;
  1325. popup = null;
  1326. }
  1327. }
  1328. }
  1329. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  1330. {
  1331. var ui = Mouse.DirectlyOver as FrameworkElement;
  1332. if (ui != null)
  1333. {
  1334. if (popup != null)
  1335. {
  1336. popup.IsOpen = false;
  1337. }
  1338. }
  1339. }
  1340. private void AnnotMenu_ColorSelected(object sender, Color e)
  1341. {
  1342. if (sender != null)
  1343. {
  1344. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  1345. if (menu == null) return;
  1346. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1347. if (annot != null)
  1348. {
  1349. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  1350. {
  1351. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1352. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1353. AnnotEvent?.UpdateAnnot();
  1354. }
  1355. else if (annot is FreeTextAnnotArgs)
  1356. {
  1357. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1358. if (menu.tag.ToString() == "FontColor")
  1359. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  1360. else
  1361. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1362. AnnotEvent?.UpdateAnnot();
  1363. }
  1364. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  1365. {
  1366. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1367. if (menu.tag.ToString() == "FillColor")
  1368. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  1369. else
  1370. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1371. AnnotEvent?.UpdateAnnot();
  1372. }
  1373. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  1374. {
  1375. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1376. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  1377. AnnotEvent?.UpdateAnnot();
  1378. }
  1379. }
  1380. }
  1381. }
  1382. //添加笔记
  1383. private void AnnotAddNoteText_Menu(object obj)
  1384. {
  1385. if (obj as CusMenuItem != null)
  1386. {
  1387. var menu = obj as CusMenuItem;
  1388. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1389. if (annot != null)
  1390. {
  1391. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  1392. args.ClientRect = annot.ClientRect;
  1393. args.AnnotHandlerEventArgs = annot;
  1394. args.PageIndex = annot.PageIndex;
  1395. args.AnnotIndex = annot.AnnotIndex;
  1396. args.EventType = annot.EventType;
  1397. args.CreateTime = annot.CreateTime;
  1398. args.UpdateTime = annot.UpdateTime;
  1399. args.Content = annot.Content;
  1400. args.MarkupContent = annot.MarkupContent;
  1401. args.Author = annot.Author;
  1402. args.Locked = annot.Locked;
  1403. args.ReadOnly = annot.ReadOnly;
  1404. args.FormField = annot.FormField;
  1405. args.Document = PDFViewer.Document;
  1406. DialogParameters value = new DialogParameters();
  1407. value.Add(ParameterNames.Annotation, args);
  1408. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1409. {
  1410. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1411. {
  1412. PDFViewer.UndoManager.CanSave = true;
  1413. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1414. {
  1415. }
  1416. }
  1417. });
  1418. }
  1419. }
  1420. }
  1421. //手绘
  1422. private void FreeHandLineStyle_Menu(object obj)
  1423. {
  1424. if (obj as CusMenuItem != null)
  1425. {
  1426. var menu = obj as CusMenuItem;
  1427. var annot = menu.Parameter as FreehandAnnotArgs;
  1428. if (annot != null)
  1429. {
  1430. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1431. if (menu.tag.ToString() == "Solid")
  1432. {
  1433. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
  1434. }
  1435. else
  1436. {
  1437. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
  1438. }
  1439. AnnotEvent?.UpdateAnnot();
  1440. }
  1441. }
  1442. }
  1443. //文本
  1444. private void FreeTextFontFamily_Menu(object obj)
  1445. {
  1446. if (obj as CusMenuItem != null)
  1447. {
  1448. var menu = obj as CusMenuItem;
  1449. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1450. if (annot != null)
  1451. {
  1452. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1453. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  1454. AnnotEvent?.UpdateAnnot();
  1455. }
  1456. }
  1457. }
  1458. private void FreeTextAglin_Menu(object obj)
  1459. {
  1460. if (obj as CusMenuItem != null)
  1461. {
  1462. var menu = obj as CusMenuItem;
  1463. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1464. var tag = menu.control.Tag;
  1465. if (annot != null && tag != null)
  1466. {
  1467. var strTag = tag.ToString();
  1468. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1469. if (strTag == "Left")
  1470. {
  1471. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1472. }
  1473. else if (strTag == "Center")
  1474. {
  1475. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1476. }
  1477. else if (strTag == "Right")
  1478. {
  1479. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1480. }
  1481. else if (strTag == "Justify")
  1482. {
  1483. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  1484. }
  1485. AnnotEvent?.UpdateAnnot();
  1486. }
  1487. }
  1488. }
  1489. //便签
  1490. private void StrikeNoteEditStrike_Menu(object obj)
  1491. {
  1492. if (obj as CusMenuItem != null)
  1493. {
  1494. var menu = obj as CusMenuItem;
  1495. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1496. if (annot != null)
  1497. {
  1498. List<AnnotHandlerEventArgs> list = new List<AnnotHandlerEventArgs>();
  1499. list.Add(annot);
  1500. GetStickyNote(list);
  1501. annot.Author = Settings.Default.AppProperties.Description.Author;
  1502. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1503. PDFViewer.SetToolParam(annot);
  1504. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1505. //isRightMenuAddAnnot = false;
  1506. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  1507. }
  1508. }
  1509. }
  1510. //形状
  1511. private void ShapeLineStyle_Menu(object obj)
  1512. {
  1513. if (obj as CusMenuItem != null)
  1514. {
  1515. var menu = obj as CusMenuItem;
  1516. var annot = menu.Parameter as AnnotHandlerEventArgs;
  1517. var tag = menu.control.Tag;
  1518. if (annot != null && tag != null)
  1519. {
  1520. var strTag = tag.ToString();
  1521. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1522. if (strTag == "Solid")
  1523. {
  1524. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1525. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1526. }
  1527. else
  1528. {
  1529. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1530. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1531. }
  1532. AnnotEvent?.UpdateAnnot();
  1533. }
  1534. }
  1535. }
  1536. private void ShapeLineDirect_Menu(object obj)
  1537. {
  1538. if (obj as CusMenuItem != null)
  1539. {
  1540. var menu = obj as CusMenuItem;
  1541. var annot = menu.Parameter as LineAnnotArgs;
  1542. var tag = menu.control.Tag;
  1543. if (annot != null && tag != null)
  1544. {
  1545. var strTag = tag.ToString();
  1546. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1547. if (strTag == "Ver")
  1548. {
  1549. annot.SetLineVertical();
  1550. }
  1551. else
  1552. {
  1553. annot.SetLineHorizontal();
  1554. }
  1555. }
  1556. }
  1557. }
  1558. private void Link_Menu(object obj)
  1559. {
  1560. if (obj is CusMenuItem menuItem)
  1561. {
  1562. if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
  1563. {
  1564. var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
  1565. if (result)
  1566. {
  1567. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1568. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1569. if (isTabItemAnnotation)
  1570. {
  1571. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1572. if (viewModel != null)
  1573. {
  1574. viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
  1575. }
  1576. }
  1577. }
  1578. }
  1579. }
  1580. }
  1581. //图章
  1582. private void StampExportPicture_Menu(object obj)
  1583. {
  1584. if (obj as CusMenuItem != null)
  1585. {
  1586. var menu = obj as CusMenuItem;
  1587. var annot = menu.Parameter as StampAnnotArgs;
  1588. if (annot != null)
  1589. {
  1590. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1591. var format = menu.tag.ToString();
  1592. if (format == "PDF")
  1593. dlg.Filter = "PDF|*.pdf";
  1594. else
  1595. dlg.Filter = format + "|*." + format.ToLower();
  1596. dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
  1597. dlg.FileName = PDFViewer.Document.FileName;
  1598. if (dlg.ShowDialog() == true)
  1599. {
  1600. var stampPicture = dlg.FileName;
  1601. if (menu.tag.ToString() == "PDF")
  1602. {
  1603. var writeStamp = annot.GetStampDrawing();
  1604. var tempDoc = new CPDFViewer();
  1605. tempDoc.CreateDocument();
  1606. if (tempDoc.Document == null)
  1607. {
  1608. AlertsMessage alertsMessage = new AlertsMessage();
  1609. alertsMessage.ShowDialog("", "创建文件失败.", "OK");
  1610. return;
  1611. }
  1612. byte[] buffer;
  1613. var encoder = new PngBitmapEncoder();
  1614. encoder.Frames.Add(BitmapFrame.Create(writeStamp));
  1615. using (var memoryStream = new MemoryStream())
  1616. {
  1617. encoder.Save(memoryStream);
  1618. buffer = memoryStream.ToArray();
  1619. }
  1620. tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
  1621. var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
  1622. if (result)
  1623. {
  1624. }
  1625. }
  1626. else
  1627. {
  1628. var writeStamp = annot.GetStampDrawing();
  1629. using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
  1630. {
  1631. PngBitmapEncoder encoder5 = new PngBitmapEncoder();
  1632. encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
  1633. encoder5.Save(stream5);
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. }
  1640. #endregion 注释右键菜单事件
  1641. #endregion 菜单
  1642. }
  1643. }