CPDFStampUI.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using compdfkit_tools.Data;
  2. using compdfkit_tools.Properties;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.InteropServices.ComTypes;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Markup;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
  24. {
  25. public partial class CPDFStampUI : UserControl
  26. {
  27. #region StandardStamp
  28. List<string> Path = new List<string>
  29. {
  30. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Approved.png",
  31. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/NotApproved.png",
  32. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Completed.png",
  33. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Final.png",
  34. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Draft.png",
  35. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Confidential.png",
  36. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/ForPublicRelease.png",
  37. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/NotForPublicRelease.png",
  38. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/ForComment.png",
  39. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Void.png",
  40. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/PreliminaryResults.png",
  41. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/InformationOnly.png",
  42. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Accepted.png",
  43. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Rejected.png",
  44. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/Witness.png",
  45. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/InitialHere.png",
  46. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/SignHere.png",
  47. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/revised.png",
  48. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark1.png",
  49. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark2.png",
  50. "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark3.png",
  51. };
  52. List<string> StampText = new List<string>
  53. {
  54. "Approved","NotApproved","Completed","Final","Draft","Confidential","ForPublicRelease","NotForPublicRelease",
  55. "ForComment","Void","PreliminaryResults","InformationOnly","Accepted","Rejected","Witness","InitialHere","SignHere",
  56. "revised","PrivateMark#1","PrivateMark#2","PrivateMark#3"
  57. };
  58. List<int> MaxWidth = new List<int>
  59. {
  60. 218,292,234,130,150,280,386,461,282,121,405,366,30,30,133,133,133,173,30,30,30
  61. };
  62. List<int> MaxHeight = new List<int>
  63. {
  64. 66,66,66,66,66,66,66,66,66,66,66,66,30,30,39,39,39,66,30,30,30
  65. };
  66. #endregion
  67. public ObservableCollection<CPDFStampData> StandardStampList { get; set; }
  68. public ObservableCollection<CPDFStampData> CustomStampList { get; set; }
  69. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  70. public CPDFStampUI()
  71. {
  72. InitializeComponent();
  73. }
  74. private void Button_Click(object sender, RoutedEventArgs e)
  75. {
  76. }
  77. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  78. {
  79. PropertyChanged?.Invoke(this, new CPDFStampData());
  80. }
  81. private void Text_Click(object sender, RoutedEventArgs e)
  82. {
  83. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  84. createStampDialog.SetCreateHeaderIndex(0);
  85. createStampDialog.Owner = Window.GetWindow(this);
  86. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  87. createStampDialog.ShowDialog();
  88. UpDataCustomStamp(createStampDialog.cPDFStampData);
  89. }
  90. private void Image_Click(object sender, RoutedEventArgs e)
  91. {
  92. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  93. createStampDialog.SetCreateHeaderIndex(1);
  94. createStampDialog.Owner = Window.GetWindow(this);
  95. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  96. createStampDialog.ShowDialog();
  97. UpDataCustomStamp(createStampDialog.cPDFStampData);
  98. }
  99. private void Standard_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  100. {
  101. PropertyChanged?.Invoke(this, (sender as ListBoxItem).DataContext as CPDFStampData);
  102. }
  103. private void Customize_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  104. {
  105. PropertyChanged?.Invoke(this, (sender as ListViewItem).DataContext as CPDFStampData);
  106. }
  107. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  108. {
  109. StandardStampList = new ObservableCollection<CPDFStampData>();
  110. CustomStampList = new ObservableCollection<CPDFStampData>();
  111. InitStandardStamp();
  112. LoadSettings();
  113. Binding Standardbinding = new Binding();
  114. Standardbinding.Source = this;
  115. Standardbinding.Path = new System.Windows.PropertyPath("StandardStampList");
  116. StandardListBox.SetBinding(ListBox.ItemsSourceProperty, Standardbinding);
  117. Binding Custombinding = new Binding();
  118. Custombinding.Source = this;
  119. Custombinding.Path = new System.Windows.PropertyPath("CustomStampList");
  120. CustomListBox.SetBinding(ListBox.ItemsSourceProperty, Custombinding);
  121. ICollectionView groupView = CollectionViewSource.GetDefaultView(CustomStampList);
  122. groupView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CPDFStampData.TypeText)));
  123. }
  124. public void InitStandardStamp()
  125. {
  126. for (int i = 0; i < Path.Count; i++)
  127. {
  128. CPDFStampData standardStamp = new CPDFStampData();
  129. standardStamp.Author = "";
  130. standardStamp.Opacity = 1;
  131. standardStamp.SourcePath = Path[i];
  132. standardStamp.StampText = StampText[i];
  133. standardStamp.MaxWidth = MaxWidth[i];
  134. standardStamp.MaxHeight = MaxHeight[i];
  135. standardStamp.Type = StampType.STANDARD_STAMP;
  136. standardStamp.AnnotationType = CPDFAnnotationType.Stamp;
  137. StandardStampList.Add(standardStamp);
  138. }
  139. }
  140. /// <summary>
  141. /// Loading CacheStamp
  142. /// </summary>
  143. public void LoadSettings()
  144. {
  145. CustomStampList stamps = Settings.Default.CustomStampList;
  146. CustomStampList.Clear();
  147. if (stamps != null)
  148. {
  149. for (int i = 0; i < stamps.Count; i++)
  150. {
  151. CPDFStampData customStamp = new CPDFStampData();
  152. customStamp.Opacity = 1;
  153. customStamp.Author = stamps[i].Author;
  154. customStamp.StampText = stamps[i].StampText;
  155. customStamp.StampTextDate = stamps[i].StampTextDate;
  156. customStamp.MaxWidth = stamps[i].MaxWidth;
  157. customStamp.MaxHeight = stamps[i].MaxHeight;
  158. customStamp.SourcePath = stamps[i].SourcePath;
  159. customStamp.Type = stamps[i].Type;
  160. customStamp.TextSharp = stamps[i].TextSharp;
  161. customStamp.TextColor = stamps[i].TextColor;
  162. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  163. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  164. customStamp.AnnotationType = CPDFAnnotationType.Stamp;
  165. CustomStampList.Add(customStamp);
  166. }
  167. }
  168. }
  169. public void UpDataCustomStamp(CPDFStampData oldstamp)
  170. {
  171. if (oldstamp != null)
  172. {
  173. CustomStampList.Add(oldstamp);
  174. CustomStampList stamps = Settings.Default.CustomStampList;
  175. if (stamps == null)
  176. {
  177. stamps = Settings.Default.CustomStampList = new CustomStampList();
  178. }
  179. stamps.Add(oldstamp);
  180. Settings.Default.Save();
  181. }
  182. }
  183. private void Delete_Click(object sender, RoutedEventArgs e)
  184. {
  185. Button ThisButton = sender as Button;
  186. if (ThisButton != null)
  187. {
  188. CPDFStampData stampData = ThisButton.DataContext as CPDFStampData;
  189. if (stampData != null)
  190. {
  191. int index = CustomStampList.IndexOf(stampData);
  192. if (index != -1)
  193. {
  194. CPDFDeleteDialog cPDFDeleteDialog = new CPDFDeleteDialog("Warning", "Are you sure to delete?");
  195. cPDFDeleteDialog.Owner = Window.GetWindow(this);
  196. cPDFDeleteDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  197. cPDFDeleteDialog.ShowDialog();
  198. if (!cPDFDeleteDialog.IsDelete)
  199. {
  200. PropertyChanged?.Invoke(this, null);
  201. return;
  202. }
  203. if (stampData.SourcePath != null)
  204. {
  205. try
  206. {
  207. if (File.Exists(stampData.SourcePath))
  208. {
  209. File.Delete(stampData.SourcePath);
  210. }
  211. }
  212. catch (Exception)
  213. {
  214. }
  215. }
  216. CustomStampList.RemoveAt(index);
  217. CustomStampList stamps = Settings.Default.CustomStampList;
  218. if (stamps != null)
  219. {
  220. stamps.RemoveAt(index);
  221. Settings.Default.Save();
  222. }
  223. PropertyChanged?.Invoke(this, null);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }