AnnotationListItem.xaml.cs 10 KB

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