KMEditDocumentController.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // KMEditDocumentController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/1.
  6. //
  7. import Cocoa
  8. class KMEditDocumentController: NSViewController {
  9. var pdfDocument: CPDFDocument?
  10. var pdfView: CPDFListView = CPDFListView.init()
  11. let coverView = NSView(frame: CGRectMake(0, 0, 300, 300))
  12. override func viewDidLoad() {
  13. super.viewDidLoad()
  14. // Do view setup here.
  15. pdfView.frame = view.bounds
  16. pdfView.autoresizingMask = [.width, .height]
  17. pdfView.setDisplay(.singlePage)
  18. pdfView.toolMode = .CMoveToolMode
  19. pdfView.autoScales = true
  20. view.addSubview(pdfView)
  21. }
  22. func reloadData() {
  23. guard let pdfDocument = self.pdfDocument else { return }
  24. DispatchQueue.main.async {
  25. self.pdfView.document = pdfDocument
  26. self.pdfView.layoutDocumentView()
  27. }
  28. }
  29. func refreshUI() {
  30. pdfView.updateRender(true)
  31. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.15) {[weak self] in
  32. self?.pdfView.updateRender(true)
  33. }
  34. }
  35. func layoutDocumentView() {
  36. pdfView.document?.refreshPageData()
  37. pdfView.layoutDocumentView()
  38. }
  39. }