CPDFCreateInfoControl.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using ComPDFKit.PDFDocument;
  2. using Compdfkit_Tools.Helper;
  3. using ComPDFKitViewer.PdfViewer;
  4. using System;
  5. using System.Text.RegularExpressions;
  6. using System.Windows.Controls;
  7. namespace Compdfkit_Tools.PDFControl
  8. {
  9. public partial class CPDFCreateInfoControl : UserControl
  10. {
  11. public CPDFViewer pdfViewer;
  12. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  13. {
  14. this.pdfViewer = pdfViewer;
  15. InitializeCreateInfo(pdfViewer.Document);
  16. }
  17. public CPDFCreateInfoControl()
  18. {
  19. InitializeComponent();
  20. }
  21. private void InitializeCreateInfo(CPDFDocument cpdfDocument)
  22. {
  23. VersionTextBlock.Text = cpdfDocument.GetInfo().Version;
  24. PageCountTextBlock.Text = cpdfDocument.PageCount.ToString();
  25. CreatorTextBlock.Text = cpdfDocument.GetInfo().Creator;
  26. CreationDateTextBlock.Text = ConverPDFTime(cpdfDocument.GetInfo().CreationDate);
  27. ModificationDateTextBlock.Text = ConverPDFTime(cpdfDocument.GetInfo().ModificationDate);
  28. }
  29. private string ConverPDFTime(string timeText)
  30. {
  31. try
  32. {
  33. if (Regex.IsMatch(timeText, "(?<=D\\:)[0-9]+(?=[\\+\\-])"))
  34. {
  35. string dateStr = Regex.Match(timeText, "(?<=D\\:)[0-9]+(?=[\\+\\-])").Value;
  36. timeText = dateStr.Substring(0, 4) + "-" + dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
  37. dateStr.Substring(10, 2) + ":" + dateStr.Substring(12, 2);
  38. }
  39. else if (Regex.IsMatch(timeText, "(?<=D\\:)[0-9]+"))
  40. {
  41. string dateStr = Regex.Match(timeText, "(?<=D\\:)[0-9]+").Value;
  42. if (dateStr.Length > 0)
  43. {
  44. timeText = dateStr.Substring(0, 4) + "-" + dateStr.Substring(4, 2) + "-" + dateStr.Substring(6, 2) + " " + dateStr.Substring(8, 2) + ":" +
  45. dateStr.Substring(10, 2) + ":" + dateStr.Substring(12, 2);
  46. }
  47. }
  48. }
  49. catch(Exception ex)
  50. {
  51. }
  52. return timeText;
  53. }
  54. }
  55. }