CPDFCreateInfoControl.xaml.cs 2.5 KB

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