KMDocumentModel.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KMDocumentModel.swift
  3. // PDF Reader Pro
  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. set {
  56. document?.unlock(withPassword: newValue)
  57. }
  58. }
  59. var currentIndex: Int = 0
  60. convenience init(url: URL) {
  61. self.init()
  62. _documentURL = url
  63. _document = CPDFDocument(url: url)
  64. }
  65. override init() {}
  66. public func unlock(_ password: String) -> Bool {
  67. if (self.document == nil) {
  68. return false
  69. }
  70. return self.document!.unlock(withPassword: password)
  71. }
  72. }