KMPageEditSettingBaseModel.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // KMPageEditSettingBaseModel.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/1/12.
  6. //
  7. import Cocoa
  8. class KMPageEditSettingBaseModel: NSObject {
  9. var documentURL: URL!
  10. var password: String = ""
  11. var fileName: String!
  12. var pathExtension: String!
  13. var outputFileNameDeletePathExtension: String!
  14. var outputFileName: String {
  15. get {
  16. if (fileName == nil || fileName.isEmpty) {
  17. return ""
  18. }
  19. var result: String = ""
  20. let pathExtension = fileName.components(separatedBy: ".").last
  21. let files = fileName.split(separator: ".")
  22. for i in 0 ..< files.count-1 {
  23. let file: String = String(files[i])
  24. result.append(file)
  25. if (i == files.count-2) {
  26. result.append(".")
  27. }
  28. }
  29. return fileName
  30. }
  31. }
  32. var pageCount: Int {
  33. get {
  34. if (documentURL == nil) {
  35. return NSNotFound
  36. }
  37. documentURL.pathExtension
  38. let document = CPDFDocument(url: documentURL)
  39. if (document!.isLocked) {
  40. if ((document?.unlock(withPassword: password))!) { /// 解锁成功
  41. return Int(document!.pageCount)
  42. }
  43. return NSNotFound
  44. }
  45. return Int(document!.pageCount)
  46. }
  47. }
  48. }