KMDocumentModel.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. var currentIndex: Int = 0
  57. convenience init(url: URL) {
  58. self.init()
  59. _documentURL = url
  60. _document = CPDFDocument(url: url)
  61. }
  62. override init() {}
  63. public func unlock(_ password: String) -> Bool {
  64. if (self.document == nil) {
  65. return false
  66. }
  67. return self.document!.unlock(withPassword: password)
  68. }
  69. }