AnnotationContentViewModel.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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 DryIoc;
  9. using ImTools;
  10. using Microsoft.Office.Interop.Excel;
  11. using Microsoft.Office.Interop.PowerPoint;
  12. using Microsoft.Office.Interop.Word;
  13. using PDF_Office.CustomControl;
  14. using PDF_Office.DataConvert;
  15. using PDF_Office.Helper;
  16. using PDF_Office.Model;
  17. using PDF_Office.Model.BOTA;
  18. using PDF_Office.Views.BOTA;
  19. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  20. using PDF_Office.Views.Scan;
  21. using Prism.Commands;
  22. using Prism.Mvvm;
  23. using Prism.Regions;
  24. using Prism.Services.Dialogs;
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Collections.ObjectModel;
  28. using System.ComponentModel;
  29. using System.Configuration;
  30. using System.Drawing;
  31. using System.Linq;
  32. using System.Text;
  33. using System.Threading.Tasks;
  34. using System.Windows;
  35. using System.Windows.Annotations;
  36. using System.Windows.Annotations.Storage;
  37. using System.Windows.Controls;
  38. using System.Windows.Data;
  39. using System.Windows.Documents;
  40. using System.Windows.Forms;
  41. using System.Windows.Markup;
  42. using System.Windows.Media;
  43. using System.Windows.Media.Imaging;
  44. using System.Windows.Shapes;
  45. using static Dropbox.Api.Files.SearchMatchType;
  46. using static Dropbox.Api.TeamLog.SpaceCapsType;
  47. using static System.Net.Mime.MediaTypeNames;
  48. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  49. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
  50. using Border = System.Windows.Controls.Border;
  51. using ListBox = System.Windows.Controls.ListBox;
  52. using Task = System.Threading.Tasks.Task;
  53. using TextBox = System.Windows.Controls.TextBox;
  54. using Winform = System.Windows.Forms;
  55. namespace PDF_Office.ViewModels.BOTA
  56. {
  57. public class AnnotationContentViewModel : BindableBase, INavigationAware
  58. {
  59. private ListBox listBox;
  60. private IRegionManager region;
  61. private IDialogService dialogs;
  62. private Visibility isEmptyPanelVisibility = Visibility.Visible;
  63. public ViewContentViewModel ViewContentViewModel { get; set; }
  64. public CPDFViewer PdfViewer { get; set; }
  65. public Visibility IsEmptyPanelVisibility
  66. {
  67. get { return isEmptyPanelVisibility; }
  68. set
  69. {
  70. SetProperty(ref isEmptyPanelVisibility, value);
  71. }
  72. }
  73. private ObservableCollection<AnnotationHandlerEventArgs> currentAnnotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  74. public ObservableCollection<AnnotationHandlerEventArgs> CurrentAnnotationArgs { get => currentAnnotationArgs; set => currentAnnotationArgs = value; }
  75. private AnnotationSortOrder annotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  76. public AnnotationSortOrder AnnotationSortOrder
  77. {
  78. get { return annotationSortOrder; }
  79. set { annotationSortOrder = value; }
  80. }
  81. private ObservableCollection<AnnotationHandlerEventArgs> annotationListItems;
  82. public ObservableCollection<AnnotationHandlerEventArgs> AnnotationListItems
  83. {
  84. get { return annotationListItems; }
  85. set
  86. {
  87. SetProperty(ref annotationListItems, value);
  88. }
  89. }
  90. private List<string> colors = new List<string>();
  91. private List<string> authors = new List<string>();
  92. private List<AnnotArgsType> annotArgsTypes = new List<AnnotArgsType>();
  93. public DelegateCommand<object> LoadedCommand { get; set; }
  94. public DelegateCommand<object> ListBoxItemPreviewMouseLeftButtonDown { get; set; }
  95. public DelegateCommand<object> AddNotesCommand { get; set; }
  96. public DelegateCommand<object> ScreenCommand { get; set; }
  97. public DelegateCommand<object> ExportCommentsCommand { get; set; }
  98. public DelegateCommand<object> ImportCommentsCommand { get; set; }
  99. public DelegateCommand<object> DeleteCommand { get; set; }
  100. public DelegateCommand DeleteAllCommand { get; set; }
  101. public DelegateCommand PageSortCommand { get; set; }
  102. public DelegateCommand TimeAscendingCommand { get; set; }
  103. public DelegateCommand TimeDescendingCommand { get; set; }
  104. public AnnotationContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  105. {
  106. region = regionManager;
  107. dialogs = dialogService;
  108. LoadedCommand = new DelegateCommand<object>(Loaded);
  109. ListBoxItemPreviewMouseLeftButtonDown = new DelegateCommand<object>(ListBoxItem_PreviewMouseLeftButtonDown);
  110. AddNotesCommand = new DelegateCommand<object>(AddNotesEvent);
  111. ScreenCommand = new DelegateCommand<object>(ScreenEvent);
  112. ExportCommentsCommand = new DelegateCommand<object>(ExportCommentsEvent);
  113. ImportCommentsCommand = new DelegateCommand<object>(ImportCommentsEvent);
  114. DeleteCommand = new DelegateCommand<object>(DelegateEvent);
  115. DeleteAllCommand = new DelegateCommand(DeleteAllEvent);
  116. PageSortCommand = new DelegateCommand(PageSortEvent);
  117. TimeAscendingCommand = new DelegateCommand(TimeAscendingEvent);
  118. TimeDescendingCommand = new DelegateCommand(TimeDescendingEvent);
  119. }
  120. /// <summary>
  121. /// 导入注释
  122. /// </summary>
  123. /// <param name="obj"></param>
  124. private async void ImportCommentsEvent(object obj)
  125. {
  126. Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  127. dlg.Filter = "PDF|*.xfdf";
  128. dlg.DefaultExt = ".xfdf";
  129. if (dlg.ShowDialog() == true)
  130. {
  131. try
  132. {
  133. string fileName = dlg.FileName;
  134. await Task.Delay(10);
  135. var result = PdfViewer.ImportAnnotationFromXFDFPath(fileName);
  136. if (result == false)
  137. {
  138. //MessageBoxEx.Show("导入失败", "", Winform.MessageBoxButtons.OK, Winform.MessageBoxIcon.Error);
  139. AlertsMessage alertsMessage = new AlertsMessage();
  140. alertsMessage.Show("提示", "导入失败!", "OK");
  141. return;
  142. }
  143. PdfViewer.ReloadVisibleAnnots();
  144. //提取出来的注释文件 时间为空 则显示未系统当前时间
  145. CurrentAnnotationArgs = GetDocumentAnnotionList();
  146. AnnotationListItems.Clear();
  147. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  148. await Task.Delay(5);
  149. RefreshAnnotationListItems(null);
  150. PdfViewer.UndoManager.CanSave = true;
  151. }
  152. catch (Exception ex)
  153. {
  154. AlertsMessage alertsMessage = new AlertsMessage();
  155. alertsMessage.Show("提示", "导入失败!" + ex.Message, "OK");
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// 时间倒序
  161. /// </summary>
  162. private void TimeDescendingEvent()
  163. {
  164. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  165. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  166. v.GroupDescriptions.Clear();
  167. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  168. v.SortDescriptions.Clear();
  169. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Descending));
  170. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Descending));
  171. AnnotationSortOrder = AnnotationSortOrder.TimeDescending;
  172. }
  173. /// <summary>
  174. /// 时间正序
  175. /// </summary>
  176. private void TimeAscendingEvent()
  177. {
  178. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  179. CreateTimeToDate createTimeToDate = new CreateTimeToDate();
  180. v.GroupDescriptions.Clear();
  181. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.CreateTime), createTimeToDate));
  182. v.SortDescriptions.Clear();
  183. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.CreateTime), ListSortDirection.Ascending));
  184. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  185. AnnotationSortOrder = AnnotationSortOrder.TimeAscending;
  186. }
  187. /// <summary>
  188. /// 页面排序
  189. /// </summary>
  190. private void PageSortEvent()
  191. {
  192. ICollectionView v = CollectionViewSource.GetDefaultView(AnnotationListItems);
  193. v.GroupDescriptions.Clear();
  194. v.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotHandlerEventArgs.PageIndex)));
  195. v.SortDescriptions.Clear();
  196. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  197. v.SortDescriptions.Add(new SortDescription(nameof(AnnotHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  198. AnnotationSortOrder = AnnotationSortOrder.PageIndexAscending;
  199. }
  200. /// <summary>
  201. /// 删除所有注释
  202. /// </summary>
  203. private void DeleteAllEvent()
  204. {
  205. //调用集中删除的接口 方便一次性undo
  206. Dictionary<int, List<int>> deleteLists = new Dictionary<int, List<int>>();
  207. for (int i = 0; i < AnnotationListItems.Count; i++)
  208. {
  209. AnnotationHandlerEventArgs item = AnnotationListItems[i] as AnnotationHandlerEventArgs;
  210. if (!deleteLists.ContainsKey(item.PageIndex))
  211. {
  212. deleteLists.Add(item.PageIndex, new List<int>() { item.AnnotIndex });
  213. }
  214. else
  215. {
  216. var pagelist = deleteLists[item.PageIndex];
  217. pagelist.Add(item.AnnotIndex);
  218. }
  219. }
  220. PdfViewer.RemovePageAnnot(deleteLists);
  221. AnnotationListItems.Clear();
  222. CurrentAnnotationArgs.Clear();
  223. PdfViewer.UndoManager.CanSave = true;
  224. }
  225. /// <summary>
  226. /// 删除注释,单个/多个
  227. /// </summary>
  228. /// <param name="obj"></param>
  229. private void DelegateEvent(object obj)
  230. {
  231. if (obj is AnnotationHandlerEventArgs annotation)
  232. {
  233. if (annotation != null)
  234. {
  235. var result = PdfViewer.RemovePageAnnot(annotation.PageIndex, annotation.AnnotIndex);
  236. if (result)
  237. {
  238. AnnotationListItems.Remove(annotation);
  239. var annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
  240. CurrentAnnotationArgs.Remove(annotation1);
  241. //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
  242. UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
  243. PdfViewer.UndoManager.CanSave = true;
  244. }
  245. }
  246. }
  247. }
  248. /// <summary>
  249. /// 删除之后,更新
  250. /// </summary>
  251. /// <param name="pageIndex"></param>
  252. /// <param name="annoteIndex"></param>
  253. private void UpdateAnnotListAfterDelete(int pageIndex, int annoteIndex)
  254. {
  255. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  256. for (int j = 0; j < items.Count; j++)//用修改赋值的方式 可以解决删除后表头折叠的问题
  257. {
  258. if (items[j].AnnotIndex >= annoteIndex)//只需要更新比删除元素索引大的注释
  259. {
  260. for (int k = 0; k < AnnotationListItems.Count; k++)
  261. {
  262. //相当于将后面的索引-1
  263. if (AnnotationListItems[k].PageIndex == pageIndex &&
  264. AnnotationListItems[k].AnnotIndex == (items[j].AnnotIndex + 1) &&
  265. string.Equals(AnnotationListItems[k].MarkupContent, items[j].MarkupContent) &&
  266. string.Equals(AnnotationListItems[k].Content, items[j].Content) &&
  267. string.Equals(AnnotationListItems[k].CreateTime, items[j].CreateTime) &&
  268. string.Equals(AnnotationListItems[k].Author, items[j].Author)
  269. )
  270. {
  271. AnnotationListItems[k].AnnotHandlerEventArgs = items[j];
  272. AnnotationListItems[k].PageIndex = items[j].PageIndex;
  273. AnnotationListItems[k].AnnotIndex = items[j].AnnotIndex;
  274. AnnotationListItems[k].EventType = items[j].EventType;
  275. AnnotationListItems[k].CreateTime = items[j].CreateTime;
  276. AnnotationListItems[k].UpdateTime = items[j].UpdateTime;
  277. if (items[j].EventType == AnnotArgsType.AnnotFreehand)
  278. {
  279. WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, items[j].PageIndex, items[j].AnnotIndex);
  280. AnnotationListItems[k].WriteableBitmap = bitmap;
  281. }
  282. AnnotationListItems[k].Content = items[j].Content;
  283. AnnotationListItems[k].MarkupContent = items[j].MarkupContent;
  284. AnnotationListItems[k].Author = items[j].Author;
  285. AnnotationListItems[k].Locked = items[j].Locked;
  286. AnnotationListItems[k].ReadOnly = items[j].ReadOnly;
  287. AnnotationListItems[k].FormField = items[j].FormField;
  288. AnnotationListItems[k].Document = PdfViewer.Document;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// 导出注释
  296. /// </summary>
  297. /// <param name="obj"></param>
  298. private void ExportCommentsEvent(object obj)
  299. {
  300. if (ViewContentViewModel.CanSave)
  301. {
  302. ViewContentViewModel.SaveFile.Execute();
  303. }
  304. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  305. dlg.Filter = "PDF|*.xfdf";
  306. dlg.DefaultExt = ".xfdf";
  307. dlg.FileName = PdfViewer.Document.FileName;
  308. if (dlg.ShowDialog() == true)
  309. {
  310. string fileName = dlg.FileName;
  311. var result = PdfViewer.ExportAnnotationToXFDFPath(fileName);
  312. if (result)
  313. {
  314. //MessageBoxEx.Show("导出成功", "", Winform.MessageBoxButtons.OK);
  315. AlertsMessage alertsMessage = new AlertsMessage();
  316. alertsMessage.Show("提示", "导出成功!", "OK");
  317. }
  318. else
  319. {
  320. AlertsMessage alertsMessage = new AlertsMessage();
  321. alertsMessage.Show("提示", "导出失败!", "OK");
  322. //MessageBoxEx.Show("导出失败", "", Winform.MessageBoxButtons.OK, Winform.MessageBoxIcon.Error);
  323. }
  324. }
  325. }
  326. /// <summary>
  327. /// 筛选注释
  328. /// </summary>
  329. /// <param name="obj"></param>
  330. private void ScreenEvent(object obj)
  331. {
  332. if (obj is System.Windows.Controls.Button button)
  333. {
  334. DialogParameters value = new DialogParameters();
  335. value.Add(ParameterNames.AnnotationList, CurrentAnnotationArgs);
  336. value.Add(ParameterNames.AnnotArgsTypes, annotArgsTypes);
  337. value.Add(ParameterNames.AnnotationColors, colors);
  338. value.Add(ParameterNames.AnnotationAuthor, authors);
  339. dialogs.ShowDialog(DialogNames.ScreenAnnotationDialog, value, e =>
  340. {
  341. if (e.Result == ButtonResult.OK && e.Parameters != null)
  342. {
  343. bool cleanState = false;
  344. if (e.Parameters.ContainsKey(ParameterNames.AnnotationCleanState))
  345. {
  346. cleanState = e.Parameters.GetValue<bool>(ParameterNames.AnnotationCleanState);
  347. if (cleanState)
  348. {
  349. colors.Clear();
  350. authors.Clear();
  351. annotArgsTypes.Clear();
  352. AnnotationListItems.Clear();
  353. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  354. RefreshAnnotationListItems(button);
  355. }
  356. else
  357. {
  358. if (e.Parameters.ContainsKey(ParameterNames.AnnotArgsTypes))
  359. {
  360. annotArgsTypes = e.Parameters.GetValue<List<AnnotArgsType>>(ParameterNames.AnnotArgsTypes);
  361. }
  362. if (e.Parameters.ContainsKey(ParameterNames.AnnotationColors))
  363. {
  364. colors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationColors);
  365. }
  366. if (e.Parameters.ContainsKey(ParameterNames.AnnotationAuthor))
  367. {
  368. authors = e.Parameters.GetValue<List<string>>(ParameterNames.AnnotationAuthor);
  369. }
  370. ObservableCollection<AnnotationHandlerEventArgs> screenAnnotationArgs = SelectAnnotationListItems(annotArgsTypes, colors, authors);
  371. AnnotationListItems.Clear();
  372. AnnotationListItems.AddRange(screenAnnotationArgs);
  373. RefreshAnnotationListItems(button);
  374. }
  375. }
  376. }
  377. else if (e.Result == ButtonResult.Cancel && e.Parameters != null)
  378. {
  379. colors.Clear();
  380. authors.Clear();
  381. annotArgsTypes.Clear();
  382. AnnotationListItems.Clear();
  383. AnnotationListItems.AddRange(CurrentAnnotationArgs);
  384. RefreshAnnotationListItems(button);
  385. }
  386. });
  387. }
  388. }
  389. /// <summary>
  390. /// 刷新列表数据
  391. /// </summary>
  392. /// <param name="button"></param>
  393. private async void RefreshAnnotationListItems(System.Windows.Controls.Button button)
  394. {
  395. switch (AnnotationSortOrder)
  396. {
  397. case AnnotationSortOrder.TimeAscending:
  398. TimeAscendingEvent();
  399. break;
  400. case AnnotationSortOrder.TimeDescending:
  401. TimeDescendingEvent();
  402. break;
  403. case AnnotationSortOrder.PageIndexAscending:
  404. PageSortEvent();
  405. break;
  406. default:
  407. break;
  408. }
  409. if (AnnotationListItems.Count > 0)
  410. {
  411. IsEmptyPanelVisibility = Visibility.Collapsed;
  412. await Task.Delay(2);
  413. //展开数据
  414. ExpandGroupHeader(AnnotationListItems, listBox);
  415. }
  416. else
  417. {
  418. if (button != null)
  419. {
  420. button.IsEnabled = true;
  421. }
  422. IsEmptyPanelVisibility = Visibility.Visible;
  423. //AnnotationListItems.AddRange(currentAnnotationArgs);
  424. //RefreshAnnotationListItems();
  425. }
  426. }
  427. /// <summary>
  428. /// 根据条件筛选列表数据
  429. /// </summary>
  430. /// <param name="annotArgsTypes"></param>
  431. /// <param name="colors"></param>
  432. /// <param name="authors"></param>
  433. /// <returns></returns>
  434. private ObservableCollection<AnnotationHandlerEventArgs> SelectAnnotationListItems(List<AnnotArgsType> annotArgsTypes, List<string> colors, List<string> authors)
  435. {
  436. ObservableCollection<AnnotationHandlerEventArgs> annotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
  437. #region 类型 颜色 作者
  438. if (annotArgsTypes.Count > 0 && colors.Count > 0 && authors.Count > 0)
  439. {
  440. foreach (var item in CurrentAnnotationArgs)
  441. {
  442. foreach (var type in annotArgsTypes)
  443. {
  444. foreach (var color in colors)
  445. {
  446. foreach (var author in authors)
  447. {
  448. if (item.EventType == type && item.Author == author)
  449. {
  450. SelectAnnotationColors(item, color, annotationArgs);
  451. }
  452. }
  453. }
  454. }
  455. }
  456. }
  457. #endregion 类型 颜色 作者
  458. #region 颜色 作者
  459. else if (colors.Count > 0 && authors.Count > 0)
  460. {
  461. foreach (var item in CurrentAnnotationArgs)
  462. {
  463. foreach (var color in colors)
  464. {
  465. foreach (var author in authors)
  466. {
  467. if (item.Author == author)
  468. {
  469. SelectAnnotationColors(item, color, annotationArgs);
  470. }
  471. }
  472. }
  473. }
  474. }
  475. #endregion 颜色 作者
  476. #region 类型 作者
  477. else if (annotArgsTypes.Count > 0 && authors.Count > 0)
  478. {
  479. foreach (var item in CurrentAnnotationArgs)
  480. {
  481. foreach (var type in annotArgsTypes)
  482. {
  483. foreach (var author in authors)
  484. {
  485. if (item.EventType == type && item.Author == author)
  486. {
  487. annotationArgs.Add(item);
  488. }
  489. }
  490. }
  491. }
  492. }
  493. #endregion 类型 作者
  494. #region 类型 颜色
  495. else if (annotArgsTypes.Count > 0 && colors.Count > 0)
  496. {
  497. foreach (var item in CurrentAnnotationArgs)
  498. {
  499. foreach (var type in annotArgsTypes)
  500. {
  501. foreach (var color in colors)
  502. {
  503. if (item.EventType == type)
  504. {
  505. SelectAnnotationColors(item, color, annotationArgs);
  506. }
  507. }
  508. }
  509. }
  510. }
  511. #endregion 类型 颜色
  512. #region 类型
  513. else if (annotArgsTypes.Count > 0)
  514. {
  515. foreach (var item in CurrentAnnotationArgs)
  516. {
  517. foreach (var type in annotArgsTypes)
  518. {
  519. if (item.EventType == type)
  520. {
  521. annotationArgs.Add(item);
  522. }
  523. }
  524. }
  525. }
  526. #endregion 类型
  527. #region 颜色
  528. else if (colors.Count > 0)
  529. {
  530. foreach (var item in CurrentAnnotationArgs)
  531. {
  532. foreach (var color in colors)
  533. {
  534. SelectAnnotationColors(item, color, annotationArgs);
  535. }
  536. }
  537. }
  538. #endregion 颜色
  539. #region 作者
  540. else if (authors.Count > 0)
  541. {
  542. foreach (var item in CurrentAnnotationArgs)
  543. {
  544. foreach (var author in authors)
  545. {
  546. if (item.Author == author)
  547. {
  548. annotationArgs.Add(item);
  549. }
  550. }
  551. }
  552. }
  553. #endregion 作者
  554. return annotationArgs;
  555. }
  556. /// <summary>
  557. /// 根据颜色筛选注释
  558. /// </summary>
  559. /// <param name="item"></param>
  560. /// <param name="color"></param>
  561. /// <param name="annotationArgs"></param>
  562. private void SelectAnnotationColors(AnnotationHandlerEventArgs item, string color, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  563. {
  564. AnnotHandlerEventArgs data = item.AnnotHandlerEventArgs;
  565. switch (item.EventType)
  566. {
  567. case AnnotArgsType.AnnotFreeText://文本
  568. if (data is FreeTextAnnotArgs textAnnotArgs)
  569. {
  570. AddScreenAnnotationArgs(textAnnotArgs.FontColor, color, item, annotationArgs);
  571. }
  572. break;
  573. case AnnotArgsType.AnnotHighlight://高亮
  574. if (data is TextHighlightAnnotArgs highlightAnnotArgs)
  575. {
  576. AddScreenAnnotationArgs(highlightAnnotArgs.Color, color, item, annotationArgs);
  577. }
  578. break;
  579. case AnnotArgsType.AnnotFreehand://手绘
  580. if (data is FreehandAnnotArgs freehandAnnotArgs)
  581. {
  582. AddScreenAnnotationArgs(freehandAnnotArgs.InkColor, color, item, annotationArgs);
  583. }
  584. break;
  585. case AnnotArgsType.AnnotSquiggly://波浪线
  586. break;
  587. case AnnotArgsType.AnnotStamp://图章
  588. break;
  589. case AnnotArgsType.AnnotStrikeout://删除线
  590. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  591. {
  592. AddScreenAnnotationArgs(textStrikeoutAnnotArgs.Color, color, item, annotationArgs);
  593. }
  594. break;
  595. case AnnotArgsType.AnnotSticky://便签
  596. if (data is StickyAnnotArgs stickyAnnotArgs)
  597. {
  598. AddScreenAnnotationArgs(stickyAnnotArgs.Color, color, item, annotationArgs);
  599. }
  600. break;
  601. case AnnotArgsType.AnnotUnderline://下划线
  602. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  603. {
  604. AddScreenAnnotationArgs(textUnderlineAnnotArgs.Color, color, item, annotationArgs);
  605. }
  606. break;
  607. case AnnotArgsType.AnnotLine:
  608. //if ((item.AnnotHandlerEventArgs as LineAnnotArgs).HeadLineType >= (C_LINE_TYPE)1 || (item.AnnotHandlerEventArgs as LineAnnotArgs).TailLineType >= (C_LINE_TYPE)1)
  609. //{
  610. // //箭头
  611. //}
  612. //else
  613. //{
  614. // //线
  615. //}
  616. if (data is LineAnnotArgs lineAnnotArgs)
  617. {
  618. AddScreenAnnotationArgs(lineAnnotArgs.LineColor, color, item, annotationArgs);
  619. }
  620. break;
  621. case AnnotArgsType.AnnotSquare://矩形
  622. if (data is SquareAnnotArgs squareAnnotArgs)
  623. {
  624. AddScreenAnnotationArgs(squareAnnotArgs.LineColor, color, item, annotationArgs);
  625. AddScreenAnnotationArgs(squareAnnotArgs.BgColor, color, item, annotationArgs);
  626. }
  627. break;
  628. case AnnotArgsType.AnnotCircle://圆
  629. if (data is CircleAnnotArgs circleAnnotArgs)
  630. {
  631. AddScreenAnnotationArgs(circleAnnotArgs.LineColor, color, item, annotationArgs);
  632. AddScreenAnnotationArgs(circleAnnotArgs.BgColor, color, item, annotationArgs);
  633. }
  634. break;
  635. }
  636. }
  637. /// <summary>
  638. /// 对比颜色
  639. /// </summary>
  640. /// <param name="color1"></param>
  641. /// <param name="color"></param>
  642. /// <param name="item"></param>
  643. /// <param name="annotationArgs"></param>
  644. private void AddScreenAnnotationArgs(System.Windows.Media.Color color1, string color, AnnotationHandlerEventArgs item, ObservableCollection<AnnotationHandlerEventArgs> annotationArgs)
  645. {
  646. if (color1.ToString() == color)
  647. {
  648. annotationArgs.Add(item);
  649. }
  650. }
  651. /// <summary>
  652. /// 添加附注的注释
  653. /// </summary>
  654. /// <param name="obj"></param>
  655. private void AddNotesEvent(object obj)
  656. {
  657. if (obj is ListBoxItem listBoxItem)
  658. {
  659. if (listBoxItem.DataContext is AnnotationHandlerEventArgs args)
  660. {
  661. if (args.EventType != AnnotArgsType.AnnotSticky && args.EventType != AnnotArgsType.AnnotFreeText && args.EventType != AnnotArgsType.AnnotLink)
  662. {
  663. DialogParameters value = new DialogParameters();
  664. value.Add(ParameterNames.Annotation, args);
  665. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, async e =>
  666. {
  667. if (e.Result == ButtonResult.OK && e.Parameters != null)
  668. {
  669. PdfViewer.UndoManager.CanSave = true;
  670. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  671. {
  672. AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
  673. RefreshOneListItem(annotation.AnnotHandlerEventArgs);
  674. }
  675. }
  676. });
  677. }
  678. }
  679. }
  680. }
  681. private async void RefreshOneListItem(AnnotHandlerEventArgs annotation)
  682. {
  683. for (int i = 0; i < AnnotationListItems.Count; i++)
  684. {
  685. if (AnnotationListItems[i].PageIndex == annotation.PageIndex && AnnotationListItems[i].AnnotIndex == annotation.AnnotIndex)
  686. {
  687. AnnotationListItems[i] = GetAddAnnotEventArgs(annotation);
  688. for (int j = 0; j < CurrentAnnotationArgs.Count; j++)
  689. {
  690. if (CurrentAnnotationArgs[j].PageIndex == annotation.PageIndex && CurrentAnnotationArgs[j].AnnotIndex == annotation.AnnotIndex)
  691. {
  692. CurrentAnnotationArgs[j] = GetAddAnnotEventArgs(annotation);
  693. break;
  694. }
  695. }
  696. if (!listBox.SelectedItems.Contains(AnnotationListItems[i]))
  697. {
  698. listBox.SelectedItem = AnnotationListItems[i];
  699. }
  700. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  701. ExpandGroupHeader(AnnotationListItems[i], listBox);
  702. await Task.Delay(1);//不加延时 会有不滚动的现象
  703. listBox.ScrollIntoView(AnnotationListItems[i]);
  704. break;
  705. }
  706. }
  707. }
  708. public async void ScrollToAnnot(int pageindex, int annotindex, ListBox AnnotationList)
  709. {
  710. //var list = PdfViewer.GetAnnotCommentList(pageindex, PdfViewer.Document);
  711. for (int i = 0; i < AnnotationList.Items.Count; i++)
  712. {
  713. if ((AnnotationList.Items[i] as AnnotationHandlerEventArgs).AnnotIndex == annotindex && (AnnotationList.Items[i] as AnnotationHandlerEventArgs).PageIndex == pageindex)
  714. {
  715. var item = AnnotationList.Items[i] as AnnotationHandlerEventArgs;
  716. //需要手动搜寻在哪一个分组 展开分组头
  717. ExpandGroupHeader(item, AnnotationList);
  718. AnnotationList.SelectedItem = item;
  719. await Task.Delay(1);
  720. AnnotationList.ScrollIntoView(item);
  721. }
  722. }
  723. }
  724. /// <summary>
  725. /// listboxitem鼠标左键点击,显示分组的数据
  726. /// </summary>
  727. /// <param name="obj"></param>
  728. private void ListBoxItem_PreviewMouseLeftButtonDown(object obj)
  729. {
  730. if (obj is ListBoxItem item)
  731. {
  732. var data = item.DataContext as AnnotationHandlerEventArgs;
  733. if (data != null)
  734. {
  735. PdfViewer.SelectAnnotation(data.PageIndex, data.AnnotIndex);
  736. }
  737. }
  738. }
  739. public async void UpdateAddedAnnot(int pageIndex, int annotIndex)
  740. {
  741. var annots = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  742. for (int i = 0; i < annots.Count; i++)
  743. {
  744. AnnotHandlerEventArgs item = annots[i];
  745. if (item.AnnotIndex == annotIndex && item.EventType != AnnotArgsType.AnnotRedaction)
  746. {
  747. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  748. if (args.AnnotHandlerEventArgs != null)
  749. {
  750. AnnotationListItems.Add(args);
  751. CurrentAnnotationArgs.Add(args);
  752. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  753. ExpandGroupHeader(args, listBox);
  754. listBox.SelectedItem = item;
  755. await Task.Delay(1);//不加延时 会有不滚动的现象
  756. listBox.ScrollIntoView(item);
  757. if (!listBox.SelectedItems.Contains(args))
  758. {
  759. listBox.SelectedItem = args;
  760. //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  761. }
  762. }
  763. }
  764. }
  765. if (IsEmptyPanelVisibility == Visibility.Visible && AnnotationListItems.Count > 0)
  766. {
  767. IsEmptyPanelVisibility = Visibility.Collapsed;
  768. }
  769. }
  770. public async void UpdateModifiedAnnot(int pageIndex, int annotIndex, bool isDelete)
  771. {
  772. try
  773. {
  774. var items = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
  775. if (isDelete && items.Count == 0)//当前页的最后一次删除
  776. {
  777. for (int k = 0; k < AnnotationListItems.Count; k++)
  778. {
  779. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  780. {
  781. AnnotationListItems.RemoveAt(k);
  782. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  783. CurrentAnnotationArgs.Remove(annotation1);
  784. UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  785. return;
  786. }
  787. }
  788. }
  789. if (isDelete)//删除
  790. {
  791. for (int k = 0; k < AnnotationListItems.Count; k++)
  792. {
  793. //不能加item[j].annoteIndex = annotIndex 删除后必匹配不上
  794. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
  795. {
  796. AnnotationListItems.RemoveAt(k);
  797. AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
  798. CurrentAnnotationArgs.Remove(annotation1);
  799. UpdateAnnotListAfterDelete(pageIndex, annotIndex);
  800. return;
  801. }
  802. }
  803. }
  804. for (int j = 0; j < items.Count; j++)
  805. {
  806. for (int k = 0; k < AnnotationListItems.Count; k++)
  807. {
  808. if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex && items[j].AnnotIndex == annotIndex)
  809. {
  810. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
  811. AnnotationListItems[k] = GetAddAnnotEventArgs(items[j]);
  812. for (int i = 0; i < CurrentAnnotationArgs.Count; i++)
  813. {
  814. if (CurrentAnnotationArgs[i].PageIndex == pageIndex && CurrentAnnotationArgs[i].AnnotIndex == annotIndex)
  815. {
  816. CurrentAnnotationArgs[i] = GetAddAnnotEventArgs(items[j]);
  817. break;
  818. }
  819. }
  820. if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
  821. {
  822. listBox.SelectedItem = AnnotationListItems[k];
  823. //PdfViewer.SelectAnnotation(args.PageIndex, args.AnnotIndex);
  824. }
  825. await Task.Delay(1);//不加延时 每页的第一个注释不会展开
  826. ExpandGroupHeader(AnnotationListItems[k], listBox);
  827. await Task.Delay(1);//不加延时 会有不滚动的现象
  828. listBox.ScrollIntoView(AnnotationListItems[k]);
  829. }
  830. }
  831. }
  832. }
  833. catch { }
  834. }
  835. /// <summary>
  836. /// 展开item所在分组
  837. /// </summary>
  838. private void ExpandGroupHeader(AnnotationHandlerEventArgs item, ListBox listBox)
  839. {
  840. try
  841. {
  842. var groups = listBox.Items.Groups;
  843. for (int i = 0; i < groups.Count; i++)
  844. {
  845. var l = groups[i] as CollectionViewGroup;
  846. if (l.Items.Contains(item))
  847. {
  848. var scroller = GetScrollHost(listBox);
  849. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  850. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  851. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  852. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  853. if (g != null)
  854. g.IsExpanded = true;
  855. }
  856. }
  857. }
  858. catch { }
  859. }
  860. /// <summary>
  861. /// 页面加载时
  862. /// </summary>
  863. /// <param name="obj"></param>
  864. private void Loaded(object obj)
  865. {
  866. if (obj is CompositeCommandParameter composite)
  867. {
  868. if (composite.Parameter is ListBox listBox)
  869. {
  870. this.listBox = listBox;
  871. SetGroupHeader(listBox);
  872. }
  873. }
  874. }
  875. public bool IsNavigationTarget(NavigationContext navigationContext)
  876. {
  877. return true;
  878. }
  879. public void OnNavigatedFrom(NavigationContext navigationContext)
  880. {
  881. }
  882. public void OnNavigatedTo(NavigationContext navigationContext)
  883. {
  884. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  885. var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  886. if (pdfview != null && viewContentViewModel != null)
  887. {
  888. ViewContentViewModel = viewContentViewModel;
  889. PdfViewer = pdfview;
  890. AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>();
  891. AnnotationListItems = GetDocumentAnnotionList();
  892. CurrentAnnotationArgs.AddRange(AnnotationListItems);
  893. AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
  894. }
  895. }
  896. /// <summary>
  897. /// 默认按照PageIndex,分组 排序
  898. /// </summary>
  899. /// <param name="listBox"></param>
  900. private async void SetGroupHeader(ListBox listBox)
  901. {
  902. //按照PageIndex,分组 排序
  903. ICollectionView iCollectionView = CollectionViewSource.GetDefaultView(AnnotationListItems);
  904. iCollectionView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(AnnotationHandlerEventArgs.PageIndex)));
  905. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
  906. iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
  907. if (AnnotationListItems.Count > 0)
  908. {
  909. IsEmptyPanelVisibility = Visibility.Collapsed;
  910. await Task.Delay(5);
  911. //展开数据
  912. ExpandGroupHeader(AnnotationListItems, listBox);
  913. }
  914. else
  915. {
  916. IsEmptyPanelVisibility = Visibility.Visible;
  917. }
  918. }
  919. /// <summary>
  920. /// 展开列表项
  921. /// </summary>
  922. /// <param name="annotationListItems"></param>
  923. /// <param name="listBox"></param>
  924. private void ExpandGroupHeader(ObservableCollection<AnnotationHandlerEventArgs> annotationListItems, ListBox listBox)
  925. {
  926. try
  927. {
  928. foreach (var item in annotationListItems)
  929. {
  930. var groups = listBox.Items.Groups;
  931. for (int i = 0; i < groups.Count; i++)
  932. {
  933. var group = groups[i] as CollectionViewGroup;
  934. if (group.Items.Contains(item))
  935. {
  936. var scroller = GetScrollHost(listBox);
  937. var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
  938. int count = VisualTreeHelper.GetChildrenCount(stackpanel);
  939. var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
  940. var g = CommonHelper.FindVisualChild<Expander>(groupItem);
  941. if (g != null)
  942. {
  943. g.IsExpanded = true;
  944. }
  945. }
  946. }
  947. }
  948. }
  949. catch { }
  950. }
  951. private ScrollViewer GetScrollHost(ListBox listBox)
  952. {
  953. if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
  954. {
  955. int s = VisualTreeHelper.GetChildrenCount(listBox);
  956. Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
  957. if (border != null)
  958. {
  959. return VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
  960. }
  961. }
  962. return null;
  963. }
  964. /// <summary>
  965. /// 获取listbox绑定数据
  966. /// </summary>
  967. /// <returns></returns>
  968. private ObservableCollection<AnnotationHandlerEventArgs> GetDocumentAnnotionList()
  969. {
  970. ObservableCollection<AnnotationHandlerEventArgs> list = new ObservableCollection<AnnotationHandlerEventArgs>();
  971. for (int i = 0; i < PdfViewer.Document.PageCount; i++)
  972. {
  973. var items = PdfViewer.GetAnnotCommentList(i, PdfViewer.Document);
  974. foreach (var item in items)
  975. {
  976. //原型图上,目前对波浪线的类型,在注释列表不显示
  977. if (item.EventType != AnnotArgsType.AnnotRedaction && item.EventType != AnnotArgsType.AnnotSquiggly)
  978. {
  979. AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
  980. if (args.AnnotHandlerEventArgs != null)
  981. {
  982. list.Add(args);
  983. }
  984. }
  985. }
  986. }
  987. return list;
  988. }
  989. private AnnotationHandlerEventArgs GetAddAnnotEventArgs(AnnotHandlerEventArgs item)
  990. {
  991. AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
  992. if (item.EventType == AnnotArgsType.AnnotFreehand)
  993. {
  994. WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
  995. args.WriteableBitmap = bitmap;
  996. }
  997. args.AnnotHandlerEventArgs = item;
  998. args.PageIndex = item.PageIndex;
  999. args.AnnotIndex = item.AnnotIndex;
  1000. args.EventType = item.EventType;
  1001. args.CreateTime = item.CreateTime;
  1002. args.UpdateTime = item.UpdateTime;
  1003. args.Content = item.Content;
  1004. args.MarkupContent = item.MarkupContent;
  1005. args.Author = item.Author;
  1006. args.Locked = item.Locked;
  1007. args.ReadOnly = item.ReadOnly;
  1008. args.FormField = item.FormField;
  1009. args.Document = PdfViewer.Document;
  1010. return args;
  1011. }
  1012. /// <summary>
  1013. /// 获取手绘图案
  1014. /// </summary>
  1015. /// <param name="doc"></param>
  1016. /// <param name="pageIndex"></param>
  1017. /// <param name="annotIndex"></param>
  1018. /// <returns></returns>
  1019. public WriteableBitmap GetAnnotImage(CPDFDocument doc, int pageIndex, int annotIndex)
  1020. {
  1021. if (doc == null)
  1022. {
  1023. return null;
  1024. }
  1025. CPDFPage docPage = doc.PageAtIndex(pageIndex, false);
  1026. if (docPage == null)
  1027. {
  1028. return null;
  1029. }
  1030. List<CPDFAnnotation> docAnnots = docPage.GetAnnotations();
  1031. foreach (CPDFAnnotation annot in docAnnots)
  1032. {
  1033. if (docAnnots.IndexOf(annot) == annotIndex)
  1034. {
  1035. CPDFInkAnnotation cPDFInk = (CPDFInkAnnotation)docAnnots[annotIndex];
  1036. CRect rawRect = annot.GetRect();
  1037. rawRect = cPDFInk.Rect;
  1038. double scaleDpi = 96.0 / 72.0;
  1039. Rect paintRect = new Rect(rawRect.left * scaleDpi, rawRect.top * scaleDpi, rawRect.width() * scaleDpi, rawRect.height() * scaleDpi);
  1040. int drawWidth = (int)paintRect.Width;
  1041. int drawHeight = (int)paintRect.Height;
  1042. byte[] bitmapArray = new byte[drawWidth * drawHeight * 4];
  1043. annot.UpdateAp();
  1044. annot.RenderAnnot(drawWidth, drawHeight, bitmapArray);
  1045. WriteableBitmap wirteBitmap = new WriteableBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Bgra32, null);
  1046. wirteBitmap.WritePixels(new Int32Rect(0, 0, drawWidth, drawHeight), bitmapArray, wirteBitmap.BackBufferStride, 0);
  1047. cPDFInk.SetRect(rawRect);
  1048. return wirteBitmap;
  1049. }
  1050. }
  1051. return null;
  1052. }
  1053. /// <summary>
  1054. /// listbox的itemsource发生变化时
  1055. /// </summary>
  1056. /// <param name="sender"></param>
  1057. /// <param name="e"></param>
  1058. private void AnnotationListItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  1059. {
  1060. if (sender is ObservableCollection<AnnotationHandlerEventArgs> obsSender)
  1061. {
  1062. //currentAnnotationArgs.Clear();
  1063. //currentAnnotationArgs.AddRange(obsSender);
  1064. if (obsSender.Count < 1)
  1065. {
  1066. IsEmptyPanelVisibility = Visibility.Visible;
  1067. //currentAnnotationArgs.Clear();
  1068. }
  1069. else
  1070. {
  1071. IsEmptyPanelVisibility = Visibility.Collapsed;
  1072. }
  1073. }
  1074. else
  1075. {
  1076. IsEmptyPanelVisibility = Visibility.Visible;
  1077. }
  1078. }
  1079. }
  1080. }