CPDFCreateInfoControl.xaml.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using ComPDFKit.PDFDocument;
  2. using compdfkit_tools.Helper;
  3. using ComPDFKitViewer.PdfViewer;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Markup;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace compdfkit_tools.PDFControl
  21. {
  22. /// <summary>
  23. /// PDFCreateInfoControl.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class CPDFCreateInfoControl : UserControl
  26. {
  27. public CPDFViewer pdfViewer;
  28. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  29. {
  30. this.pdfViewer = pdfViewer;
  31. InitializeCreateInfo(pdfViewer.Document);
  32. }
  33. public CPDFCreateInfoControl()
  34. {
  35. InitializeComponent();
  36. }
  37. private void InitializeCreateInfo(CPDFDocument cpdfDocument)
  38. {
  39. VersionTextBlock.Text = cpdfDocument.GetInfo().Version;
  40. PageCountTextBlock.Text = cpdfDocument.PageCount.ToString();
  41. CreatorTextBlock.Text = cpdfDocument.GetInfo().Creator;
  42. CreationDateTextBlock.Text = ConverPDFTime(cpdfDocument.GetInfo().CreationDate);
  43. ModificationDateTextBlock.Text = ConverPDFTime(cpdfDocument.GetInfo().ModificationDate);
  44. }
  45. private string ConverPDFTime(string timeText)
  46. {
  47. try
  48. {
  49. if (Regex.IsMatch(timeText, "(?<=D\\:)[0-9]+(?=[\\+\\-])"))
  50. {
  51. string dateStr = Regex.Match(timeText, "(?<=D\\:)[0-9]+(?=[\\+\\-])").Value;
  52. timeText = dateStr.Substring(0, 4) + "-" + dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
  53. dateStr.Substring(10, 2) + ":" + dateStr.Substring(12, 2);
  54. }
  55. else if (Regex.IsMatch(timeText, "(?<=D\\:)[0-9]+"))
  56. {
  57. string dateStr = Regex.Match(timeText, "(?<=D\\:)[0-9]+").Value;
  58. if (dateStr.Length > 0)
  59. {
  60. timeText = dateStr.Substring(0, 4) + "-" + dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
  61. dateStr.Substring(10, 2) + ":" + dateStr.Substring(12, 2);
  62. }
  63. }
  64. }
  65. catch(Exception ex)
  66. {
  67. }
  68. return timeText;
  69. }
  70. }
  71. }