|
@@ -116,6 +116,7 @@ class KMAITranslationVC: NSViewController {
|
|
|
openPanel.beginSheetModal(for: self.view.window!) { result in
|
|
|
if result == .OK {
|
|
|
for url in openPanel.urls {
|
|
|
+ let isExceedsLimit = self.isPDFPageCountExceedsLimit(filePath: url.path)
|
|
|
if (url.pathExtension == "pdf") || url.pathExtension == "PDF" {
|
|
|
if !url.path.isPDFValid() {
|
|
|
let alert = NSAlert()
|
|
@@ -128,6 +129,9 @@ class KMAITranslationVC: NSViewController {
|
|
|
if self.isFileGreaterThan10MB(atPath: url.path) {
|
|
|
self.errorView.isHidden = false
|
|
|
self.errorLabel.stringValue = NSLocalizedString("The uploaded file size cannot exceed 10MB", comment: "")
|
|
|
+ } else if isExceedsLimit {
|
|
|
+ self.errorView.isHidden = false
|
|
|
+ self.errorLabel.stringValue = NSLocalizedString("Documents cannot exceed 30 pages", comment: "")
|
|
|
} else {
|
|
|
DispatchQueue.main.async {
|
|
|
self.showProgressWindow()
|
|
@@ -378,6 +382,16 @@ class KMAITranslationVC: NSViewController {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
|
|
|
+ let url = URL(fileURLWithPath: filePath)
|
|
|
+ guard let document = PDFDocument(url: url) else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ let pageCount = document.pageCount
|
|
|
+ return pageCount > 30
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: Action Methods
|
|
|
|
|
|
func languageAction(_ isFromLanguage: Bool) -> Void {
|