StampAnnotPropertyViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Win32;
  7. using PDF_Office.Helper;
  8. using PDF_Office.Model;
  9. using PDF_Office.Model.AnnotPanel;
  10. using PDF_Office.Properties;
  11. using Prism.Commands;
  12. using Prism.Mvvm;
  13. using Prism.Regions;
  14. using Prism.Services.Dialogs;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Reflection;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using static Dropbox.Api.Files.FileCategory;
  27. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  28. {
  29. internal class StampAnnotPropertyViewModel : BindableBase, INavigationAware
  30. {
  31. #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的,如果要支持多语,Path则需要替换成SDK获取图片的方法,并修改对应参数与实现代码)
  32. List<string> Path = new List<string>
  33. {
  34. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Approved.png",
  35. "pack://application:,,,/PDF Office;component/Resources/StampIcons/NotApproved.png",
  36. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Completed.png",
  37. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Final.png",
  38. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Draft.png",
  39. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Confidential.png",
  40. "pack://application:,,,/PDF Office;component/Resources/StampIcons/ForPublicRelease.png",
  41. "pack://application:,,,/PDF Office;component/Resources/StampIcons/NotForPublicRelease.png",
  42. "pack://application:,,,/PDF Office;component/Resources/StampIcons/ForComment.png",
  43. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Void.png",
  44. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PreliminaryResults.png",
  45. "pack://application:,,,/PDF Office;component/Resources/StampIcons/InformationOnly.png",
  46. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Accepted.png",
  47. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Rejected.png",
  48. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Witness.png",
  49. "pack://application:,,,/PDF Office;component/Resources/StampIcons/InitialHere.png",
  50. "pack://application:,,,/PDF Office;component/Resources/StampIcons/SignHere.png",
  51. "pack://application:,,,/PDF Office;component/Resources/StampIcons/revised.png",
  52. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark1.png",
  53. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark2.png",
  54. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark3.png",
  55. };
  56. List<string> StampText = new List<string>
  57. {
  58. "Approved","NotApproved","Completed","Final","Draft","Confidential","ForPublicRelease","NotForPublicRelease",
  59. "ForComment","Void","PreliminaryResults","InformationOnly","Accepted","Rejected","Witness","InitialHere","SignHere",
  60. "revised","PrivateMark#1","PrivateMark#2","PrivateMark#3"
  61. };
  62. List<int> MaxWidth = new List<int>
  63. {
  64. 218,292,234,130,150,280,386,461,282,121,405,366,30,30,133,133,133,173,30,30,30
  65. };
  66. List<int> MaxHeight = new List<int>
  67. {
  68. 66,66,66,66,66,66,66,66,66,66,66,66,30,30,39,39,39,66,30,30,30
  69. };
  70. #endregion
  71. #region 动态图章相关配置(需要支持多语则修改DynamicStampText的内容)
  72. List<string> DynamicStampText = new List<string>
  73. {
  74. "REVISED","REVIEWED","Completed","RECEIVED","APPROVED","CONFIDENTIAL"
  75. };
  76. List<C_TEXTSTAMP_COLOR> DynamicColor = new List<C_TEXTSTAMP_COLOR>
  77. {
  78. C_TEXTSTAMP_COLOR.TEXTSTAMP_RED, C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
  79. C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
  80. C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_RED,
  81. };
  82. #endregion
  83. private string author = "12312";
  84. public string Author
  85. {
  86. get { return author; }
  87. set
  88. {
  89. SetProperty(ref author, value);
  90. }
  91. }
  92. private bool isSetAuthor = false;
  93. public bool IsSetAuthor
  94. {
  95. get { return isSetAuthor; }
  96. set
  97. {
  98. SetProperty(ref isSetAuthor, value);
  99. }
  100. }
  101. private int tabControlSelectedIndex = 0;
  102. public int TabControlSelectedIndex
  103. {
  104. get { return tabControlSelectedIndex; }
  105. set
  106. {
  107. SetProperty(ref tabControlSelectedIndex, value);
  108. if (tabControlSelectedIndex == 0)
  109. {
  110. UnStandard = false;
  111. }
  112. else
  113. {
  114. UnStandard = true;
  115. }
  116. }
  117. }
  118. private int cusListboxIndex=-1;
  119. public int CusListboxIndex
  120. {
  121. get { return cusListboxIndex; }
  122. set
  123. {
  124. SetProperty(ref cusListboxIndex, value);
  125. }
  126. }
  127. private bool unStandard;
  128. /// <summary>
  129. /// 判断当前是否为非标准图章,控制UI展示
  130. /// </summary>
  131. public bool UnStandard
  132. {
  133. get { return unStandard; }
  134. set
  135. {
  136. SetProperty(ref unStandard, value);
  137. }
  138. }
  139. /// <summary>
  140. /// 日期格式
  141. /// </summary>
  142. private string dateType = "F";
  143. private IDialogService dialogs;
  144. public DelegateCommand ShowDialogCommand { get; set; }
  145. private CPDFViewer PDFViewer;
  146. public ObservableCollection<Stamp> StandardStampList { get; set; }
  147. public ObservableCollection<Stamp> DynamicStampList { get; set; }
  148. public ObservableCollection<Stamp> CustomStampList { get; set; }
  149. public StampAnnotPropertyViewModel(IDialogService dialogService)
  150. {
  151. dialogs = dialogService;
  152. StandardStampList = new ObservableCollection<Stamp>();
  153. DynamicStampList = new ObservableCollection<Stamp>();
  154. CustomStampList = new ObservableCollection<Stamp>();
  155. ShowDialogCommand = new DelegateCommand(ShowDialog);
  156. InitStandardStamp();
  157. UpDataDynamicStampList();
  158. LoadSettings();
  159. }
  160. /// <summary>
  161. /// 加载缓存的自定义图章
  162. /// </summary>
  163. private void LoadSettings()
  164. {
  165. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  166. if (stamps != null)
  167. {
  168. for (int i = 0; i < stamps.Count; i++)
  169. {
  170. Stamp customStamp = new Stamp();
  171. customStamp.Opacity = 1;
  172. customStamp.Author = stamps[i].Author;
  173. customStamp.StampText = stamps[i].StampText;
  174. customStamp.StampTextDate = stamps[i].StampTextDate;
  175. customStamp.MaxWidth = stamps[i].ImageWidth;
  176. customStamp.MaxHeight = stamps[i].ImageHeight;
  177. customStamp.SourcePath = stamps[i].SourcePath;
  178. customStamp.Type = stamps[i].Type;
  179. customStamp.TextSharp = stamps[i].TextSharp;
  180. customStamp.TextColor = stamps[i].TextColor;
  181. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  182. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  183. CustomStampList.Add(customStamp);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 初始化标准图章相关内容
  189. /// </summary>
  190. private void InitStandardStamp()
  191. {
  192. for (int i = 0; i < Path.Count; i++)
  193. {
  194. Stamp standardStamp = new Stamp();
  195. standardStamp.Author = "";
  196. standardStamp.Opacity = 1;
  197. standardStamp.SourcePath = Path[i];
  198. standardStamp.StampText = StampText[i];
  199. standardStamp.MaxWidth = MaxWidth[i];
  200. standardStamp.MaxHeight = MaxHeight[i];
  201. standardStamp.Type = StampType.STANDARD_STAMP;
  202. StandardStampList.Add(standardStamp);
  203. }
  204. }
  205. public bool IsNavigationTarget(NavigationContext navigationContext)
  206. {
  207. return true;
  208. }
  209. public void OnNavigatedFrom(NavigationContext navigationContext)
  210. {
  211. return;
  212. }
  213. public void OnNavigatedTo(NavigationContext navigationContext)
  214. {
  215. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  216. if (PDFViewer == null)
  217. {
  218. return;
  219. }
  220. }
  221. /// <summary>
  222. /// 在PDFView上创建图章的统一方法
  223. /// </summary>
  224. /// <param name="stamp"></param>
  225. public void SetStamp(Stamp stamp)
  226. {
  227. StampAnnotArgs Args = new StampAnnotArgs();
  228. Args.StampText = stamp.StampText;
  229. Args.Author = stamp.Author;
  230. Args.Opacity = stamp.Opacity;
  231. if (stamp.Type == StampType.IMAGE_STAMP)
  232. {
  233. Args.ImageWidth = stamp.MaxWidth;
  234. Args.ImageHeight = stamp.MaxHeight;
  235. }
  236. else
  237. {
  238. Args.MaxWidth = stamp.MaxWidth;
  239. Args.MaxHeight = stamp.MaxHeight;
  240. }
  241. Args.StampTextDate = stamp.StampTextDate;
  242. Args.TextColor = stamp.TextColor;
  243. Args.TextSharp = stamp.TextSharp;
  244. if (!string.IsNullOrEmpty(stamp.SourcePath))
  245. {
  246. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  247. Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
  248. image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
  249. Args.ImageHeight = image.PixelHeight;
  250. Args.ImageWidth = image.PixelWidth;
  251. }
  252. else
  253. {
  254. Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
  255. stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
  256. Args.ImageHeight = stamp.ImageSource.PixelHeight;
  257. Args.ImageWidth = stamp.ImageSource.PixelWidth;
  258. }
  259. Args.Type = stamp.Type;
  260. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  261. PDFViewer.SetToolParam(Args);
  262. }
  263. /// <summary>
  264. /// 更新动态图章对象相关属性
  265. /// </summary>
  266. public void UpDataDynamicStampList()
  267. {
  268. CPDFDocument doc = CPDFDocument.CreateDocument();
  269. bool tt = doc.InsertPage(0, 300, 500, null);
  270. CPDFPage docPage = doc.PageAtIndex(0);
  271. CPDFStampAnnotation stampCore = docPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
  272. var x = stampCore.GetTextAttribute();
  273. DynamicStampList.Clear();
  274. for (int i = 0; i < DynamicStampText.Count; i++)
  275. {
  276. string date = "";
  277. //区分机密(CONFIDENTIAL)和其他动态图章的区别
  278. if (i < DynamicStampText.Count - 1)
  279. {
  280. date = System.DateTime.Now.ToString(dateType);
  281. }
  282. Stamp standardStamp = new Stamp();
  283. if (IsSetAuthor && !string.IsNullOrEmpty(Author))
  284. {
  285. standardStamp.Author = Author;
  286. if (i < DynamicStampText.Count - 1)
  287. {
  288. standardStamp.StampTextDate = "By " + Author + " at " + date;
  289. }
  290. else
  291. {
  292. standardStamp.StampTextDate = Author;
  293. }
  294. }
  295. else
  296. {
  297. standardStamp.StampTextDate = date;
  298. standardStamp.Author = "";
  299. }
  300. var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
  301. C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
  302. PixelFormat fmt = PixelFormats.Bgra32;
  303. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
  304. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  305. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  306. int Dpi = (int)dpiProperty.GetValue(null, null);
  307. standardStamp.Opacity = 1;
  308. standardStamp.SourcePath = "";
  309. standardStamp.StampText = DynamicStampText[i];
  310. standardStamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(stampWidth / 72D * DpiHelpers.Dpi);
  311. standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
  312. standardStamp.Type = StampType.TEXT_STAMP;
  313. standardStamp.ImageSource = bps;
  314. standardStamp.IsCheckedDate = true;
  315. standardStamp.IsCheckedTime = true;
  316. switch (DynamicColor[i])
  317. {
  318. case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
  319. break;
  320. case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
  321. standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
  322. break;
  323. case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
  324. standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
  325. break;
  326. case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
  327. break;
  328. default:
  329. break;
  330. }
  331. DynamicStampList.Add(standardStamp);
  332. }
  333. }
  334. /// <summary>
  335. /// 导出图章
  336. /// </summary>
  337. public void SaveToPath(string FileType, Stamp Item)
  338. {
  339. SaveFileDialog saveFileDialog = new SaveFileDialog();
  340. saveFileDialog.Title = "保存" + FileType + "文件";
  341. saveFileDialog.Filter = "(*)|*." + FileType;
  342. if (saveFileDialog.ShowDialog() == false)
  343. {
  344. return;
  345. }
  346. BitmapEncoder encoder;
  347. if (FileType.ToUpper() == "JPG")
  348. {
  349. encoder = new JpegBitmapEncoder();
  350. }
  351. else
  352. {
  353. encoder = new PngBitmapEncoder();
  354. }
  355. encoder.Frames.Add(BitmapFrame.Create(new Uri(Item.SourcePath)));
  356. string path = saveFileDialog.FileName;
  357. switch (FileType.ToUpper())
  358. {
  359. case "PDF":
  360. CPDFDocument newDoc = CPDFDocument.CreateDocument();
  361. BitmapFrame frame = BitmapFrame.Create(new Uri(Item.SourcePath));
  362. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  363. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  364. newDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  365. newDoc.WriteToFilePath(path);
  366. break;
  367. case "PNG":
  368. using (FileStream stream = new FileStream(path, FileMode.Create))
  369. {
  370. encoder.Save(stream);
  371. }
  372. break;
  373. default:
  374. break;
  375. }
  376. System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
  377. }
  378. public void DeleteStamp(Stamp stamp)
  379. {
  380. int index = CustomStampList.IndexOf(stamp);
  381. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  382. CustomStampList.RemoveAt(index);
  383. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  384. stamps.RemoveAt(index);
  385. Settings.Default.Save();
  386. }
  387. public void DeleteAll()
  388. {
  389. foreach (Stamp item in CustomStampList)
  390. {
  391. App.CachePath.AddToDeleteFiles(item.SourcePath);
  392. }
  393. CustomStampList.Clear();
  394. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  395. stamps.Clear();
  396. Settings.Default.Save();
  397. }
  398. private void ShowDialog()
  399. {
  400. switch (TabControlSelectedIndex)
  401. {
  402. case 1:
  403. ShowDynamicPropertyDialog();
  404. break;
  405. case 2:
  406. ShowCustomCreateDialog(null);
  407. break;
  408. default:
  409. break;
  410. }
  411. }
  412. private void ShowDynamicPropertyDialog()
  413. {
  414. bool result = true;
  415. dialogs.ShowDialog(DialogNames.DynamicPropertyDialog, null, e =>
  416. {
  417. if (e.Result != ButtonResult.OK)
  418. {
  419. result = false;
  420. }
  421. DynamicPropertyDialogViewModel DynamicVM = e.Parameters.GetValue<DynamicPropertyDialogViewModel>(ParameterNames.DataModel);
  422. if (DynamicVM != null)
  423. {
  424. Author = DynamicVM.Author;
  425. IsSetAuthor = DynamicVM.IsChecked;
  426. if (Settings.Default.AppProperties.culture == "en-US")
  427. {
  428. dateType = DynamicVM.SelectedIndex == 0 ? "F" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  429. }
  430. else
  431. {
  432. dateType = DynamicVM.SelectedIndex == 0 ? "r" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  433. }
  434. UpDataDynamicStampList();
  435. }
  436. });
  437. if (!result)
  438. {
  439. return;
  440. }
  441. }
  442. private void ShowCustomCreateDialog(Stamp stamp)
  443. {
  444. bool result = true;
  445. DialogParameters value = new DialogParameters();
  446. value.Add(ParameterNames.DataModel, stamp);
  447. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  448. {
  449. if (e.Result != ButtonResult.OK)
  450. {
  451. result = false;
  452. }
  453. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  454. if (CustomVM != null)
  455. {
  456. CreateCustomStamp(CustomVM);
  457. }
  458. });
  459. if (!result)
  460. {
  461. return;
  462. }
  463. }
  464. public void EditorCustomStamp(Stamp stamp)
  465. {
  466. bool result = true;
  467. DialogParameters value = new DialogParameters();
  468. value.Add(ParameterNames.DataModel, stamp);
  469. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  470. {
  471. if (e.Result != ButtonResult.OK)
  472. {
  473. result = false;
  474. }
  475. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  476. if (CustomVM != null)
  477. {
  478. UpDataCustomStamp(CustomVM, stamp);
  479. }
  480. });
  481. if (!result)
  482. {
  483. return;
  484. }
  485. }
  486. private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
  487. {
  488. Stamp stamp = new Stamp();
  489. stamp.Author = "";
  490. stamp.Opacity = 1;
  491. stamp.SourcePath = viewModel.SaveToPath;
  492. stamp.StampText = viewModel.StampText;
  493. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  494. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  495. stamp.StampTextDate = viewModel.StampTextDate;
  496. stamp.Type = viewModel.Type;
  497. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  498. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  499. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  500. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  501. int index= CustomStampList.IndexOf(oldstamp);
  502. CustomStampList[index] = stamp;
  503. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  504. if (stamps == null)
  505. {
  506. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  507. }
  508. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  509. Stamp customStamp = new Stamp();
  510. annote.Author = stamp.Author;
  511. annote.StampText = stamp.StampText;
  512. annote.StampTextDate = stamp.StampTextDate;
  513. annote.ImageWidth = stamp.MaxWidth;
  514. annote.ImageHeight = stamp.MaxHeight;
  515. annote.SourcePath = stamp.SourcePath;
  516. annote.Type = stamp.Type;
  517. annote.TextSharp = stamp.TextSharp;
  518. annote.TextColor = stamp.TextColor;
  519. annote.IsCheckedDate = stamp.IsCheckedDate;
  520. annote.IsCheckedTime = stamp.IsCheckedTime;
  521. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  522. stamps[index] = annote;
  523. Settings.Default.Save();
  524. }
  525. /// <summary>
  526. /// 创建自定义图章,并且保存到APP缓存
  527. /// </summary>
  528. private void CreateCustomStamp(CustomCreateDialogViewModel viewModel)
  529. {
  530. Stamp stamp = new Stamp();
  531. stamp.Author = "";
  532. stamp.Opacity = 1;
  533. if (viewModel.IsRemoveBackground)
  534. {
  535. if (!string.IsNullOrEmpty(viewModel.SaveToPath))
  536. {
  537. App.CachePath.AddToDeleteFiles(viewModel.SaveToPath);
  538. }
  539. stamp.SourcePath = viewModel.RemoveBackgroundSaveToPath;
  540. }
  541. else
  542. {
  543. stamp.SourcePath = viewModel.SaveToPath;
  544. }
  545. stamp.StampText = viewModel.StampText;
  546. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  547. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  548. stamp.StampTextDate = viewModel.StampTextDate;
  549. stamp.Type = viewModel.Type;
  550. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  551. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  552. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  553. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  554. CustomStampList.Add(stamp);
  555. //缓存数据
  556. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  557. if (stamps == null)
  558. {
  559. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  560. }
  561. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  562. annote.Author = stamp.Author;
  563. annote.StampText = stamp.StampText;
  564. annote.StampTextDate = stamp.StampTextDate;
  565. annote.ImageWidth = stamp.MaxWidth;
  566. annote.ImageHeight = stamp.MaxHeight;
  567. annote.SourcePath = stamp.SourcePath;
  568. annote.Type = stamp.Type;
  569. annote.TextSharp = stamp.TextSharp;
  570. annote.TextColor = stamp.TextColor;
  571. annote.IsCheckedDate = stamp.IsCheckedDate;
  572. annote.IsCheckedTime = stamp.IsCheckedTime;
  573. stamps.Add(annote);
  574. Settings.Default.Save();
  575. SetStamp(stamp);
  576. CusListboxIndex = CustomStampList.Count-1;
  577. }
  578. }
  579. }