StampAnnotPropertyViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 bool unStandard;
  119. /// <summary>
  120. /// 判断当前是否为非标准图章,控制UI展示
  121. /// </summary>
  122. public bool UnStandard
  123. {
  124. get { return unStandard; }
  125. set
  126. {
  127. SetProperty(ref unStandard, value);
  128. }
  129. }
  130. /// <summary>
  131. /// 日期格式
  132. /// </summary>
  133. private string dateType = "F";
  134. private IDialogService dialogs;
  135. public DelegateCommand ShowDialogCommand { get; set; }
  136. private CPDFViewer PDFViewer;
  137. public ObservableCollection<Stamp> StandardStampList { get; set; }
  138. public ObservableCollection<Stamp> DynamicStampList { get; set; }
  139. public ObservableCollection<Stamp> CustomStampList { get; set; }
  140. public StampAnnotPropertyViewModel(IDialogService dialogService)
  141. {
  142. dialogs = dialogService;
  143. StandardStampList = new ObservableCollection<Stamp>();
  144. DynamicStampList = new ObservableCollection<Stamp>();
  145. CustomStampList = new ObservableCollection<Stamp>();
  146. ShowDialogCommand = new DelegateCommand(ShowDialog);
  147. InitStandardStamp();
  148. UpDataDynamicStampList();
  149. LoadSettings();
  150. }
  151. /// <summary>
  152. /// 加载缓存的自定义图章
  153. /// </summary>
  154. private void LoadSettings()
  155. {
  156. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  157. if (stamps != null)
  158. {
  159. for (int i = 0; i < stamps.Count; i++)
  160. {
  161. Stamp customStamp = new Stamp();
  162. customStamp.Opacity = 1;
  163. customStamp.Author = stamps[i].Author;
  164. customStamp.StampText = stamps[i].StampText;
  165. customStamp.StampTextDate = stamps[i].StampTextDate;
  166. customStamp.MaxWidth = stamps[i].ImageWidth;
  167. customStamp.MaxHeight = stamps[i].ImageHeight;
  168. customStamp.SourcePath = stamps[i].SourcePath;
  169. customStamp.Type = stamps[i].Type;
  170. customStamp.TextSharp = stamps[i].TextSharp;
  171. customStamp.TextColor = stamps[i].TextColor;
  172. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  173. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  174. CustomStampList.Add(customStamp);
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// 初始化标准图章相关内容
  180. /// </summary>
  181. private void InitStandardStamp()
  182. {
  183. for (int i = 0; i < Path.Count; i++)
  184. {
  185. Stamp standardStamp = new Stamp();
  186. standardStamp.Author = "";
  187. standardStamp.Opacity = 1;
  188. standardStamp.SourcePath = Path[i];
  189. standardStamp.StampText = StampText[i];
  190. standardStamp.MaxWidth = MaxWidth[i];
  191. standardStamp.MaxHeight = MaxHeight[i];
  192. standardStamp.Type = StampType.STANDARD_STAMP;
  193. StandardStampList.Add(standardStamp);
  194. }
  195. }
  196. public bool IsNavigationTarget(NavigationContext navigationContext)
  197. {
  198. return true;
  199. }
  200. public void OnNavigatedFrom(NavigationContext navigationContext)
  201. {
  202. return;
  203. }
  204. public void OnNavigatedTo(NavigationContext navigationContext)
  205. {
  206. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  207. if (PDFViewer == null)
  208. {
  209. return;
  210. }
  211. }
  212. /// <summary>
  213. /// 在PDFView上创建图章的统一方法
  214. /// </summary>
  215. /// <param name="stamp"></param>
  216. public void SetStamp(Stamp stamp)
  217. {
  218. StampAnnotArgs Args = new StampAnnotArgs();
  219. Args.StampText = stamp.StampText;
  220. Args.Author = stamp.Author;
  221. Args.Opacity = stamp.Opacity;
  222. if (stamp.Type == StampType.IMAGE_STAMP)
  223. {
  224. Args.ImageWidth = stamp.MaxWidth;
  225. Args.ImageHeight = stamp.MaxHeight;
  226. }
  227. else
  228. {
  229. Args.MaxWidth = stamp.MaxWidth;
  230. Args.MaxHeight = stamp.MaxHeight;
  231. }
  232. Args.StampTextDate = stamp.StampTextDate;
  233. Args.TextColor = stamp.TextColor;
  234. Args.TextSharp = stamp.TextSharp;
  235. if (!string.IsNullOrEmpty(stamp.SourcePath))
  236. {
  237. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  238. Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
  239. image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
  240. Args.ImageHeight = image.PixelHeight;
  241. Args.ImageWidth = image.PixelWidth;
  242. }
  243. else
  244. {
  245. Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
  246. stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
  247. Args.ImageHeight = stamp.ImageSource.PixelHeight;
  248. Args.ImageWidth = stamp.ImageSource.PixelWidth;
  249. }
  250. Args.Type = stamp.Type;
  251. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  252. PDFViewer.SetToolParam(Args);
  253. }
  254. /// <summary>
  255. /// 更新动态图章对象相关属性
  256. /// </summary>
  257. public void UpDataDynamicStampList()
  258. {
  259. CPDFDocument doc = CPDFDocument.CreateDocument();
  260. bool tt = doc.InsertPage(0, 300, 500, null);
  261. CPDFPage docPage = doc.PageAtIndex(0);
  262. CPDFStampAnnotation stampCore = docPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
  263. var x = stampCore.GetTextAttribute();
  264. DynamicStampList.Clear();
  265. for (int i = 0; i < DynamicStampText.Count; i++)
  266. {
  267. string date = "";
  268. //区分机密(CONFIDENTIAL)和其他动态图章的区别
  269. if (i < DynamicStampText.Count - 1)
  270. {
  271. date = System.DateTime.Now.ToString(dateType);
  272. }
  273. Stamp standardStamp = new Stamp();
  274. if (IsSetAuthor && !string.IsNullOrEmpty(Author))
  275. {
  276. standardStamp.Author = Author;
  277. if (i < DynamicStampText.Count - 1)
  278. {
  279. standardStamp.StampTextDate = "By " + Author + " at " + date;
  280. }
  281. else
  282. {
  283. standardStamp.StampTextDate = Author;
  284. }
  285. }
  286. else
  287. {
  288. standardStamp.StampTextDate = date;
  289. standardStamp.Author = "";
  290. }
  291. var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
  292. C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
  293. PixelFormat fmt = PixelFormats.Bgra32;
  294. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
  295. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  296. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  297. int Dpi = (int)dpiProperty.GetValue(null, null);
  298. standardStamp.Opacity = 1;
  299. standardStamp.SourcePath = "";
  300. standardStamp.StampText = DynamicStampText[i];
  301. standardStamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(stampWidth / 72D * DpiHelpers.Dpi);
  302. standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
  303. standardStamp.Type = StampType.TEXT_STAMP;
  304. standardStamp.ImageSource = bps;
  305. standardStamp.IsCheckedDate = true;
  306. standardStamp.IsCheckedTime = true;
  307. switch (DynamicColor[i])
  308. {
  309. case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
  310. break;
  311. case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
  312. standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
  313. break;
  314. case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
  315. standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
  316. break;
  317. case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
  318. break;
  319. default:
  320. break;
  321. }
  322. DynamicStampList.Add(standardStamp);
  323. }
  324. }
  325. /// <summary>
  326. /// 导出图章
  327. /// </summary>
  328. public void SaveToPath(string FileType, Stamp Item)
  329. {
  330. SaveFileDialog saveFileDialog = new SaveFileDialog();
  331. saveFileDialog.Title = "保存" + FileType + "文件";
  332. saveFileDialog.Filter = "(*)|*." + FileType;
  333. if (saveFileDialog.ShowDialog() == false)
  334. {
  335. return;
  336. }
  337. BitmapEncoder encoder;
  338. if (FileType.ToUpper() == "JPG")
  339. {
  340. encoder = new JpegBitmapEncoder();
  341. }
  342. else
  343. {
  344. encoder = new PngBitmapEncoder();
  345. }
  346. encoder.Frames.Add(BitmapFrame.Create(new Uri(Item.SourcePath)));
  347. string path = saveFileDialog.FileName;
  348. switch (FileType.ToUpper())
  349. {
  350. case "PDF":
  351. CPDFDocument newDoc = CPDFDocument.CreateDocument();
  352. BitmapFrame frame = BitmapFrame.Create(new Uri(Item.SourcePath));
  353. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  354. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  355. newDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  356. newDoc.WriteToFilePath(path);
  357. break;
  358. case "PNG":
  359. using (FileStream stream = new FileStream(path, FileMode.Create))
  360. {
  361. encoder.Save(stream);
  362. }
  363. break;
  364. default:
  365. break;
  366. }
  367. System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
  368. }
  369. public void DeleteStamp(Stamp stamp)
  370. {
  371. int index = CustomStampList.IndexOf(stamp);
  372. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  373. CustomStampList.RemoveAt(index);
  374. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  375. stamps.RemoveAt(index);
  376. Settings.Default.Save();
  377. }
  378. public void DeleteAll()
  379. {
  380. foreach (Stamp item in CustomStampList)
  381. {
  382. App.CachePath.AddToDeleteFiles(item.SourcePath);
  383. }
  384. CustomStampList.Clear();
  385. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  386. stamps.Clear();
  387. Settings.Default.Save();
  388. }
  389. private void ShowDialog()
  390. {
  391. switch (TabControlSelectedIndex)
  392. {
  393. case 1:
  394. ShowDynamicPropertyDialog();
  395. break;
  396. case 2:
  397. ShowCustomCreateDialog(null);
  398. break;
  399. default:
  400. break;
  401. }
  402. }
  403. private void ShowDynamicPropertyDialog()
  404. {
  405. bool result = true;
  406. dialogs.ShowDialog(DialogNames.DynamicPropertyDialog, null, e =>
  407. {
  408. if (e.Result != ButtonResult.OK)
  409. {
  410. result = false;
  411. }
  412. DynamicPropertyDialogViewModel DynamicVM = e.Parameters.GetValue<DynamicPropertyDialogViewModel>(ParameterNames.DataModel);
  413. if (DynamicVM != null)
  414. {
  415. Author = DynamicVM.Author;
  416. IsSetAuthor = DynamicVM.IsChecked;
  417. //需要加多语判断
  418. dateType = DynamicVM.SelectedIndex == 0 ? "F" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  419. UpDataDynamicStampList();
  420. }
  421. });
  422. if (!result)
  423. {
  424. return;
  425. }
  426. }
  427. private void ShowCustomCreateDialog(Stamp stamp)
  428. {
  429. bool result = true;
  430. DialogParameters value = new DialogParameters();
  431. value.Add(ParameterNames.DataModel, stamp);
  432. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  433. {
  434. if (e.Result != ButtonResult.OK)
  435. {
  436. result = false;
  437. }
  438. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  439. if (CustomVM != null)
  440. {
  441. CreateCustomStamp(CustomVM);
  442. }
  443. });
  444. if (!result)
  445. {
  446. return;
  447. }
  448. }
  449. public void EditorCustomStamp(Stamp stamp)
  450. {
  451. bool result = true;
  452. DialogParameters value = new DialogParameters();
  453. value.Add(ParameterNames.DataModel, stamp);
  454. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  455. {
  456. if (e.Result != ButtonResult.OK)
  457. {
  458. result = false;
  459. }
  460. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  461. if (CustomVM != null)
  462. {
  463. UpDataCustomStamp(CustomVM, stamp);
  464. }
  465. });
  466. if (!result)
  467. {
  468. return;
  469. }
  470. }
  471. private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
  472. {
  473. Stamp stamp = new Stamp();
  474. stamp.Author = "";
  475. stamp.Opacity = 1;
  476. stamp.SourcePath = viewModel.SaveToPath;
  477. stamp.StampText = viewModel.StampText;
  478. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  479. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  480. stamp.StampTextDate = viewModel.StampTextDate;
  481. stamp.Type = viewModel.Type;
  482. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  483. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  484. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  485. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  486. int index= CustomStampList.IndexOf(oldstamp);
  487. CustomStampList[index] = stamp;
  488. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  489. if (stamps == null)
  490. {
  491. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  492. }
  493. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  494. Stamp customStamp = new Stamp();
  495. annote.Author = stamp.Author;
  496. annote.StampText = stamp.StampText;
  497. annote.StampTextDate = stamp.StampTextDate;
  498. annote.ImageWidth = stamp.MaxWidth;
  499. annote.ImageHeight = stamp.MaxHeight;
  500. annote.SourcePath = stamp.SourcePath;
  501. annote.Type = stamp.Type;
  502. annote.TextSharp = stamp.TextSharp;
  503. annote.TextColor = stamp.TextColor;
  504. annote.IsCheckedDate = stamp.IsCheckedDate;
  505. annote.IsCheckedTime = stamp.IsCheckedTime;
  506. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  507. stamps[index] = annote;
  508. Settings.Default.Save();
  509. }
  510. /// <summary>
  511. /// 创建自定义图章,并且保存到APP缓存
  512. /// </summary>
  513. private void CreateCustomStamp(CustomCreateDialogViewModel viewModel)
  514. {
  515. Stamp stamp = new Stamp();
  516. stamp.Author = "";
  517. stamp.Opacity = 1;
  518. if (viewModel.IsRemoveBackground)
  519. {
  520. if (!string.IsNullOrEmpty(viewModel.SaveToPath))
  521. {
  522. App.CachePath.AddToDeleteFiles(viewModel.SaveToPath);
  523. }
  524. stamp.SourcePath = viewModel.RemoveBackgroundSaveToPath;
  525. }
  526. else
  527. {
  528. stamp.SourcePath = viewModel.SaveToPath;
  529. }
  530. stamp.StampText = viewModel.StampText;
  531. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  532. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  533. stamp.StampTextDate = viewModel.StampTextDate;
  534. stamp.Type = viewModel.Type;
  535. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  536. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  537. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  538. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  539. CustomStampList.Add(stamp);
  540. //缓存数据
  541. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  542. if (stamps == null)
  543. {
  544. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  545. }
  546. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  547. Stamp customStamp = new Stamp();
  548. annote.Author = stamp.Author;
  549. annote.StampText = stamp.StampText;
  550. annote.StampTextDate = stamp.StampTextDate;
  551. annote.ImageWidth = stamp.MaxWidth;
  552. annote.ImageHeight = stamp.MaxHeight;
  553. annote.SourcePath = stamp.SourcePath;
  554. annote.Type = stamp.Type;
  555. annote.TextSharp = stamp.TextSharp;
  556. annote.TextColor = stamp.TextColor;
  557. annote.IsCheckedDate = stamp.IsCheckedDate;
  558. annote.IsCheckedTime = stamp.IsCheckedTime;
  559. stamps.Add(annote);
  560. Settings.Default.Save();
  561. }
  562. }
  563. }