AnnotationListItem.xaml.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFPage;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.AnnotEvent;
  7. using ComPDFKitViewer.PdfViewer;
  8. using PDF_Office.Helper;
  9. using PDF_Office.Model.BOTA;
  10. using PDF_Office.ViewModels.BOTA;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Data;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using System.Windows.Navigation;
  27. using System.Windows.Shapes;
  28. namespace PDF_Office.Views.BOTA
  29. {
  30. /// <summary>
  31. /// AnnotationListItem.xaml 的交互逻辑
  32. /// </summary>
  33. public partial class AnnotationListItem : System.Windows.Controls.UserControl
  34. {
  35. //private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  36. public AnnotationListItem()
  37. {
  38. InitializeComponent();
  39. }
  40. private void GridIco_Loaded(object sender, RoutedEventArgs e)
  41. {
  42. Grid grid = e.Source as Grid;
  43. var args = grid.DataContext as AnnotationHandlerEventArgs;
  44. AnnotHandlerEventArgs data = args.AnnotHandlerEventArgs;
  45. if (data == null)
  46. {
  47. return;
  48. }
  49. switch (data.EventType)
  50. {
  51. case AnnotArgsType.AnnotFreeText:
  52. BtnAnnotFreeText.Visibility = Visibility.Visible;
  53. TxbMarkUpContent.Foreground = new SolidColorBrush((data as FreeTextAnnotArgs).FontColor);
  54. break;
  55. case AnnotArgsType.AnnotHighlight:
  56. BtnHighlight.Visibility = Visibility.Visible;
  57. PathHighlight.Background = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  58. //TxbContext.Text = data.Content;
  59. if (!string.IsNullOrEmpty(TxbContext.Text))
  60. {
  61. TxbContext.Background = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  62. }
  63. break;
  64. case AnnotArgsType.AnnotFreehand:
  65. BtnFreeHand.Visibility = Visibility.Visible;
  66. PathFreehand.Fill = new SolidColorBrush((data as FreehandAnnotArgs).InkColor);
  67. ImageContext.Visibility = Visibility.Visible;
  68. TxbContext.Visibility = Visibility.Collapsed;
  69. //var encoder = new PngBitmapEncoder();
  70. //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
  71. //FileStream file = new FileStream(String.Format($@"C:\Users\oyxh\Desktop\images\PDFText\{data.AnnotIndex}.png"), FileMode.Create);
  72. //encoder.Save(file);
  73. //file.Close();
  74. break;
  75. case AnnotArgsType.AnnotSquiggly://波浪线
  76. AnnotSquiggly.Visibility = Visibility.Visible;
  77. AnnotSquigglycolor.Stroke = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  78. #region TO DO
  79. //TextDecoration mySquiggly = new TextDecoration();
  80. //Pen myPen = new Pen();
  81. //myPen.Brush = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  82. //myPen.Brush.Opacity = 0.8;
  83. //myPen.Thickness = 2;
  84. //myPen.DashStyle = DashStyles.Dash;
  85. //mySquiggly.Pen = myPen;
  86. //mySquiggly.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  87. //TextDecorationCollection myCollection = new TextDecorationCollection();
  88. //myCollection.Add(mySquiggly);
  89. //TxbContext.TextDecorations = myCollection;
  90. #endregion TO DO
  91. break;
  92. case AnnotArgsType.AnnotStamp:
  93. BtnAnnotStamp.Visibility = Visibility.Visible;
  94. break;
  95. case AnnotArgsType.AnnotStrikeout://删除线
  96. BtnAnnotStrikeout.Visibility = Visibility.Visible;
  97. PathStrikeoutyColor.Fill = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  98. #region to do
  99. TextDecoration myStrikeout = new TextDecoration();
  100. Pen myPen2 = new Pen();
  101. myPen2.Brush = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  102. myPen2.Brush.Opacity = 0.8;
  103. myPen2.Thickness = 2;
  104. myStrikeout.Pen = myPen2;
  105. myStrikeout.PenOffset = -4;
  106. myStrikeout.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  107. TextDecorationCollection myCollection2 = new TextDecorationCollection();
  108. myCollection2.Add(myStrikeout);
  109. //因为波浪线无法实现 暂时只显示文字 不显示下划线,删除线等
  110. TxbContext.TextDecorations = myCollection2;
  111. #endregion to do
  112. break;
  113. case AnnotArgsType.AnnotSticky://便签
  114. BtnAnnotSticky.Visibility = Visibility;
  115. PathSticky.Fill = new SolidColorBrush((data as StickyAnnotArgs).Color);
  116. break;
  117. case AnnotArgsType.AnnotUnderline:
  118. BtnUnderLine.Visibility = Visibility.Visible;
  119. RectangleUnderline.Fill = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  120. #region TO DO
  121. TextDecoration myUnderline = new TextDecoration();
  122. Pen myPen1 = new Pen();
  123. myPen1.Brush = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  124. myPen1.Brush.Opacity = 0.8;
  125. myPen1.Thickness = 2;
  126. myUnderline.Pen = myPen1;
  127. myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  128. TextDecorationCollection myCollection1 = new TextDecorationCollection();
  129. myCollection1.Add(myUnderline);
  130. TxbContext.TextDecorations = myCollection1;
  131. #endregion TO DO
  132. break;
  133. case AnnotArgsType.AnnotLine:
  134. if ((data as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (data as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  135. {
  136. BtnSharpArrow.Visibility = Visibility.Visible;
  137. PathArrow.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  138. }
  139. else
  140. {
  141. PathSharpLine.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  142. BtnSharpLine.Visibility = Visibility.Visible;
  143. }
  144. ///对于形状注释等只有Note 的处理
  145. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  146. {
  147. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  148. TxbContext.Text = "";
  149. }
  150. break;
  151. case AnnotArgsType.AnnotSquare:
  152. BtnAnnotSquare.Visibility = Visibility.Visible;
  153. RectAnnotSquare.Stroke = new SolidColorBrush((data as SquareAnnotArgs).LineColor);
  154. RectAnnotSquare.Fill = new SolidColorBrush((data as SquareAnnotArgs).BgColor);
  155. ///对于形状注释等只有Note 的处理
  156. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  157. {
  158. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  159. TxbContext.Text = "";
  160. }
  161. break;
  162. case AnnotArgsType.AnnotCircle:
  163. BtnAnnotCircle.Visibility = Visibility.Visible;
  164. EllipseCircle.Stroke = new SolidColorBrush((data as CircleAnnotArgs).LineColor);
  165. EllipseCircle.Fill = new SolidColorBrush((data as CircleAnnotArgs).BgColor);
  166. ///对于形状注释等只有Note 的处理
  167. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  168. {
  169. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  170. TxbContext.Text = "";
  171. }
  172. break;
  173. case AnnotArgsType.AnnotLink:
  174. BtnAnnotLink.Visibility = Visibility.Visible;
  175. if (data is LinkAnnotArgs linkAnnotArgs)
  176. {
  177. if (string.IsNullOrEmpty(linkAnnotArgs.Content))
  178. {
  179. if (linkAnnotArgs.DestIndex != -1)
  180. {
  181. TxbContext.Text = string.Format($"To Page {linkAnnotArgs.DestIndex + 1}");
  182. }
  183. else
  184. {
  185. TxbContext.Text = string.Format($"{linkAnnotArgs.URI}");
  186. }
  187. }
  188. }
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. }
  195. }