CPDFSecurityInfoControl.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKitViewer;
  3. using System.Windows.Controls;
  4. namespace Compdfkit_Tools.PDFControl
  5. {
  6. public partial class CPDFSecurityInfoControl : UserControl
  7. {
  8. private string T_Allowed = "Allowed";
  9. private string T_NotAllowed = "Not Allowed";
  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. InitializeSecurityInfo(pdfDoc);
  21. }
  22. }
  23. }
  24. public CPDFSecurityInfoControl()
  25. {
  26. InitializeComponent();
  27. }
  28. /// <summary>
  29. /// Pass in a boolean value and return the corresponding text.
  30. /// </summary>
  31. /// <param name="isTrue"></param>
  32. /// <returns></returns>
  33. private string GetStringFromBool(bool isTrue)
  34. {
  35. if (isTrue)
  36. {
  37. return T_Allowed;
  38. }
  39. else
  40. {
  41. return T_NotAllowed;
  42. }
  43. }
  44. private void InitializeSecurityInfo(CPDFDocument pdfDocument)
  45. {
  46. CPDFPermissionsInfo Permissions = pdfDocument.GetPermissionsInfo();
  47. AllowsPrintingTextBlock.Text = GetStringFromBool(Permissions.AllowsPrinting);
  48. AllowsCopyingTextBlock.Text = GetStringFromBool(Permissions.AllowsCopying);
  49. AllowsDocumentChangesTextBlock.Text = GetStringFromBool(Permissions.AllowsDocumentChanges);
  50. AllowsDocumentAssemblyTextBlock.Text = GetStringFromBool(Permissions.AllowsDocumentAssembly);
  51. AllowsCommentingTextBlock.Text = GetStringFromBool(Permissions.AllowsCommenting);
  52. AllowsFormFieldEntryTextBlock.Text = GetStringFromBool(Permissions.AllowsFormFieldEntry);
  53. }
  54. }
  55. }