AnnotToolContentViewModel.Function.cs 71 KB

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