AnnotToolContentViewModel.Function.cs 75 KB

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