KMDocumentModel.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // KMDocumentModel.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/7.
  6. //
  7. import Cocoa
  8. class KMDocumentModel: NSObject {
  9. private var _documentURL: URL!
  10. var documentURL: URL {
  11. get {
  12. return _documentURL
  13. }
  14. }
  15. private var _document: CPDFDocument?
  16. var document: CPDFDocument? {
  17. get {
  18. return _document
  19. }
  20. }
  21. var isLocked: Bool {
  22. get {
  23. if (self.document == nil) {
  24. return false
  25. }
  26. return self.document!.isLocked
  27. }
  28. }
  29. var isEncrypt: Bool {
  30. get {
  31. if (self.document == nil) {
  32. return false
  33. }
  34. return self.document!.isEncrypted
  35. }
  36. }
  37. var pageCount: Int {
  38. get {
  39. if (self.document == nil) {
  40. return 0
  41. }
  42. return Int(self.document!.pageCount)
  43. }
  44. }
  45. var password: String {
  46. get {
  47. if (self.document == nil) {
  48. return ""
  49. }
  50. if (self.document?.password == nil) {
  51. return ""
  52. }
  53. return (self.document?.password)!
  54. }
  55. }
  56. convenience init(url: URL) {
  57. self.init()
  58. _documentURL = url
  59. _document = CPDFDocument(url: url)
  60. }
  61. override init() {}
  62. public func unlock(_ password: String) -> Bool {
  63. if (self.document == nil) {
  64. return false
  65. }
  66. return self.document!.unlock(withPassword: password)
  67. }
  68. }