AnnotationListItem.xaml.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. TxbMarkUpContent.Text = data.MarkupContent;
  46. TxbContext.Text = data.Content;
  47. if (data == null)
  48. {
  49. return;
  50. }
  51. switch (data.EventType)
  52. {
  53. case AnnotArgsType.AnnotFreeText:
  54. BtnAnnotFreeText.Visibility = Visibility.Visible;
  55. TxbMarkUpContent.Foreground = new SolidColorBrush((data as FreeTextAnnotArgs).FontColor);
  56. break;
  57. case AnnotArgsType.AnnotHighlight:
  58. BtnHighlight.Visibility = Visibility.Visible;
  59. PathHighlight.Background = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  60. //TxbContext.Text = data.Content;
  61. if (!string.IsNullOrEmpty(TxbContext.Text))
  62. {
  63. TxbContext.Background = new SolidColorBrush((data as TextHighlightAnnotArgs).Color);
  64. }
  65. break;
  66. case AnnotArgsType.AnnotFreehand:
  67. BtnFreeHand.Visibility = Visibility.Visible;
  68. PathFreehand.Fill = new SolidColorBrush((data as FreehandAnnotArgs).InkColor);
  69. ImageContext.Visibility = Visibility.Visible;
  70. TxbContext.Visibility = Visibility.Collapsed;
  71. //var encoder = new PngBitmapEncoder();
  72. //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
  73. //FileStream file = new FileStream(String.Format($@"C:\Users\oyxh\Desktop\images\PDFText\{data.AnnotIndex}.png"), FileMode.Create);
  74. //encoder.Save(file);
  75. //file.Close();
  76. break;
  77. case AnnotArgsType.AnnotSquiggly://波浪线
  78. AnnotSquiggly.Visibility = Visibility.Visible;
  79. AnnotSquigglycolor.Stroke = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  80. #region TO DO
  81. //TextDecoration mySquiggly = new TextDecoration();
  82. //Pen myPen = new Pen();
  83. //myPen.Brush = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  84. //myPen.Brush.Opacity = 0.8;
  85. //myPen.Thickness = 2;
  86. //myPen.DashStyle = DashStyles.Dash;
  87. //mySquiggly.Pen = myPen;
  88. //mySquiggly.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  89. //TextDecorationCollection myCollection = new TextDecorationCollection();
  90. //myCollection.Add(mySquiggly);
  91. //TxbContext.TextDecorations = myCollection;
  92. #endregion TO DO
  93. break;
  94. case AnnotArgsType.AnnotStamp:
  95. BtnAnnotStamp.Visibility = Visibility.Visible;
  96. break;
  97. case AnnotArgsType.AnnotStrikeout://删除线
  98. BtnAnnotStrikeout.Visibility = Visibility.Visible;
  99. PathStrikeoutyColor.Fill = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  100. #region to do
  101. TextDecoration myStrikeout = new TextDecoration();
  102. Pen myPen2 = new Pen();
  103. myPen2.Brush = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  104. myPen2.Brush.Opacity = 0.8;
  105. myPen2.Thickness = 2;
  106. myStrikeout.Pen = myPen2;
  107. myStrikeout.PenOffset = -4;
  108. myStrikeout.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  109. TextDecorationCollection myCollection2 = new TextDecorationCollection();
  110. myCollection2.Add(myStrikeout);
  111. //因为波浪线无法实现 暂时只显示文字 不显示下划线,删除线等
  112. TxbContext.TextDecorations = myCollection2;
  113. #endregion to do
  114. break;
  115. case AnnotArgsType.AnnotSticky://便签
  116. BtnAnnotSticky.Visibility = Visibility;
  117. PathSticky.Fill = new SolidColorBrush((data as StickyAnnotArgs).Color);
  118. break;
  119. case AnnotArgsType.AnnotUnderline:
  120. BtnUnderLine.Visibility = Visibility.Visible;
  121. RectangleUnderline.Fill = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  122. #region TO DO
  123. TextDecoration myUnderline = new TextDecoration();
  124. Pen myPen1 = new Pen();
  125. myPen1.Brush = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  126. myPen1.Brush.Opacity = 0.8;
  127. myPen1.Thickness = 2;
  128. myUnderline.Pen = myPen1;
  129. myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  130. TextDecorationCollection myCollection1 = new TextDecorationCollection();
  131. myCollection1.Add(myUnderline);
  132. TxbContext.TextDecorations = myCollection1;
  133. #endregion TO DO
  134. break;
  135. case AnnotArgsType.AnnotLine:
  136. if ((data as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (data as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  137. {
  138. BtnSharpArrow.Visibility = Visibility.Visible;
  139. PathArrow.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  140. }
  141. else
  142. {
  143. PathSharpLine.Fill = new SolidColorBrush((data as LineAnnotArgs).LineColor);
  144. BtnSharpLine.Visibility = Visibility.Visible;
  145. }
  146. ///对于形状注释等只有Note 的处理
  147. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  148. {
  149. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  150. TxbContext.Text = "";
  151. }
  152. break;
  153. case AnnotArgsType.AnnotSquare:
  154. BtnAnnotSquare.Visibility = Visibility.Visible;
  155. RectAnnotSquare.Stroke = new SolidColorBrush((data as SquareAnnotArgs).LineColor);
  156. RectAnnotSquare.Fill = new SolidColorBrush((data as SquareAnnotArgs).BgColor);
  157. ///对于形状注释等只有Note 的处理
  158. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  159. {
  160. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  161. TxbContext.Text = "";
  162. }
  163. break;
  164. case AnnotArgsType.AnnotCircle:
  165. BtnAnnotCircle.Visibility = Visibility.Visible;
  166. EllipseCircle.Stroke = new SolidColorBrush((data as CircleAnnotArgs).LineColor);
  167. EllipseCircle.Fill = new SolidColorBrush((data as CircleAnnotArgs).BgColor);
  168. ///对于形状注释等只有Note 的处理
  169. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  170. {
  171. TxbMarkUpContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  172. TxbContext.Text = "";
  173. }
  174. break;
  175. case AnnotArgsType.AnnotLink:
  176. BtnAnnotLink.Visibility = Visibility.Visible;
  177. if (data is LinkAnnotArgs linkAnnotArgs)
  178. {
  179. if (string.IsNullOrEmpty(linkAnnotArgs.Content))
  180. {
  181. if (linkAnnotArgs.DestIndex != -1)
  182. {
  183. TxbContext.Text = string.Format($"To Page {linkAnnotArgs.DestIndex + 1}");
  184. }
  185. else
  186. {
  187. TxbContext.Text = string.Format($"{linkAnnotArgs.URI}");
  188. }
  189. }
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. }
  196. }
  197. }