AnnotToolContentViewModel.Function.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Dropbox.Api.TeamLog;
  7. using Microsoft.Office.Core;
  8. using Microsoft.Win32;
  9. using PDF_Master.CustomControl;
  10. using PDF_Master.EventAggregators;
  11. using PDF_Master.Helper;
  12. using PDF_Master.Model;
  13. using PDF_Master.Model.BOTA;
  14. using PDF_Master.Properties;
  15. using PDF_Master.ViewModels.BOTA;
  16. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  17. using PDF_Master.ViewModels.Tools.AnnotManager;
  18. using PDF_Master.Views.BOTA;
  19. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  20. using PDFSettings;
  21. using Prism.Mvvm;
  22. using Prism.Regions;
  23. using Prism.Services.Dialogs;
  24. using System;
  25. using System.Collections.Generic;
  26. using System.IO;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading.Tasks;
  30. using System.Windows;
  31. using System.Windows.Controls;
  32. using System.Windows.Documents;
  33. using System.Windows.Forms;
  34. using System.Windows.Input;
  35. using System.Windows.Media;
  36. using System.Windows.Media.Imaging;
  37. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  38. using ContextMenu = System.Windows.Controls.ContextMenu;
  39. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  40. using MenuItem = System.Windows.Controls.MenuItem;
  41. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  42. namespace PDF_Master.ViewModels.Tools
  43. {
  44. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  45. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  46. {
  47. #region 初始化
  48. #region 初始化数据
  49. //初始化注释的属性值,并存在本地缓存数据集里
  50. private void InitDefaultValue()
  51. {
  52. InitToolBtnUI();
  53. }
  54. //注释工具按钮初始化时的属性值
  55. private void InitToolBtnUI()
  56. {
  57. InitAnnotHighlight();
  58. InitAnnotUnderline();
  59. InitAnnotSquiggly();
  60. InitAnnotStrikeout();
  61. }
  62. private void InitAnnotHighlight()
  63. {
  64. var annotate = Settings.Default.AppProperties.Annotate;
  65. if (annotate != null && annotate.HighLightColor != Colors.Transparent)
  66. {
  67. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  68. HighLightOpacity = 1;
  69. }
  70. else
  71. {
  72. HighLightColor = new SolidColorBrush(Colors.Red);
  73. HighLightOpacity = 1;
  74. }
  75. }
  76. private void InitAnnotUnderline()
  77. {
  78. var annotate = Settings.Default.AppProperties.Annotate;
  79. //避免默认值为透明度
  80. if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
  81. {
  82. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  83. HighLightOpacity = 1;
  84. }
  85. else
  86. {
  87. UnderLineColor = new SolidColorBrush(Colors.Red);
  88. UnderLineOpacity = 1;
  89. }
  90. }
  91. private void InitAnnotSquiggly()
  92. {
  93. var annotate = Settings.Default.AppProperties.Annotate;
  94. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  95. {
  96. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  97. SquigglyOpacity = 1;
  98. }
  99. else
  100. {
  101. SquigglyColor = new SolidColorBrush(Colors.Red);
  102. SquigglyOpacity = 1;
  103. }
  104. }
  105. private void InitAnnotStrikeout()
  106. {
  107. var annotate = Settings.Default.AppProperties.Annotate;
  108. if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
  109. {
  110. StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
  111. StrikeoutOpacity = 1;
  112. }
  113. else
  114. {
  115. StrikeoutColor = new SolidColorBrush(Colors.Red);
  116. StrikeoutOpacity = 1;
  117. }
  118. }
  119. //在xaml里引用
  120. public Dictionary<string, string> GetToolTipDict
  121. { get { return ToolTipDict; } }
  122. //用来记录选中、创建注释的标识
  123. private void InitToolDict()
  124. {
  125. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  126. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  127. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  128. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  129. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  130. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  131. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  132. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  133. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  134. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  135. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  136. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  137. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  138. }
  139. //注释工具按钮悬浮文案
  140. private void InitToolTipDict()
  141. {
  142. ToolTipDict.Add("Hand", "滚动工具");
  143. ToolTipDict.Add("BtnSelecttool", "内容选择工具");
  144. ToolTipDict.Add("SnapshotEdit", "内容选择工具");
  145. ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
  146. ToolTipDict.Add("UnderLine", "高亮" + " | Ctrl+Alt+U");
  147. ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
  148. ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
  149. ToolTipDict.Add("Freehand", "手绘");
  150. ToolTipDict.Add("Freetext", "文字");
  151. ToolTipDict.Add("StickyNote", "便签");
  152. ToolTipDict.Add("Rect", "矩形");
  153. ToolTipDict.Add("Circle", "圆");
  154. ToolTipDict.Add("Arrow", "箭头");
  155. ToolTipDict.Add("Line", "线条");
  156. ToolTipDict.Add("Link", "超链接");
  157. ToolTipDict.Add("Stamp", "图章");
  158. ToolTipDict.Add("Image", "图片");
  159. ToolTipDict.Add("Signature", "签名");
  160. ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
  161. }
  162. //便签批注弹窗
  163. private void LoaedStickyNotePopup()
  164. {
  165. if (PDFViewer == null) return;
  166. if (customStickyPopup == null)
  167. {
  168. customStickyPopup = new StickyNotePopup();
  169. PDFViewer.SetStickyNotePop(customStickyPopup);
  170. }
  171. }
  172. #endregion 初始化数据
  173. #endregion 初始化
  174. #region 注释工具
  175. //注释工具
  176. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  177. {
  178. switch (tag)
  179. {
  180. case "SnapshotEdit"://内容选择
  181. annotArgs = GetSnapshotEdit();
  182. break;
  183. case "HighLight"://字体高亮
  184. annotArgs = GetHighLight();
  185. break;
  186. case "UnderLine"://下划线
  187. annotArgs = GetUnderLine();
  188. break;
  189. case "Squiggly"://波浪线
  190. annotArgs = GetSquiggly();
  191. break;
  192. case "Strikeout"://删除线
  193. annotArgs = GetStrikeout();
  194. break;
  195. case "Freehand"://手绘
  196. annotArgs = GetFreehand();
  197. break;
  198. case "Freetext"://文本
  199. annotArgs = GetFreetext();
  200. break;
  201. case "StickyNote"://便签
  202. annotArgs = GetStickyNote();
  203. break;
  204. case "Rect"://矩形
  205. annotArgs = GetRect();
  206. break;
  207. case "Circle"://圆
  208. annotArgs = GetCircle();
  209. break;
  210. case "Arrow"://箭头
  211. case "Line"://线
  212. annotArgs = GetArrowLine(tag);
  213. break;
  214. case "Stamp"://图章
  215. //付费锁
  216. if (!App.IsLogin)
  217. {
  218. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  219. return;
  220. }
  221. annotArgs = GetStamp();
  222. break;
  223. case "Image":
  224. annotArgs = GetImage();
  225. break;
  226. case "Signature"://签名
  227. //付费锁
  228. if (!App.IsLogin)
  229. {
  230. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  231. return;
  232. }
  233. annotArgs = GetSignature();
  234. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  235. break;
  236. case "Link"://链接
  237. //付费锁
  238. if (!App.IsLogin)
  239. {
  240. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  241. return;
  242. }
  243. propertyPanel.IsAddLink = true;
  244. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  245. annotArgs = GetLink();
  246. break;
  247. }
  248. if (annotArgs != null)
  249. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  250. }
  251. //创建,选中,保留上次属性值的注释
  252. /// <summary>
  253. /// 高亮注释
  254. /// </summary>
  255. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  256. {
  257. TextHighlightAnnotArgs highlightArgs = null;
  258. if (selectedArgs == null || selectedArgs.Count == 0)
  259. {
  260. highlightArgs = new TextHighlightAnnotArgs();
  261. highlightArgs.Transparency = highLightOpacity;
  262. highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
  263. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotHighlight] == null)
  264. {
  265. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
  266. if (defaultAnnot == null)
  267. {
  268. defaultAnnot = new DefaultAnnotProperty();
  269. defaultAnnot.AnnotToolType = highlightArgs.EventType;
  270. defaultAnnot.ForgoundColor = (highLightColor as SolidColorBrush).Color;
  271. defaultAnnot.Opacity = 1;
  272. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  273. Settings.Default.Save();
  274. }
  275. highLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
  276. }
  277. else
  278. {
  279. }
  280. selectedArgs = new List<AnnotHandlerEventArgs>();
  281. selectedArgs.Add(highlightArgs);
  282. }
  283. else
  284. {
  285. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  286. }
  287. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
  288. return highlightArgs;
  289. }
  290. /// <summary>
  291. /// 链接
  292. /// </summary>
  293. /// <param name="selectedArgs">所选中的注释</param>
  294. /// <param name="annotAttribEvent">注释属性列表</param>
  295. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  296. {
  297. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  298. if (selectedArgs != null && selectedArgs.Count > 0)
  299. {
  300. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  301. }
  302. else
  303. {
  304. linkArgs.URI = string.Empty;
  305. linkArgs.LinkType = LINK_TYPE.GOTO;
  306. linkArgs.DestIndex = -1;
  307. if (linkArgs != null)
  308. {
  309. selectedArgs = new List<AnnotHandlerEventArgs>();
  310. selectedArgs.Add(linkArgs);
  311. }
  312. }
  313. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
  314. return linkArgs;
  315. }
  316. /// <summary>
  317. /// 下划线
  318. /// </summary>
  319. /// <param name="selectedArgs"></param>
  320. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  321. {
  322. TextUnderlineAnnotArgs underlineArgs = null;
  323. if (selectedArgs == null || selectedArgs.Count == 0)
  324. {
  325. underlineArgs = new TextUnderlineAnnotArgs();
  326. underlineArgs.Transparency = UnderLineOpacity;
  327. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  328. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotUnderline] == null)
  329. {
  330. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
  331. if (defaultAnnot == null)
  332. {
  333. defaultAnnot = new DefaultAnnotProperty();
  334. defaultAnnot.AnnotToolType = underlineArgs.EventType;
  335. defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
  336. defaultAnnot.Opacity = 1;
  337. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  338. Settings.Default.Save();
  339. }
  340. UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
  341. }
  342. selectedArgs = new List<AnnotHandlerEventArgs>();
  343. selectedArgs.Add(underlineArgs);
  344. }
  345. else
  346. {
  347. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  348. }
  349. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
  350. return underlineArgs;
  351. }
  352. /// <summary>
  353. /// 波浪线
  354. /// </summary>
  355. /// <param name="selectedArgs"></param>
  356. /// <returns></returns>
  357. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  358. {
  359. TextSquigglyAnnotArgs squigglyArgs = null;
  360. if (selectedArgs == null || selectedArgs.Count == 0)
  361. {
  362. squigglyArgs = new TextSquigglyAnnotArgs();
  363. squigglyArgs.Transparency = SquigglyOpacity;
  364. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  365. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquiggly] == null)
  366. {
  367. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
  368. if (defaultAnnot == null)
  369. {
  370. defaultAnnot = new DefaultAnnotProperty();
  371. defaultAnnot.AnnotToolType = squigglyArgs.EventType;
  372. defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
  373. defaultAnnot.Opacity = 1;
  374. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  375. Settings.Default.Save();
  376. }
  377. SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
  378. }
  379. selectedArgs = new List<AnnotHandlerEventArgs>();
  380. selectedArgs.Add(squigglyArgs);
  381. }
  382. else
  383. {
  384. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  385. }
  386. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
  387. return squigglyArgs;
  388. }
  389. /// <summary>
  390. /// 删除线
  391. /// </summary>
  392. /// <param name="selectedArgs"></param>
  393. /// <returns></returns>
  394. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  395. {
  396. TextStrikeoutAnnotArgs strikeoutArgs = null;
  397. if (selectedArgs == null || selectedArgs.Count == 0)
  398. {
  399. strikeoutArgs = new TextStrikeoutAnnotArgs();
  400. strikeoutArgs.Transparency = strikeoutOpacity;
  401. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  402. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotStrikeout] == null)
  403. {
  404. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
  405. if (defaultAnnot == null)
  406. {
  407. defaultAnnot = new DefaultAnnotProperty();
  408. defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
  409. defaultAnnot.ForgoundColor = (strikeoutColor as SolidColorBrush).Color;
  410. defaultAnnot.Opacity = 1;
  411. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  412. Settings.Default.Save();
  413. }
  414. strikeoutArgs.Transparency = defaultAnnot.Opacity;
  415. }
  416. selectedArgs = new List<AnnotHandlerEventArgs>();
  417. selectedArgs.Add(strikeoutArgs);
  418. }
  419. else
  420. {
  421. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  422. }
  423. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
  424. return strikeoutArgs;
  425. }
  426. /// <summary>
  427. /// 手绘
  428. /// </summary>
  429. /// <param name="selectedArgs"></param>
  430. /// <returns></returns>
  431. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  432. {
  433. FreehandAnnotArgs freehandArgs = null;
  434. if (selectedArgs == null || selectedArgs.Count == 0)
  435. {
  436. freehandArgs = new FreehandAnnotArgs();
  437. var annotate = Settings.Default.AppProperties.Annotate;
  438. if (annotate != null)
  439. {
  440. freehandArgs.InkColor = annotate.FreeHandColor;
  441. }
  442. else
  443. {
  444. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  445. }
  446. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] == null)
  447. {
  448. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
  449. if (defaultAnnot == null)
  450. {
  451. defaultAnnot = new DefaultAnnotProperty();
  452. defaultAnnot.AnnotToolType = freehandArgs.EventType;
  453. defaultAnnot.ForgoundColor = annotate.FreeHandColor;
  454. defaultAnnot.Opacity = 1;
  455. defaultAnnot.Thickness = 2;
  456. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  457. Settings.Default.Save();
  458. }
  459. freehandArgs.Transparency = defaultAnnot.Opacity;
  460. freehandArgs.LineWidth = defaultAnnot.Thickness;
  461. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  462. {
  463. freehandArgs.LineDash = DashStyles.Solid;
  464. }
  465. else
  466. {
  467. var collect = new DoubleCollection();
  468. foreach (var item in defaultAnnot.DashArray)
  469. {
  470. collect.Add(item);
  471. }
  472. if (freehandArgs.LineDash == null)
  473. freehandArgs.LineDash = new DashStyle();
  474. freehandArgs.LineDash.Dashes = collect;
  475. }
  476. }
  477. else
  478. {
  479. freehandArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
  480. }
  481. selectedArgs = new List<AnnotHandlerEventArgs>();
  482. selectedArgs.Add(freehandArgs);
  483. }
  484. else
  485. {
  486. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  487. if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
  488. {
  489. return freehandArgs;
  490. }
  491. }
  492. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  493. return freehandArgs;
  494. }
  495. /// <summary>
  496. /// 文本
  497. /// </summary>
  498. /// <param name="selectedArgs"></param>
  499. /// <returns></returns>
  500. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  501. {
  502. FreeTextAnnotArgs freetextArgs = null;
  503. TextAlignment textAlignment;
  504. if (selectedArgs == null || selectedArgs.Count == 0)
  505. {
  506. freetextArgs = new FreeTextAnnotArgs();
  507. var annotate = Settings.Default.AppProperties.Annotate;
  508. if (annotate != null)
  509. {
  510. freetextArgs.FontColor = annotate.TextAnnoteColor;
  511. }
  512. else
  513. {
  514. freetextArgs.FontColor = Colors.Black;
  515. }
  516. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] == null)
  517. {
  518. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  519. if (defaultAnnot == null)
  520. {
  521. defaultAnnot = new DefaultAnnotProperty();
  522. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  523. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  524. defaultAnnot.BorderColor = Colors.Transparent;
  525. defaultAnnot.BackgroundColor = Colors.Transparent;
  526. defaultAnnot.Opacity = 1;
  527. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  528. defaultAnnot.FontSize = 14;
  529. defaultAnnot.TextAlign = TextAlignment.Left;
  530. defaultAnnot.Thickness = 0;
  531. defaultAnnot.NoteText = string.Empty;
  532. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  533. Settings.Default.Save();
  534. }
  535. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  536. freetextArgs.LineColor = defaultAnnot.BorderColor;
  537. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  538. freetextArgs.Transparency = defaultAnnot.Opacity;
  539. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  540. freetextArgs.FontSize = defaultAnnot.FontSize;
  541. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  542. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  543. freetextArgs.LineWidth = defaultAnnot.Thickness;
  544. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  545. if (align == 0)
  546. textAlignment = TextAlignment.Left;
  547. else if (align == 1)
  548. textAlignment = TextAlignment.Center;
  549. else
  550. textAlignment = TextAlignment.Right;
  551. freetextArgs.Align = textAlignment;
  552. }
  553. else
  554. {
  555. freetextArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] as FreeTextAnnotArgs;
  556. freetextArgs.Content = string.Empty;
  557. freetextArgs.TextContent= string.Empty;
  558. }
  559. if (freetextArgs != null)
  560. {
  561. selectedArgs = new List<AnnotHandlerEventArgs>();
  562. selectedArgs.Add(freetextArgs);
  563. SelectTextCreateAnnot(freetextArgs);
  564. }
  565. }
  566. else
  567. {
  568. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  569. textAlignment = freetextArgs.Align;
  570. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  571. {
  572. return freetextArgs;
  573. }
  574. }
  575. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  576. return freetextArgs;
  577. }
  578. private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
  579. {
  580. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  581. if (selectList != null && selectList.Count > 0)
  582. {
  583. foreach (TextSelectNode selectNode in selectList)
  584. {
  585. FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
  586. Rect clientRect = Rect.Empty;
  587. foreach (Rect rawRect in selectNode.RawRect)
  588. {
  589. clientRect.Union(rawRect);
  590. }
  591. if (clientRect.IsEmpty == false)
  592. {
  593. clientRect = new Rect(
  594. clientRect.Left / 72D * 96D,
  595. clientRect.Top / 72D * 96D,
  596. clientRect.Width / 72D * 96D,
  597. clientRect.Height / 72D * 96D);
  598. textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
  599. //textArgs.Transparency = 1;
  600. //textArgs.BgColor = Colors.Transparent;
  601. //textArgs.LineColor = Colors.Red;
  602. //textArgs.LineWidth = 2;
  603. textArgs.Transparency = freeText.Transparency;
  604. textArgs.BgColor = freeText.BgColor;
  605. textArgs.LineColor = freeText.LineColor;
  606. textArgs.LineWidth = freeText.LineWidth;
  607. textArgs.TextContent = selectNode.SelectText;
  608. PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
  609. }
  610. break;
  611. }
  612. }
  613. }
  614. //Event导航到填写与签名的属性面板
  615. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  616. {
  617. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  618. {
  619. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  620. if (annotFillAndSign != null)
  621. {
  622. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  623. return true;
  624. }
  625. }
  626. return false;
  627. }
  628. private void FromFillAndSign(FillAndSigntEventArgs obj)
  629. {
  630. if (obj != null)
  631. {
  632. if (string.IsNullOrEmpty(obj.Action) == false)
  633. {
  634. if (obj.Action == "Clear")
  635. {
  636. viewContentViewModel.AnnotSignatures.Clear();
  637. }
  638. }
  639. }
  640. }
  641. /// <summary>
  642. /// 便签
  643. /// </summary>
  644. /// <param name="selectedArgs"></param>
  645. /// <returns></returns>
  646. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  647. {
  648. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  649. if (selectedArgs == null || selectedArgs.Count == 0)
  650. {
  651. var annotate = Settings.Default.AppProperties.Annotate;
  652. if (annotate != null)
  653. {
  654. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  655. }
  656. else
  657. {
  658. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  659. }
  660. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  661. {
  662. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  663. if (defaultAnnot == null)
  664. {
  665. defaultAnnot = new DefaultAnnotProperty();
  666. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  667. defaultAnnot.NoteText = string.Empty;
  668. defaultAnnot.Opacity = 1;
  669. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  670. Settings.Default.Save();
  671. }
  672. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  673. }
  674. else
  675. {
  676. stickyAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  677. }
  678. if (stickyAnnotArgs != null)
  679. {
  680. selectedArgs = new List<AnnotHandlerEventArgs>();
  681. selectedArgs.Add(stickyAnnotArgs);
  682. }
  683. }
  684. else
  685. {
  686. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  687. }
  688. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  689. if (stickyAnnotArgs != null)
  690. stickyAnnotArgsList.Add(stickyAnnotArgs);
  691. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  692. return stickyAnnotArgs;
  693. }
  694. /// <summary>
  695. /// 矩形
  696. /// </summary>
  697. /// <param name="selectedArgs"></param>
  698. /// <returns></returns>
  699. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  700. {
  701. SquareAnnotArgs squareArgs = null;
  702. if (selectedArgs == null || selectedArgs.Count == 0)
  703. {
  704. squareArgs = new SquareAnnotArgs();
  705. var annotate = Settings.Default.AppProperties.Annotate;
  706. if (annotate != null)
  707. {
  708. squareArgs.BgColor = annotate.RectangleFillColor;
  709. squareArgs.LineColor = annotate.RectangleBorderColor;
  710. }
  711. else
  712. {
  713. squareArgs.LineColor = Colors.Red;
  714. squareArgs.BgColor = Colors.Red;
  715. }
  716. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  717. {
  718. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  719. if (defaultAnnot == null)
  720. {
  721. defaultAnnot = new DefaultAnnotProperty();
  722. defaultAnnot.AnnotToolType = squareArgs.EventType;
  723. defaultAnnot.Thickness = 1;
  724. defaultAnnot.Opacity = 1;
  725. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  726. Settings.Default.Save();
  727. }
  728. squareArgs.LineWidth = defaultAnnot.Thickness;
  729. squareArgs.Transparency = defaultAnnot.Opacity;
  730. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  731. {
  732. squareArgs.LineDash = DashStyles.Solid;
  733. }
  734. else
  735. {
  736. var collect = new DoubleCollection();
  737. foreach (var item in defaultAnnot.DashArray)
  738. {
  739. collect.Add(item);
  740. }
  741. if (squareArgs.LineDash == null)
  742. squareArgs.LineDash = new DashStyle();
  743. squareArgs.LineDash.Dashes = collect;
  744. }
  745. }
  746. else
  747. {
  748. squareArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  749. }
  750. if (squareArgs != null)
  751. {
  752. selectedArgs = new List<AnnotHandlerEventArgs>();
  753. selectedArgs.Add(squareArgs);
  754. }
  755. }
  756. else
  757. {
  758. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  759. }
  760. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  761. return squareArgs;
  762. }
  763. /// <summary>
  764. /// 圆
  765. /// </summary>
  766. /// <param name="selectedArgs"></param>
  767. /// <returns></returns>
  768. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  769. {
  770. CircleAnnotArgs circleAnnotArgs = null;
  771. if (selectedArgs == null || selectedArgs.Count == 0)
  772. {
  773. circleAnnotArgs = new CircleAnnotArgs();
  774. var annotate = Settings.Default.AppProperties.Annotate;
  775. if (annotate != null)
  776. {
  777. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  778. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  779. }
  780. else
  781. {
  782. circleAnnotArgs.LineColor = Colors.Red;
  783. circleAnnotArgs.BgColor = Colors.Red;
  784. }
  785. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  786. {
  787. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  788. if (defaultAnnot == null)
  789. {
  790. defaultAnnot = new DefaultAnnotProperty();
  791. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  792. defaultAnnot.Thickness = 1;
  793. defaultAnnot.Opacity = 1;
  794. defaultAnnot.NoteText = string.Empty;
  795. defaultAnnot.DashArray = null;
  796. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  797. Settings.Default.Save();
  798. }
  799. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  800. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  801. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  802. {
  803. circleAnnotArgs.LineDash = DashStyles.Solid;
  804. }
  805. else
  806. {
  807. var collect = new DoubleCollection();
  808. foreach (var item in defaultAnnot.DashArray)
  809. {
  810. collect.Add(item);
  811. }
  812. if (circleAnnotArgs.LineDash == null)
  813. circleAnnotArgs.LineDash = new DashStyle();
  814. circleAnnotArgs.LineDash.Dashes = collect;
  815. }
  816. }
  817. else
  818. {
  819. circleAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  820. }
  821. if (circleAnnotArgs != null)
  822. {
  823. selectedArgs = new List<AnnotHandlerEventArgs>();
  824. selectedArgs.Add(circleAnnotArgs);
  825. }
  826. }
  827. else
  828. {
  829. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  830. }
  831. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  832. return circleAnnotArgs;
  833. }
  834. /// <summary>
  835. /// 箭头 线
  836. /// </summary>
  837. /// <param name="TagStr"></param>
  838. /// <param name="selectedArgs"></param>
  839. /// <returns></returns>
  840. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  841. {
  842. LineAnnotArgs lineArgs = new LineAnnotArgs();
  843. if (selectedArgs == null || selectedArgs.Count == 0)
  844. {
  845. var annotate = Settings.Default.AppProperties.Annotate;
  846. if (annotate != null)
  847. {
  848. lineArgs.LineColor = annotate.LineColor;
  849. }
  850. else
  851. {
  852. lineArgs.LineColor = Colors.Red;
  853. }
  854. lineArgs.LineColor = Colors.Red;
  855. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  856. bool isLastAnnot = false;
  857. if (TagStr == "Line")
  858. {
  859. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  860. isLastAnnot = (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  861. }
  862. else
  863. {
  864. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  865. isLastAnnot = (propertyPanel.LastArrowAnnot != null ? true : false);
  866. }
  867. if (isLastAnnot == false)
  868. {
  869. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  870. if (defaultAnnot == null)
  871. {
  872. defaultAnnot = new DefaultAnnotProperty();
  873. defaultAnnot.AnnotToolType = lineArgs.EventType;
  874. defaultAnnot.Thickness = 1;
  875. defaultAnnot.Opacity = 1;
  876. defaultAnnot.NoteText = string.Empty;
  877. defaultAnnot.DashArray = null;
  878. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  879. Settings.Default.Save();
  880. }
  881. lineArgs.LineDash = DashStyles.Solid;
  882. lineArgs.LineWidth = defaultAnnot.Thickness;
  883. lineArgs.Transparency = defaultAnnot.Opacity;
  884. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  885. {
  886. lineArgs.LineDash = DashStyles.Solid;
  887. }
  888. else
  889. {
  890. var collect = new DoubleCollection();
  891. foreach (var item in defaultAnnot.DashArray)
  892. {
  893. collect.Add(item);
  894. }
  895. if (lineArgs.LineDash == null)
  896. lineArgs.LineDash = new DashStyle();
  897. lineArgs.LineDash.Dashes = collect;
  898. }
  899. }
  900. else
  901. {
  902. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  903. {
  904. lineArgs = propertyPanel.LastArrowAnnot as LineAnnotArgs;
  905. }
  906. else
  907. {
  908. lineArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  909. }
  910. }
  911. if (lineArgs != null)
  912. {
  913. selectedArgs = new List<AnnotHandlerEventArgs>();
  914. selectedArgs.Add(lineArgs);
  915. }
  916. }
  917. else
  918. {
  919. lineArgs = selectedArgs[0] as LineAnnotArgs;
  920. }
  921. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  922. return lineArgs;
  923. }
  924. /// <summary>
  925. /// 图章
  926. /// </summary>
  927. /// <returns></returns>
  928. private AnnotHandlerEventArgs GetStamp()
  929. {
  930. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  931. stampAnnotArgs.Opacity = 1;
  932. stampAnnotArgs.StampText = "APPROVED";
  933. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  934. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  935. if (stampAnnotArgs != null)
  936. stampAnnotArgsList.Add(stampAnnotArgs);
  937. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  938. return stampAnnotArgs;
  939. }
  940. /// <summary>
  941. /// 签名
  942. /// </summary>
  943. /// <returns></returns>
  944. private AnnotHandlerEventArgs GetSignature()
  945. {
  946. AddToPropertyPanel("SignatureAnnotProperty");
  947. return null;
  948. }
  949. private AnnotHandlerEventArgs GetImage()
  950. {
  951. StampAnnotArgs stampArgs = new StampAnnotArgs();
  952. stampArgs.Opacity = 1;
  953. stampArgs.Type = StampType.IMAGE_STAMP;
  954. OpenFileDialog openFileDialog = new OpenFileDialog();
  955. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  956. if (openFileDialog.ShowDialog() == true)
  957. {
  958. stampArgs.ImagePath = openFileDialog.FileName;
  959. }
  960. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  961. if (stampArgs != null)
  962. stampArgsList.Add(stampArgs);
  963. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  964. return stampArgs;
  965. }
  966. /// <summary>
  967. /// 内容选择
  968. /// </summary>
  969. /// <param name="annotBtn"></param>
  970. /// <returns></returns>
  971. private AnnotHandlerEventArgs GetSnapshotEdit()
  972. {
  973. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  974. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  975. snapshotArgs.ControlPointColor = Colors.White;
  976. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  977. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  978. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  979. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  980. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  981. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  982. #region to do
  983. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  984. //snapshotArgs.ToolPanel = snapMenu;
  985. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  986. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  987. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  988. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  989. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  990. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  991. #endregion to do
  992. return snapshotArgs;
  993. }
  994. #endregion 注释工具
  995. #region 菜单
  996. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  997. {
  998. if (viewContentViewModel.mainViewModel.IsBookMode)
  999. {
  1000. menuItem.IsEnabled = false;
  1001. return true;
  1002. }
  1003. else
  1004. {
  1005. menuItem.IsEnabled = true;
  1006. return false;
  1007. }
  1008. }
  1009. private void ExportPicture_MenuItemClick()
  1010. {
  1011. //图片提取
  1012. try
  1013. {
  1014. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1015. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1016. foreach (int pageIndex in imageDict.Keys)
  1017. {
  1018. imageList = imageDict[pageIndex];
  1019. }
  1020. string path = PDFViewer.Document.FileName;
  1021. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1022. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1023. {
  1024. int i = 1;
  1025. int pagenum = 1;
  1026. string choosePath = folderDialog.SelectedPath;
  1027. string sPath = choosePath + "\\" + path + "_Extract Image";
  1028. sPath = GetExportPathName(sPath);
  1029. if (!Directory.Exists(sPath))
  1030. {
  1031. Directory.CreateDirectory(sPath);
  1032. }
  1033. if (Directory.Exists(sPath))
  1034. {
  1035. foreach (System.Drawing.Bitmap image in imageList)
  1036. {
  1037. foreach (var item in imageDict.Keys)
  1038. {
  1039. pagenum = item;
  1040. }
  1041. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1042. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1043. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1044. i++;
  1045. }
  1046. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1047. }
  1048. }
  1049. }
  1050. catch (Exception ex) { }
  1051. }
  1052. public string GetExportPathName(string path)
  1053. {
  1054. int i = 1;
  1055. string outpath = path;
  1056. while (Directory.Exists(outpath))
  1057. {
  1058. outpath = path + $"({i.ToString()})";
  1059. i++;
  1060. }
  1061. return outpath;
  1062. }
  1063. private string GetNum(int num)
  1064. {
  1065. if (num % 10 < 1)
  1066. {
  1067. return "00" + num.ToString();
  1068. }
  1069. if (num % 10 >= 1 && num % 10 < 10)
  1070. {
  1071. return "0" + num.ToString();
  1072. }
  1073. else
  1074. {
  1075. return num.ToString();
  1076. }
  1077. }
  1078. #endregion 菜单
  1079. }
  1080. }