HomePageControl.xaml.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using Compdfkit_Tools.Helper;
  17. using Path = System.Windows.Shapes.Path;
  18. namespace Compdfkit_Tools.PDFControl
  19. {
  20. /// <summary>
  21. /// Interaction logic for HomePageControl.xaml
  22. /// </summary>
  23. public partial class HomePageControl : UserControl
  24. {
  25. Canvas viewerCanvas = new Canvas();
  26. Canvas annotationsCanvas = new Canvas();
  27. Canvas formsCanvas = new Canvas();
  28. Canvas signatureCanvas = new Canvas();
  29. Canvas documentEditorCanvas = new Canvas();
  30. Canvas contentEditorCanvas = new Canvas();
  31. Canvas securityCanvas = new Canvas();
  32. Canvas redactionCanvas = new Canvas();
  33. Canvas waterCanvas = new Canvas();
  34. private List<CustomItem> customItems;
  35. /// <summary>
  36. /// Open file event.
  37. /// param: Whether to create a file
  38. /// </summary>
  39. public event EventHandler<OpenFileEventArgs> OpenFileEvent;
  40. public HomePageControl()
  41. {
  42. InitializeComponent();
  43. RecentFilesControl.OpenFileEvent += (sender, args) =>
  44. {
  45. OpenFileEvent?.Invoke(this, args);
  46. };
  47. }
  48. private void ImportFeatures()
  49. {
  50. if (FeaturesListControl != null)
  51. {
  52. foreach (CustomItem item in customItems)
  53. {
  54. FeaturesListControl.Items.Add(item);
  55. }
  56. }
  57. FeaturesListControl.SelectionChanged -= FeaturesListControl_SelectionChanged;
  58. FeaturesListControl.SelectionChanged += FeaturesListControl_SelectionChanged;
  59. }
  60. private void FeaturesListControl_SelectionChanged(object sender, CustomItem e)
  61. {
  62. var parentWindow = Window.GetWindow(this);
  63. switch (e.TitleText)
  64. {
  65. case "Watermark":
  66. {
  67. WatermarkOperationTypeDialog watermarkOperationTypeDialog = new WatermarkOperationTypeDialog()
  68. {
  69. Owner = parentWindow
  70. };
  71. watermarkOperationTypeDialog.ShowDialog();
  72. break;
  73. }
  74. case "Security":
  75. {
  76. SecurityOperationTypeDialog securityOperationTypeDialog = new SecurityOperationTypeDialog()
  77. {
  78. Owner = parentWindow
  79. };
  80. securityOperationTypeDialog.ShowDialog();
  81. break;
  82. }
  83. default:
  84. MessageBox.Show(e.TitleText + " is under development.");
  85. break;
  86. }
  87. }
  88. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  89. {
  90. CreatFeatureIcon();
  91. CreateCustomItems();
  92. ImportFeatures();
  93. UseTheScrollViewerScrolling(FeaturesListControl);
  94. }
  95. private void UseTheScrollViewerScrolling(FrameworkElement fElement)
  96. {
  97. fElement.PreviewMouseWheel += (sender, e) =>
  98. {
  99. var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
  100. eventArg.RoutedEvent = UIElement.MouseWheelEvent;
  101. eventArg.Source = sender;
  102. fElement.RaiseEvent(eventArg);
  103. };
  104. }
  105. private void CreateCustomItems()
  106. {
  107. customItems = new List<CustomItem>()
  108. {
  109. new CustomItem{ IconCanvas = viewerCanvas,TitleText = "Viewer", DescriptionText="View PDFs with tools like display modes, navigation, reading themes, scrolling, zooming, text searching, text reflow, split viewer, etc."},
  110. new CustomItem{ IconCanvas = annotationsCanvas,TitleText= "Annotations", DescriptionText="Annotate and markup PDFs with notes, links, texts, line, square, arrow, circle, highlight, underline, squiggly, strikeout, stamps, ink, signature, sound, etc. Allow to create, delete, edit, import, export, and flatten PDF annotations." },
  111. new CustomItem{ IconCanvas = formsCanvas, TitleText="Forms", DescriptionText="Create, delete, edit, fill, flatten, import, and export forms. Support a wide array of PDF form fields including text field, check box, radio button, list box, combo button, push button, and signatures."},
  112. new CustomItem{ IconCanvas = signatureCanvas,TitleText="Signature", DescriptionText="Sign PDFs with digital signatures and electronic signatures. Choose the drawn, image, or typed signatures and sign files conveniently. Or sign with your digital ID securely.\r\n"},
  113. new CustomItem{ IconCanvas = documentEditorCanvas, TitleText="Document Editor", DescriptionText="Process PDF pages and files. Add, insert, replace, extract, reverse, move, copy, paste, rotate, delete, crop, scale, etc."},
  114. new CustomItem{ IconCanvas = contentEditorCanvas, TitleText="Content Editor", DescriptionText="Edit the text and images with ComPDFKit Content Editor. Give you the freedom to adjust the size, position, style, font, etc.\r\n"},
  115. new CustomItem{ IconCanvas = securityCanvas,TitleText="Security", DescriptionText="Secure your documents using AES-128, AES-256, or RC4 encryption and decrypt PDFs. Customize permissions, edit headers & footers, change the background, insert or remove Bates numbers for indexing, etc.\r\n"},
  116. new CustomItem{ IconCanvas = redactionCanvas,TitleText="Redaction", DescriptionText="Use redaction to remove sensitive images, text, and vector graphics, that can't be recovered after applying the redaction. Support customizing redaction appearance and choosing an area or searching for specific text to redact.\r\n"},
  117. new CustomItem{ IconCanvas = waterCanvas,TitleText="Watermark", DescriptionText="Create, insert, and remove text or image watermarks to brand your users' work and discourage its unauthorized use.\r\n"},
  118. };
  119. }
  120. private void CreatFeatureIcon()
  121. {
  122. //Viewer
  123. {
  124. Path path1 = new Path
  125. {
  126. Data = Geometry.Parse("M13.2071 1.5H2.5V18.5H17.5V5.79289L13.2071 1.5Z"),
  127. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#80477EDE")),
  128. Clip = new RectangleGeometry(new Rect(0, 0, 20, 20))
  129. };
  130. Path path2 = new Path
  131. {
  132. Data = Geometry.Parse("M4.5 3.5H12.5L15.5 6.5V16.5H4.5L4.5 3.5Z"),
  133. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#477EDE")),
  134. };
  135. Path path3 = new Path
  136. {
  137. Data = Geometry.Parse("M9.95833 12.75C11.6763 12.75 13.1387 11.2833 13.6862 10.6551C13.8279 10.4925 13.8279 10.2575 13.6862 10.0949C13.1387 9.46673 11.6763 8 9.95833 8C8.24035 8 6.778 9.46673 6.23047 10.0949C6.08878 10.2575 6.08878 10.4925 6.23047 10.6551C6.778 11.2833 8.24035 12.75 9.95833 12.75Z"),
  138. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
  139. };
  140. Path path4 = new Path
  141. {
  142. Data = Geometry.Parse("M9.95833 11.3639C10.5049 11.3639 10.9479 10.9209 10.9479 10.3743C10.9479 9.82782 10.5049 9.38477 9.95833 9.38477C9.41181 9.38477 8.96875 9.82782 8.96875 10.3743C8.96875 10.9209 9.41181 11.3639 9.95833 11.3639Z"),
  143. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#477EDE"))
  144. };
  145. viewerCanvas.Children.Add(path1);
  146. viewerCanvas.Children.Add(path2);
  147. viewerCanvas.Children.Add(path3);
  148. viewerCanvas.Children.Add(path4);
  149. }
  150. // Annotations
  151. {
  152. Path path1 = new Path
  153. {
  154. Data = Geometry.Parse("M11.2071 0.5H0.5V17.5H15.5V4.79289L11.2071 0.5Z"),
  155. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#806675FE")),
  156. };
  157. Path path2 = new Path
  158. {
  159. Data = Geometry.Parse("M2.5 2.5H10.5L13.5 5.5V15.5H2.5L2.5 2.5Z"),
  160. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6675FE")),
  161. };
  162. Path path3 = new Path
  163. {
  164. Data = Geometry.Parse("M8.81755 12.6459C8.71612 12.559 8.56646 12.559 8.46503 12.6459L8.32746 12.7639C8.02318 13.0247 7.57419 13.0247 7.26991 12.7639L7.13234 12.6459C7.03091 12.559 6.88125 12.559 6.77982 12.6459L6.59593 12.8036C6.32336 13.0372 5.92977 13.0643 5.62778 12.8701L5.12441 12.5465C4.99859 12.4656 4.96216 12.2981 5.04305 12.1722C5.12393 12.0464 5.2915 12.01 5.41733 12.0909L5.9207 12.4145C6.02136 12.4792 6.15256 12.4702 6.24341 12.3923L6.4273 12.2347C6.73158 11.9739 7.18058 11.9739 7.48486 12.2347L7.62243 12.3526C7.72385 12.4395 7.87352 12.4395 7.97494 12.3526L8.11251 12.2347C8.41679 11.9739 8.86579 11.9739 9.17006 12.2347L9.35396 12.3923C9.44481 12.4702 9.57601 12.4792 9.67667 12.4145L10.18 12.0909C10.3059 12.01 10.4734 12.0464 10.5543 12.1722C10.6352 12.2981 10.5988 12.4656 10.473 12.5465L9.96959 12.8701C9.6676 13.0643 9.27401 13.0372 9.00144 12.8036L8.81755 12.6459Z"),
  165. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
  166. };
  167. Path path4 = new Path
  168. {
  169. Data = Geometry.Parse("M10.5066 6V7.15097H8.50593V11.0556H7.09957V7.15097H5.08984V6H10.5066Z"),
  170. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
  171. };
  172. annotationsCanvas.Children.Add(path1);
  173. annotationsCanvas.Children.Add(path2);
  174. annotationsCanvas.Children.Add(path3);
  175. annotationsCanvas.Children.Add(path4);
  176. }
  177. // Forms
  178. {
  179. Path path1 = new Path
  180. {
  181. Data = Geometry.Parse("M6.12502 4.25H1.90628V6.76817H6.12502V4.25ZM0.500028 3.55233V1.19767C0.500028 0.81236 0.812387 0.5 1.1977 0.5H14.8024C15.1877 0.5 15.5 0.81236 15.5 1.19767V3.55233V14.8023C15.5 15.1876 15.1877 15.5 14.8024 15.5H1.1977C0.812388 15.5 0.500028 15.1876 0.500028 14.8023V8.17442H0.5V6.76817H0.500028V3.55233ZM7.53127 4.25H14.0938V6.76817H7.53127V4.25ZM1.90628 8.17442H6.12502V14.0938H1.90628V8.17442ZM7.53127 14.0938H14.0938V8.17442H7.53127V14.0938ZM13.2437 9.73906C13.3232 9.81854 13.3232 9.94741 13.2437 10.0269L10.7112 12.5594C10.4552 12.8154 10.0403 12.8154 9.78432 12.5594L8.37532 11.1504C8.29584 11.071 8.29584 10.9421 8.37532 10.8626L8.74955 10.4884C8.82903 10.4089 8.9579 10.4089 9.03738 10.4884L10.2478 11.6988L12.5817 9.36484C12.6612 9.28535 12.79 9.28535 12.8695 9.36484L13.2437 9.73906Z"),
  182. Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")),
  183. };
  184. Path path2 = new Path
  185. {
  186. Data = Geometry.Parse("M6.12502 4.25H1.90628V6.76817H6.12502V4.25ZM0.500028 3.55233V1.19767C0.500028 0.81236 0.812387 0.5 1.1977 0.5H14.8024C15.1877 0.5 15.5 0.81236 15.5 1.19767V3.55233V14.8023C15.5 15.1876 15.1877 15.5 14.8024 15.5H1.1977C0.812388 15.5 0.500028 15.1876 0.500028 14.8023V8.17442H0.5V6.76817H0.500028V3.55233ZM7.53127 4.25H14.0938V6.76817H7.53127V4.25ZM1.90628 8.17442H6.12502V14.0938H1.90628V8.17442ZM7.53127 14.0938H14.0938V8.17442H7.53127V14.0938ZM13.2437 9.73906C13.3232 9.81854 13.3232 9.94741 13.2437 10.0269L10.7112 12.5594C10.4552 12.8154 10.0403 12.8154 9.78432 12.5594L8.37532 11.1504C8.29584 11.071 8.29584 10.9421 8.37532 10.8626L8.74955 10.4884C8.82903 10.4089 8.9579 10.4089 9.03738 10.4884L10.2478 11.6988L12.5817 9.36484C12.6612 9.28535 12.79 9.28535 12.8695 9.36484L13.2437 9.73906Z"),
  187. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#477EDE")),
  188. };
  189. formsCanvas.Children.Add(path1);
  190. formsCanvas.Children.Add(path2);
  191. }
  192. // Signature
  193. {
  194. Path path1 = new Path
  195. {
  196. Data = Geometry.Parse("M11.4771 3.16735C11.6151 2.96809 11.8998 2.94242 12.0712 3.11378L15.2582 6.30084C15.4296 6.4722 15.4039 6.75692 15.2047 6.89487L12.0633 9.06966C12.0332 9.09048 12.0114 9.12124 12.0018 9.15653L11.2248 12.0057C11.2059 12.0747 11.143 12.123 11.0717 12.1277C10.7929 12.1458 10.0064 12.2356 8.44611 12.6725C7.06518 13.0592 5.39632 13.8125 4.47439 14.2527C4.61684 14.5428 4.56744 14.9032 4.32618 15.1445C4.0228 15.4479 3.53092 15.4479 3.22754 15.1445C2.92415 14.8411 2.92415 14.3492 3.22754 14.0458C3.46379 13.8096 3.81435 13.7573 4.10119 13.889C4.57233 12.8495 5.42026 10.9231 5.69949 9.92588C6.02875 8.74998 6.19116 7.62277 6.23578 7.28285C6.24404 7.21992 6.28895 7.16832 6.35019 7.15162L9.21546 6.37018C9.25075 6.36056 9.28151 6.33879 9.30233 6.30872L11.4771 3.16735ZM14.7596 14.6595C14.7015 14.6633 14.6428 14.6651 14.5837 14.6651C14.5253 14.6651 14.4673 14.6633 14.4098 14.6597L13.209 16.7396C13.148 16.8452 12.9948 16.8427 12.9374 16.7352L12.4679 15.8567C12.44 15.8045 12.3849 15.7726 12.3258 15.7746L11.3303 15.8073C11.2084 15.8113 11.1297 15.6799 11.1906 15.5743L12.372 13.5281C12.0527 13.0824 11.8647 12.5362 11.8647 11.9461C11.8647 10.4445 13.082 9.22712 14.5837 9.22712C16.0854 9.22712 17.3027 10.4445 17.3027 11.9461C17.3027 12.5355 17.1152 13.0811 16.7966 13.5264L17.9789 15.5743C18.0399 15.6799 17.9611 15.8113 17.8393 15.8073L16.8437 15.7746C16.7846 15.7726 16.7295 15.8045 16.7016 15.8567L16.2322 16.7352C16.1747 16.8427 16.0215 16.8452 15.9606 16.7396L14.7596 14.6595Z"),
  197. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6675FE")),
  198. };
  199. Path path2 = new Path
  200. {
  201. Data = Geometry.Parse("M8.66951 8.63805C8.69551 8.59472 8.75532 8.58735 8.79106 8.62309L9.74899 9.58102C9.78473 9.61676 9.77737 9.67657 9.73403 9.70257L7.33919 11.1395C7.26984 11.1811 7.191 11.1022 7.23261 11.0329L8.66951 8.63805Z"),
  202. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff")),
  203. };
  204. signatureCanvas.Children.Add(path1);
  205. signatureCanvas.Children.Add(path2);
  206. }
  207. // Document Editor
  208. {
  209. Path path1 = new Path
  210. {
  211. Data = Geometry.Parse("M8.6 17.5H15.5V9.6H8.6V17.5ZM15.5 8.4V0.5H8.6V8.4H15.5ZM7.4 17.5V9.6H0.5V17.5H7.4ZM0.5 8.4H7.4V0.5H0.5V8.4Z"),
  212. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#477EDE")),
  213. };
  214. documentEditorCanvas.Children.Add(path1);
  215. }
  216. // Content Editor
  217. {
  218. Path path1 = new Path
  219. {
  220. Data = Geometry.Parse("M4.13281 15.8681V4.13281H15.8681V15.8681H4.13281Z"),
  221. Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F08E26")),
  222. StrokeThickness = 1.5
  223. };
  224. Path path2 = new Path
  225. {
  226. Data = Geometry.Parse("M6.42546 6.0293C6.33775 6.0293 6.26664 6.1004 6.26664 6.18812V6.7528C6.26664 6.84051 6.33775 6.91162 6.42546 6.91162H8.83596C8.92368 6.91162 8.99478 6.84051 8.99478 6.7528V6.18812C8.99478 6.1004 8.92368 6.0293 8.83596 6.0293H6.42546ZM10.1456 6.02938C10.0579 6.02938 9.98679 6.10049 9.98679 6.1882V8.51753C9.98679 8.60524 10.0579 8.67635 10.1456 8.67635H13.5482C13.6359 8.67635 13.707 8.60524 13.707 8.51753V6.1882C13.707 6.10049 13.6359 6.02938 13.5482 6.02938H10.1456ZM6.2666 7.95299C6.2666 7.86527 6.33771 7.79416 6.42543 7.79416H8.83592C8.92364 7.79416 8.99475 7.86527 8.99475 7.95299V8.51766C8.99475 8.60538 8.92364 8.67649 8.83592 8.67649H6.42543C6.33771 8.67649 6.2666 8.60538 6.2666 8.51766V7.95299ZM6.42543 9.55876C6.33771 9.55876 6.2666 9.62987 6.2666 9.71759V10.2823C6.2666 10.37 6.33771 10.4411 6.42542 10.4411H13.5482C13.6359 10.4411 13.707 10.37 13.707 10.2823V9.71759C13.707 9.62987 13.6359 9.55876 13.5482 9.55876H6.42543ZM6.2666 11.4822C6.2666 11.3945 6.33771 11.3234 6.42543 11.3234H13.5482C13.6359 11.3234 13.707 11.3945 13.707 11.4822V12.0469C13.707 12.1346 13.6359 12.2057 13.5482 12.2057H6.42542C6.33771 12.2057 6.2666 12.1346 6.2666 12.0469V11.4822ZM6.42543 13.0881C6.33771 13.0881 6.2666 13.1593 6.2666 13.247V13.8116C6.2666 13.8994 6.33771 13.9705 6.42542 13.9705H11.3161C11.4038 13.9705 11.4749 13.8994 11.4749 13.8116V13.247C11.4749 13.1593 11.4038 13.0881 11.3161 13.0881H6.42543Z"),
  227. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F08E26")),
  228. };
  229. for (int i = 0; i < 4; i++)
  230. {
  231. Rectangle rectangle = new Rectangle
  232. {
  233. Width = 2.64706,
  234. Height = 2.64706,
  235. RadiusX = 0.441176,
  236. RadiusY = 0.441176,
  237. Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F08E26")),
  238. Opacity = 0.5
  239. };
  240. switch (i)
  241. {
  242. case 0:
  243. Canvas.SetLeft(rectangle, 2.5);
  244. Canvas.SetTop(rectangle, 2.5);
  245. break;
  246. case 1:
  247. Canvas.SetLeft(rectangle, 14.8525);
  248. Canvas.SetTop(rectangle, 2.5);
  249. break;
  250. case 2:
  251. Canvas.SetLeft(rectangle, 2.5);
  252. Canvas.SetTop(rectangle, 14.8535);
  253. break;
  254. case 3:
  255. Canvas.SetLeft(rectangle, 14.8525);
  256. Canvas.SetTop(rectangle, 14.8535);
  257. break;
  258. }
  259. contentEditorCanvas.Children.Add(rectangle);
  260. }
  261. contentEditorCanvas.Children.Add(path1);
  262. contentEditorCanvas.Children.Add(path2);
  263. }
  264. }
  265. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  266. {
  267. }
  268. private void CreateDocument_Click(object sender, RoutedEventArgs e)
  269. {
  270. OpenFileEvent?.Invoke(this, new OpenFileEventArgs(FileOperationType.CreateNewFile));
  271. }
  272. private void OpenDocument_Click(object sender, RoutedEventArgs e)
  273. {
  274. OpenFileEvent?.Invoke(this, new OpenFileEventArgs(FileOperationType.OpenFileDialog));
  275. }
  276. }
  277. public class OpenFileEventArgs : EventArgs
  278. {
  279. public string FilePath { get; set; } // 文件路径
  280. public FileOperationType OperationType { get; set; } // 操作类型
  281. public OpenFileEventArgs(FileOperationType operationType, string filePath = "")
  282. {
  283. OperationType = operationType;
  284. FilePath = filePath;
  285. }
  286. }
  287. public enum FileOperationType
  288. {
  289. CreateNewFile,
  290. OpenFileDialog,
  291. OpenFileDirectly
  292. }
  293. }