浏览代码

【UI替换】-主页 从网页新增PDF

lizhe 1 年之前
父节点
当前提交
4971e61144

+ 28 - 2
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -1359,6 +1359,9 @@
 		ADAFD9F72AE68A8500F084BC /* KMCreatPDFView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADAFD9F62AE68A8500F084BC /* KMCreatPDFView.xib */; };
 		ADAFD9F82AE68A8500F084BC /* KMCreatPDFView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADAFD9F62AE68A8500F084BC /* KMCreatPDFView.xib */; };
 		ADAFD9F92AE68A8500F084BC /* KMCreatPDFView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADAFD9F62AE68A8500F084BC /* KMCreatPDFView.xib */; };
+		ADAFDA032AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */ = {isa = PBXBuildFile; fileRef = ADAFDA022AE8BD5C00F084BC /* KMConvertURLToPDF.m */; };
+		ADAFDA042AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */ = {isa = PBXBuildFile; fileRef = ADAFDA022AE8BD5C00F084BC /* KMConvertURLToPDF.m */; };
+		ADAFDA052AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */ = {isa = PBXBuildFile; fileRef = ADAFDA022AE8BD5C00F084BC /* KMConvertURLToPDF.m */; };
 		ADB2D6E6294740F30029D2B3 /* KMPrintPaperSetWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB2D6E4294740F30029D2B3 /* KMPrintPaperSetWindowController.swift */; };
 		ADB2D6E7294740F30029D2B3 /* KMPrintPaperSetWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB2D6E4294740F30029D2B3 /* KMPrintPaperSetWindowController.swift */; };
 		ADB2D6E8294740F30029D2B3 /* KMPrintPaperSetWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB2D6E4294740F30029D2B3 /* KMPrintPaperSetWindowController.swift */; };
@@ -3723,6 +3726,8 @@
 		ADAFD9ED2AE616B100F084BC /* FocusAwareSecureTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FocusAwareSecureTextField.swift; sourceTree = "<group>"; };
 		ADAFD9F22AE68A7400F084BC /* KMCreatPDFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCreatPDFView.swift; sourceTree = "<group>"; };
 		ADAFD9F62AE68A8500F084BC /* KMCreatPDFView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCreatPDFView.xib; sourceTree = "<group>"; };
+		ADAFDA012AE8BD5B00F084BC /* KMConvertURLToPDF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMConvertURLToPDF.h; sourceTree = "<group>"; };
+		ADAFDA022AE8BD5C00F084BC /* KMConvertURLToPDF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMConvertURLToPDF.m; sourceTree = "<group>"; };
 		ADB2D6E4294740F30029D2B3 /* KMPrintPaperSetWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPrintPaperSetWindowController.swift; sourceTree = "<group>"; };
 		ADB2D6E5294740F30029D2B3 /* KMPrintPaperSetWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPrintPaperSetWindowController.xib; sourceTree = "<group>"; };
 		ADB2D6EC2947415E0029D2B3 /* KMPrintPaperSetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPrintPaperSetView.swift; sourceTree = "<group>"; };
@@ -5361,12 +5366,11 @@
 		9F78EFD428F81F1A001E66F4 /* WindowController */ = {
 			isa = PBXGroup;
 			children = (
+				ADAFD9FB2AE8AE9800F084BC /* KMURLToPDFWindowController */,
 				899700DD28F3A9F2009AF911 /* KMHomeWindowController.swift */,
 				899700DE28F3A9F2009AF911 /* KMHomeWindowController.xib */,
 				9F705F74291A3A84005199AD /* KMHistoryFileDeleteWindowController.swift */,
 				9F705F75291A3A84005199AD /* KMHistoryFileDeleteWindowController.xib */,
-				9F0CB5402986953A00007028 /* KMURLToPDFWindowController.swift */,
-				9F0CB5412986953A00007028 /* KMURLToPDFWindowController.xib */,
 				9FD0FA4929D43D6800F2AB0D /* KMDeviceBrowserWindowController.swift */,
 				9FD0FA4A29D43D6800F2AB0D /* KMDeviceBrowserWindowController.xib */,
 				9F02018C2A1DDAA500C9B673 /* KMAITranslationWindowController.swift */,
@@ -5890,6 +5894,25 @@
 			path = CreatPDFView;
 			sourceTree = "<group>";
 		};
+		ADAFD9FB2AE8AE9800F084BC /* KMURLToPDFWindowController */ = {
+			isa = PBXGroup;
+			children = (
+				9F0CB5402986953A00007028 /* KMURLToPDFWindowController.swift */,
+				9F0CB5412986953A00007028 /* KMURLToPDFWindowController.xib */,
+				ADAFD9FC2AE8AEA900F084BC /* Model */,
+			);
+			path = KMURLToPDFWindowController;
+			sourceTree = "<group>";
+		};
+		ADAFD9FC2AE8AEA900F084BC /* Model */ = {
+			isa = PBXGroup;
+			children = (
+				ADAFDA012AE8BD5B00F084BC /* KMConvertURLToPDF.h */,
+				ADAFDA022AE8BD5C00F084BC /* KMConvertURLToPDF.m */,
+			);
+			path = Model;
+			sourceTree = "<group>";
+		};
 		ADB2D6E229473FF00029D2B3 /* DealPaper */ = {
 			isa = PBXGroup;
 			children = (
@@ -9974,6 +9997,7 @@
 				896DD4552985FB3200ADE514 /* KMPageDisplayThemeCollectionViewItem.swift in Sources */,
 				ADA9102E2A272CEA003352F0 /* KMImageOptimization.swift in Sources */,
 				BBC348532958465C008D2CD1 /* KMBackgroundFilePropertyInfoController.swift in Sources */,
+				ADAFDA032AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */,
 				AD9527C2295294EF0039D2BC /* KMPrintPaperModel.swift in Sources */,
 				AD8810A929A8463600178CA1 /* KMAccountInfoWindowController.swift in Sources */,
 				9F0CB525298656BA00007028 /* KMDesignToken+BorderWidth.swift in Sources */,
@@ -10132,6 +10156,7 @@
 				BB3198172AC55E6D00107371 /* CPDFDocument+KMExtension.swift in Sources */,
 				BBEC00C8295C319400A26C98 /* KMBatesManager.swift in Sources */,
 				ADA9102B2A272CE2003352F0 /* KMEditPDFTextManager.swift in Sources */,
+				ADAFDA042AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */,
 				BB147021299DC0D100784A6A /* OIDServiceDiscovery.m in Sources */,
 				BB5DF1F22959C9F00025CDA1 /* KMHeaderFooterPropertyMainController.swift in Sources */,
 				BBC3482529559506008D2CD1 /* KMBackgroundManager.swift in Sources */,
@@ -11475,6 +11500,7 @@
 				8997011028F40842009AF911 /* KMOutlineViewController.swift in Sources */,
 				9F1F82BE292E01860092C4B4 /* KMCloudEmptyCollectionViewItem.swift in Sources */,
 				BB6DD8272934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */,
+				ADAFDA052AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */,
 				9FCFECAA2AD243C900EAD2CB /* KMBlankView.swift in Sources */,
 				9F0201902A1DDAA500C9B673 /* KMAITranslationWindowController.swift in Sources */,
 				ADDEEA802AD3FB1D00EF675D /* KMImageAccessoryController.swift in Sources */,

文件差异内容过多而无法显示
+ 830 - 1
PDF Office/PDF Master.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist


+ 2 - 2
PDF Office/PDF Master/Class/Document/KMDocumentController.swift

@@ -128,8 +128,8 @@ class KMDocumentController: NSDocumentController {
     @IBAction func importFromWebPage(_ sender: Any) {
         let windowController: KMURLToPDFWindowController = KMURLToPDFWindowController.init(windowNibName: NSNib.Name("KMURLToPDFWindowController"))
         
-        windowController.beginSheetModal(for: NSApp.mainWindow!) { filePath in
-            if filePath != nil && FileManager.default.fileExists(atPath: filePath) {
+        windowController.beginSheetModalForWindow(NSWindow.currentWindow()) { filePath in
+            if FileManager.default.fileExists(atPath: filePath) {
                 NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
                     if error != nil {
                         NSApp.presentError(error!)

+ 3 - 3
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -714,8 +714,8 @@ extension KMHomeViewController {
     func importFromWebPage() {
         self.urlToPDFWindowController = KMURLToPDFWindowController.init(windowNibName: NSNib.Name("KMURLToPDFWindowController"))
         
-        self.urlToPDFWindowController!.beginSheetModal(for: NSApp.mainWindow!) { filePath in
-            if filePath != nil && FileManager.default.fileExists(atPath: filePath) {
+        self.urlToPDFWindowController?.beginSheetModalForWindow(NSApp.mainWindow!, completionHandler: { filePath in
+            if FileManager.default.fileExists(atPath: filePath) {
                 NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
                     if error != nil {
                         NSApp.presentError(error!)
@@ -726,7 +726,7 @@ extension KMHomeViewController {
                     }
                 }
             }
-        }
+        })
     }
     
     func importFromScanner() {

+ 0 - 456
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController.swift

@@ -1,456 +0,0 @@
-//
-//  KMURLToPDFWindowController.swift
-//  PDF Master
-//
-//  Created by wanjun on 2023/1/29.
-//
-
-import Cocoa
-
-class KMURLToPDFWindowController: NSWindowController {
-    
-    @IBOutlet weak var title: NSTextField!
-    @IBOutlet weak var urlView: NSView!
-    @IBOutlet weak var urlTextFieldBox: NSBox!
-    @IBOutlet weak var fileView: NSView!
-    @IBOutlet weak var fileTextFieldBox: NSBox!
-    @IBOutlet weak var fileButtonBox: NSBox!
-    @IBOutlet weak var pageConfigurationView: NSView!
-    @IBOutlet weak var pageConfigurationLabel: NSTextField!
-    @IBOutlet weak var pageSizeLabel: NSTextField!
-    @IBOutlet weak var pageSizePopUpButton: KMPopUpButton!
-    @IBOutlet weak var spacingLanel: NSTextField!
-    @IBOutlet weak var stepperBox: NSBox!
-    @IBOutlet weak var mmLabel: NSTextField!
-    @IBOutlet weak var cancelView: NSView!
-    @IBOutlet weak var openView: NSView!
-    
-    var urlButtonVC: KMDesignButton!
-    var urlTextfieldVC: KMTextfieldVC!
-    var fileButtonVC: KMDesignButton!
-    var fileTextfieldVC: KMTextfieldVC!
-    var openFileVC: KMDesignButton!
-    var stepperVC: KMStepperView!
-    var cancelVC: KMDesignButton!
-    var openVC: KMDesignButton!
-    
-    var filePath: String = ""
-    var gap: Float = 0.0
-    var pageSize: CGSize = NSZeroSize
-
-    override func windowDidLoad() {
-        super.windowDidLoad()
-
-        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
-        urlButtonVC     = KMDesignButton.init(withType: .RadioButton)
-        urlTextfieldVC  = KMTextfieldVC.init(nibName: "KMTextfieldVC", bundle: nil)
-        fileButtonVC    = KMDesignButton.init(withType: .RadioButton)
-        fileTextfieldVC = KMTextfieldVC.init(nibName: "KMTextfieldVC", bundle: nil)
-        openFileVC      = KMDesignButton.init(withType: .Image)
-        stepperVC       = KMStepperView.init(nibName: "KMStepperView", bundle: nil)
-        cancelVC        = KMDesignButton.init(withType: .Text)
-        openVC          = KMDesignButton.init(withType: .Text)
-
-        pageSizePopUpButton.removeAllItems()
-        
-        self.initializeUI()
-        self.initLocalization()
-        
-        refreshUI()
-    }
-    
-    // MARK: Init
-
-    func initializeUI() {
-        self.window?.backgroundColor = .white
-
-        title.font = NSFont.boldSystemFont(ofSize: 16.0)
-        title.textColor = NSColor(red: 37/255.0, green: 41/255.0, blue: 41/255.0, alpha: 1.0)
-        urlView.addSubview(urlButtonVC.view)
-        urlButtonVC.image = NSImage(named: "KMRadioButtonUnSelect")!
-        urlButtonVC.target = self
-        urlButtonVC.action = #selector(buttonChangeType)
-        urlButtonVC.state = .Checked
-//        let itemSpacing = KMDesignToken.shared.itemSpacing(withToken: "checkbox-radio.bg.def")
-//        urlButtonVC.radio_label = itemSpacing.stringToCGFloat()
-//        let typography = KMDesignToken.shared.typography(withToken: "checkbox-radio.mac-text.def")
-//        let fill = KMDesignToken.shared.fill(withToken: "checkbox-radio.mac-text.def")
-        urlTextFieldBox.contentView = urlTextfieldVC.view
-        urlTextfieldVC.borderColor = .gray
-        urlTextfieldVC.borderWidth = 1.0
-        urlTextfieldVC.cornerRadius = 4.0
-        urlTextfieldVC.width = 400.0
-        urlTextfieldVC.height = 32.0
-        urlTextfieldVC.editable = true
-        urlTextfieldVC.becomeFirstResponder = true
-        urlTextfieldVC.delete = self
-        
-        fileView.addSubview(fileButtonVC.view)
-        fileButtonVC.image = NSImage(named: "KMRadioButtonUnSelect")!
-        fileButtonVC.target = self
-        fileButtonVC.action = #selector(buttonChangeType)
-
-        fileTextFieldBox.contentView = fileTextfieldVC.view
-        fileTextfieldVC.borderColor = .gray
-        fileTextfieldVC.borderWidth = 1.0
-        fileTextfieldVC.cornerRadius = 4.0
-        fileTextfieldVC.width = 360.0
-        fileTextfieldVC.height = 32.0
-        fileTextfieldVC.editable = false
-        fileTextfieldVC.delete = self
-
-        fileButtonBox.contentView = openFileVC.view
-        openFileVC.image = NSImage(named: "KMFileIcon")!
-        openFileVC.borderColor = .gray
-        openFileVC.borderWidth = 1.0
-        openFileVC.cornerRadius = 4.0
-        openFileVC.width = 32.0
-        openFileVC.height = 32.0
-        openFileVC.target = self
-        openFileVC.action = #selector(selectFileAction)
-        openFileVC.enabled = false
-
-        stepperBox.contentView = stepperVC.view
-        stepperVC.borderColor = .gray
-        stepperVC.borderWidth = 1.0
-        stepperVC.cornerRadius = 4.0
-        stepperVC.width = 72.0
-        stepperVC.height = 32.0
-        stepperVC.delete = self
-        stepperVC.enabled = false
-
-        cancelView.addSubview(cancelVC.view)
-        cancelVC.borderColor = .gray
-        cancelVC.borderWidth = 1.0
-        cancelVC.cornerRadius = 4.0
-        cancelVC.width = 80.0
-        cancelVC.height = 32.0
-        cancelVC.textColor = .black
-        cancelVC.target = self
-        cancelVC.action = #selector(cancelAction)
-
-        openView.addSubview(openVC.view)
-        openVC.borderColor = .gray
-        openVC.borderWidth = 1.0
-        openVC.cornerRadius = 4.0
-        openVC.width = 80.0
-        openVC.height = 32.0
-        openVC.background = NSColor(red: 23/255.0, green: 112/255.0, blue: 244/255.0, alpha: 1.0)
-        openVC.textColor = .white
-        openVC.target = self
-        openVC.action = #selector(startAction)
-    }
-    
-    func initLocalization() {
-        title.stringValue = NSLocalizedString("New From Web Page", comment: "")
-        urlButtonVC.stringValue = NSLocalizedString("URL", comment: "")
-        urlTextfieldVC.placeholderString = NSLocalizedString("https://pdfreaderpro.com", comment: "")
-        fileButtonVC.stringValue = NSLocalizedString("File", comment: "")
-        fileTextfieldVC.placeholderString = NSLocalizedString("Select Files(.html,.webarchive)", comment: "")
-        pageConfigurationLabel.stringValue = NSLocalizedString("Page Configuration", comment: "")
-        pageSizeLabel.stringValue = NSLocalizedString("Page Size:", comment: "")
-        spacingLanel.stringValue = NSLocalizedString("Spacing:", comment: "")
-        mmLabel.stringValue = NSLocalizedString("mm:", comment: "")
-        cancelVC.stringValue = NSLocalizedString("Cancel", comment: "")
-        openVC.stringValue = NSLocalizedString("Open", comment: "")
-
-        pageSizePopUpButton.addItems(withTitles: [NSLocalizedString("Automatic resizing", comment: ""),
-                                                  "4A0 1682 × 2378 mm",
-                                                  "2A0 1189 × 1682 mm",
-                                                  "A0 841 × 1189 mm",
-                                                  "A1 594 × 841 mm",
-                                                  "A2 420 × 594 mm",
-                                                  "A3 297 × 420 mm",
-                                                  "A4 210 × 297 mm",
-                                                  "A5 148 × 210 mm",
-                                                  "A6 105 × 148 mm",
-                                                  "A7 74 × 105 mm",
-                                                  "A8 52 × 74 mm",
-                                                  "A9 37 × 52 mm",
-                                                  "A10 26 × 37 mm"])
-    }
-    
-    func refreshUI() -> Void {
-        urlButtonVC.updateUI()
-        urlTextfieldVC.updateUI()
-        fileButtonVC.updateUI()
-        fileTextfieldVC.updateUI()
-        openFileVC.updateUI()
-        stepperVC.updateUI()
-        cancelVC.updateUI()
-        openVC.updateUI()
-    }
-    
-    // MARK: Private Methods
-
-    func kUrlToPDFFolderPath() -> String {
-//        let searchPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last
-//        let append2 = searchPath!.stringByAppendingPathComponent("WebPage")
-        let append1: NSString = "WebPage"
-        let append2 = append1.kUrlToPDFFolderPath()
-        return append2 as String
-    }
-    
-    @objc func beginSheetModal(for window: NSWindow, completionHandler handler: ((_ filePath: String) -> Void)?) {
-        window.beginSheet(self.window!) { [weak self] returnCode in
-            if self != nil {
-                handler!(self!.filePath)
-            }
-        }
-    }
-
-    func formatFloat(_ f: Float) -> String {
-        if (fmodf(f, 1) == 0) {             //如果有一位小数点
-            return String(format: "%.0f",f)
-        } else if (fmodf(f*10, 1) == 0) {   //如果有两位小数点
-            return String(format: "%.1f",f)
-        } else {
-            return String(format: "%.2f",f)
-        }
-    }
-    
-    // MARK: Action
-    
-    @objc func buttonChangeType(_ sender: NSButton) -> Void {
-        if (sender == urlButtonVC.button) {
-            if urlButtonVC.state == .Norm {
-                urlButtonVC.image = NSImage(named: "KMRadioButtonSelect")!
-                urlButtonVC.state = .Checked
-                fileButtonVC.image = NSImage(named: "KMRadioButtonUnSelect")!
-                fileButtonVC.state = .Norm
-                urlTextfieldVC.editable = true
-                urlTextfieldVC.becomeFirstResponder = true
-                fileTextfieldVC.stringValue = ""
-                openFileVC.enabled = false
-                if urlTextfieldVC.stringValue.count > 0 {
-//                    openVC.enabled = true
-                } else {
-//                    openVC.enabled = false
-                }
-            }
-        } else if (sender == fileButtonVC.button) {
-            if fileButtonVC.state == .Norm {
-                urlButtonVC.image = NSImage(named: "KMRadioButtonUnSelect")!
-                urlButtonVC.state = .Norm
-                fileButtonVC.image = NSImage(named: "KMRadioButtonSelect")!
-                fileButtonVC.state = .Checked
-                urlTextfieldVC.editable = false
-                urlTextfieldVC.stringValue = ""
-                openFileVC.enabled = true
-                
-                if fileTextfieldVC.stringValue.count > 0 {
-//                    openVC.enabled = true
-                } else {
-//                    openVC.enabled = false
-                }
-            }
-        }
-        refreshUI()
-    }
-    
-    @objc func selectFileAction(_ sender: NSButton) -> Void {
-        urlButtonVC.state = .Norm
-        fileButtonVC.state = .Checked
-        urlTextfieldVC.editable = false
-        urlTextfieldVC.stringValue = ""
-//        openVC.enabled = false
-        
-        let openPanel = NSOpenPanel()
-        openPanel.canChooseFiles = true
-        openPanel.canChooseDirectories = false
-        openPanel.allowsMultipleSelection = false
-        openPanel.allowedFileTypes = ["HTML","html","webarchive","htm"]
-        openPanel.beginSheetModal(for: self.window!) { [self] response in
-            if response == .OK {
-                fileTextfieldVC.stringValue = openPanel.url!.path
-//                openVC.enabled = true
-                refreshUI()
-            }
-        }
-    }
- 
-    @objc func cancelAction(_ sender: NSButton) -> Void {
-        if (sender == cancelVC.button) {
-            NSApp.mainWindow!.endSheet(self.window!)
-            self.window?.orderOut(self)
-        }
-    }
-    
-    @objc func startAction(_ sender: NSButton) -> Void {
-        if (sender == openVC.button) {
-            if FileManager.default.fileExists(atPath: kUrlToPDFFolderPath()) {
-                try? FileManager.default.createDirectory(atPath: kUrlToPDFFolderPath(), withIntermediateDirectories: false)
-            }
-
-            var url: URL
-            var fileName: String = ""
-            if urlButtonVC.state == .Checked {
-                let urlstring = urlTextfieldVC.stringValue
-                var tUrl = URL(string: urlstring)
-                if tUrl?.scheme == nil {
-                    tUrl = URL(string: String(format: "http://%@", urlstring))
-                }
-                url = tUrl!
-            } else {
-                url = URL(fileURLWithPath: fileTextfieldVC.stringValue)
-                fileName = fileTextfieldVC.stringValue.lastPathComponent.deletingPathExtension.lastPathComponent
-            }
-            var string = stepperVC.text
-            let unitScanle: Float = (595.0/21.0) * 2.54
-            if Float(string)! <= 0 {
-                stepperVC.text = "0"
-                string = "0"
-            } else if Float(string)! * unitScanle > Float(pageSize.width)/2 {
-                let maxF = pageSize.width/(string.stringToCGFloat() * 2)
-                stepperVC.text = String(format: "%f",maxF)
-                string = String(format: "%f",maxF)
-            }
-            gap = Float(formatFloat(Float(string.stringToCGFloat()) * unitScanle))!
-            
-//            if url != nil {
-//                let convert = KMConvertURLToPDF.shareInstance()
-//                convert.fileName = fileName
-//                convert.convertUrl(toPDF: [url], toPath: kUrlToPDFFolderPath(), pageSize: pageSize, gap: CGFloat(gap)) { value in
-//                    
-//                } completionHandler: { successArray, failArray in
-//                    if failArray.count < 1 {
-//                        let filePath: String = successArray.first as! String
-//                        if FileManager.default.fileExists(atPath: filePath) {
-//                            self.filePath = filePath
-//                            NSApp.mainWindow!.endSheet(self.window!)
-//                            self.window?.orderOut(self)
-//                        }
-//                    } else {
-//                        let alert = NSAlert()
-//                        alert.alertStyle = .critical
-//                        alert.informativeText = NSLocalizedString("Conversion Failed", comment: "")
-//                        alert.messageText = NSLocalizedString("", comment: "")
-//                        alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-//                        alert.runModal()
-//                    }
-//                }
-//            }
-        }
-    }
-    
-    @IBAction func comboBoxItemClick_PageSize(_ sender: KMPopUpButton) {
-        switch pageSizePopUpButton.indexOfSelectedItem {
-        case 0:
-            pageSize = CGSize(width: 0, height: 0)
-            break
-        case 1:
-            pageSize = CGSize(width: 4760, height: 6736)
-            break
-        case 2:
-            pageSize = CGSize(width: 3368, height: 4760)
-            break
-        case 3:
-            pageSize = CGSize(width: 2380, height: 3368)
-            break
-        case 4:
-            pageSize = CGSize(width: 1684, height: 2380)
-            break
-        case 5:
-            pageSize = CGSize(width: 1190, height: 1684)
-            break
-        case 6:
-            pageSize = CGSize(width: 842, height: 1190)
-            break
-        case 7:
-            pageSize = CGSize(width: 595, height: 842)
-            break
-        case 8:
-            pageSize = CGSize(width: 420, height: 595)
-            break
-        case 9:
-            pageSize = CGSize(width: 298, height: 420)
-            break
-        default:
-            pageSize = CGSize(width: 210, height: 298)
-            break
-        }
-        if (pageSizePopUpButton.indexOfSelectedItem != 0) {
-            stepperVC.text = "0"
-            stepperVC.enabled = true
-        } else {
-            stepperVC.text = "0"
-            stepperVC.enabled = false
-        }
-        refreshUI()
-    }
-}
-
-extension KMURLToPDFWindowController: KMStepperViewDelegate {
-    func km_controlTextDidEndEditing(_ obj: KMStepperView) {
-        if obj == stepperVC {
-            var string: String = obj.text
-            let unitScanle: Float = (595.0/21.0) * 2.54
-            if (string.stringToCGFloat() <= 0) {
-                stepperVC.text = "0"
-                string = "0"
-            } else if (Float(string.stringToCGFloat()) * unitScanle > Float(pageSize.width)/2) {
-                let maxF = pageSize.width / (string.stringToCGFloat() * 2)
-                stepperVC.text = String(format: "%f",maxF)
-                string = String(format: "%f",maxF)
-            }
-            gap = Float(formatFloat(Float(string.stringToCGFloat()) * unitScanle))!
-            refreshUI()
-        }
-    }
-    
-    func km_controlTextDidChange(_ obj: KMStepperView) {
-        if obj == stepperVC {
-            if (urlButtonVC.state == .Checked) {
-                if (urlTextfieldVC.stringValue.count > 0) {
-//                    openVC.enabled = true
-                } else {
-//                    openVC.enabled = false
-                }
-            } else {
-                if (fileTextfieldVC.stringValue.count > 0) {
-//                    openVC.enabled = true
-                } else {
-//                    openVC.enabled = false
-                }
-            }
-        }
-        refreshUI()
-    }
-    
-    func km_controlClick(_ obj: KMStepperView) {
-        if (obj.text.stringToCGFloat() < 0) {
-            stepperVC.text = "0"
-        }
-        let unitScanle = (595.0/21.0) * 2.54
-        let formatter = formatFloat(Float(obj.text.stringToCGFloat() * unitScanle))
-        gap = Float(formatter)!
-        
-        refreshUI()
-    }
-}
-
-extension KMURLToPDFWindowController: KMTextfieldVCDelegate {
-    func km_controlTextDidEndEditing(_ obj: KMTextfieldVC) {
-        
-    }
-    
-    func km_controlTextDidChange(_ obj: KMTextfieldVC) {
-        if urlButtonVC.state == .Checked {
-            if urlTextfieldVC.stringValue.count > 0 {
-                openVC.enabled = true
-                refreshUI()
-            } else {
-                openVC.enabled = false
-                refreshUI()
-            }
-        } else {
-            if fileTextfieldVC.stringValue.count > 0 {
-                openVC.enabled = true
-                refreshUI()
-            } else {
-                openVC.enabled = false
-                refreshUI()
-            }
-        }
-    }
-}

+ 0 - 292
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController.xib

@@ -1,292 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
-    <dependencies>
-        <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
-        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
-    </dependencies>
-    <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMURLToPDFWindowController" customModule="PDF_Master" customModuleProvider="target">
-            <connections>
-                <outlet property="cancelView" destination="137-mQ-meg" id="IeR-yR-8Al"/>
-                <outlet property="fileButtonBox" destination="3Ww-O2-STf" id="9xj-nd-Itu"/>
-                <outlet property="fileTextFieldBox" destination="Avh-hY-SXB" id="xDP-Zg-KMk"/>
-                <outlet property="fileView" destination="qXY-ql-qU4" id="ApS-Qq-4nh"/>
-                <outlet property="mmLabel" destination="6LX-3p-Wa9" id="4kH-mo-gkN"/>
-                <outlet property="openView" destination="BEe-XQ-4yv" id="AHi-Ae-OxO"/>
-                <outlet property="pageConfigurationLabel" destination="pQd-aG-W5t" id="PyS-3j-Vut"/>
-                <outlet property="pageConfigurationView" destination="1ob-vx-s0R" id="wTd-Dk-6v4"/>
-                <outlet property="pageSizeLabel" destination="A7s-pc-oH6" id="NtP-jZ-yZt"/>
-                <outlet property="pageSizePopUpButton" destination="Xdv-g4-jY0" id="dSj-eN-0TC"/>
-                <outlet property="spacingLanel" destination="6XK-Pz-ujn" id="ebk-qx-lC7"/>
-                <outlet property="stepperBox" destination="Urb-tD-cQm" id="nki-XD-DAR"/>
-                <outlet property="title" destination="pJU-XO-8iX" id="atc-RQ-s48"/>
-                <outlet property="urlTextFieldBox" destination="vPp-iu-2FN" id="eor-V4-mpN"/>
-                <outlet property="urlView" destination="Py4-BC-ARo" id="Iyb-2l-v4q"/>
-                <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
-            </connections>
-        </customObject>
-        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
-        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
-        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES"/>
-            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
-            <rect key="contentRect" x="196" y="240" width="948" height="493"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
-            <view key="contentView" id="se5-gp-TjO">
-                <rect key="frame" x="0.0" y="0.0" width="948" height="370"/>
-                <autoresizingMask key="autoresizingMask"/>
-                <subviews>
-                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="y7U-Dm-f0s">
-                        <rect key="frame" x="16" y="0.0" width="916" height="370"/>
-                        <subviews>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="u8l-AB-pxk">
-                                <rect key="frame" x="0.0" y="333" width="916" height="24"/>
-                                <subviews>
-                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pJU-XO-8iX">
-                                        <rect key="frame" x="-2" y="4" width="37" height="16"/>
-                                        <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="hRe-34-aDe">
-                                            <font key="font" usesAppearanceFont="YES"/>
-                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                        </textFieldCell>
-                                    </textField>
-                                </subviews>
-                                <constraints>
-                                    <constraint firstItem="pJU-XO-8iX" firstAttribute="centerY" secondItem="u8l-AB-pxk" secondAttribute="centerY" id="OvU-ex-uxc"/>
-                                    <constraint firstAttribute="height" constant="24" id="nUg-WN-GSh"/>
-                                    <constraint firstItem="pJU-XO-8iX" firstAttribute="leading" secondItem="u8l-AB-pxk" secondAttribute="leading" id="vQE-35-3b0"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="Py4-BC-ARo">
-                                <rect key="frame" x="0.0" y="298" width="916" height="22"/>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="22" id="wZo-Xp-0WB"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="wCP-ff-q0J">
-                                <rect key="frame" x="0.0" y="180" width="916" height="32"/>
-                                <subviews>
-                                    <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Avh-hY-SXB">
-                                        <rect key="frame" x="0.0" y="0.0" width="876" height="32"/>
-                                        <view key="contentView" id="cl7-lg-Taj">
-                                            <rect key="frame" x="0.0" y="0.0" width="876" height="32"/>
-                                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                        </view>
-                                    </box>
-                                    <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="3Ww-O2-STf">
-                                        <rect key="frame" x="884" y="0.0" width="32" height="32"/>
-                                        <view key="contentView" id="heH-4o-sO5">
-                                            <rect key="frame" x="0.0" y="0.0" width="32" height="32"/>
-                                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                        </view>
-                                        <constraints>
-                                            <constraint firstAttribute="width" constant="32" id="2XY-4B-Yca"/>
-                                            <constraint firstAttribute="width" secondItem="3Ww-O2-STf" secondAttribute="height" multiplier="1:1" id="PWw-t2-7sq"/>
-                                        </constraints>
-                                    </box>
-                                </subviews>
-                                <constraints>
-                                    <constraint firstItem="Avh-hY-SXB" firstAttribute="leading" secondItem="wCP-ff-q0J" secondAttribute="leading" id="aDQ-3m-0MX"/>
-                                    <constraint firstAttribute="bottom" secondItem="Avh-hY-SXB" secondAttribute="bottom" id="cnq-4Z-D3M"/>
-                                    <constraint firstAttribute="trailing" secondItem="3Ww-O2-STf" secondAttribute="trailing" id="ezA-u7-puH"/>
-                                    <constraint firstItem="3Ww-O2-STf" firstAttribute="leading" secondItem="Avh-hY-SXB" secondAttribute="trailing" constant="8" id="nNS-Mw-wnM"/>
-                                    <constraint firstAttribute="bottom" secondItem="3Ww-O2-STf" secondAttribute="bottom" id="uhq-q1-H1x"/>
-                                    <constraint firstAttribute="height" constant="32" id="yB6-sP-T07"/>
-                                    <constraint firstItem="Avh-hY-SXB" firstAttribute="top" secondItem="wCP-ff-q0J" secondAttribute="top" id="zHz-fe-FqV"/>
-                                    <constraint firstItem="3Ww-O2-STf" firstAttribute="top" secondItem="wCP-ff-q0J" secondAttribute="top" id="zpM-sU-uup"/>
-                                </constraints>
-                            </customView>
-                            <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="vPp-iu-2FN">
-                                <rect key="frame" x="0.0" y="258" width="916" height="32"/>
-                                <view key="contentView" id="bnu-dm-hvU">
-                                    <rect key="frame" x="0.0" y="0.0" width="916" height="32"/>
-                                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                </view>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="32" id="mjF-Un-QOb"/>
-                                </constraints>
-                            </box>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="1ob-vx-s0R">
-                                <rect key="frame" x="0.0" y="144" width="916" height="20"/>
-                                <subviews>
-                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pQd-aG-W5t">
-                                        <rect key="frame" x="-2" y="2" width="37" height="16"/>
-                                        <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="Ic1-jB-Dow">
-                                            <font key="font" usesAppearanceFont="YES"/>
-                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                        </textFieldCell>
-                                    </textField>
-                                </subviews>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="20" id="287-jQ-YKq"/>
-                                    <constraint firstItem="pQd-aG-W5t" firstAttribute="leading" secondItem="1ob-vx-s0R" secondAttribute="leading" id="ClC-VL-020"/>
-                                    <constraint firstItem="pQd-aG-W5t" firstAttribute="centerY" secondItem="1ob-vx-s0R" secondAttribute="centerY" id="bA1-w0-efb"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="H2J-9d-Zrv">
-                                <rect key="frame" x="0.0" y="104" width="916" height="32"/>
-                                <subviews>
-                                    <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="uk7-mo-ZMr">
-                                        <rect key="frame" x="601" y="0.0" width="315" height="32"/>
-                                        <view key="contentView" id="hqg-xS-6zj">
-                                            <rect key="frame" x="1" y="1" width="313" height="30"/>
-                                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                            <subviews>
-                                                <popUpButton translatesAutoresizingMaskIntoConstraints="NO" id="Xdv-g4-jY0" customClass="KMPopUpButton">
-                                                    <rect key="frame" x="-5" y="0.0" width="318" height="30"/>
-                                                    <popUpButtonCell key="cell" type="bevel" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" arrowPosition="noArrow" selectedItem="hZy-kr-YE8" id="b1x-JM-ryW">
-                                                        <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
-                                                        <font key="font" metaFont="menu"/>
-                                                        <menu key="menu" id="TAo-el-XNS">
-                                                            <items>
-                                                                <menuItem title="Item 1" state="on" id="hZy-kr-YE8"/>
-                                                                <menuItem title="Item 2" id="GyX-Yu-W8h"/>
-                                                                <menuItem title="Item 3" id="xSn-aj-ht8"/>
-                                                            </items>
-                                                        </menu>
-                                                    </popUpButtonCell>
-                                                    <connections>
-                                                        <action selector="comboBoxItemClick_PageSize:" target="-2" id="7XV-B0-J5g"/>
-                                                    </connections>
-                                                </popUpButton>
-                                            </subviews>
-                                            <constraints>
-                                                <constraint firstAttribute="bottom" secondItem="Xdv-g4-jY0" secondAttribute="bottom" id="6rz-Er-UEP"/>
-                                                <constraint firstItem="Xdv-g4-jY0" firstAttribute="leading" secondItem="hqg-xS-6zj" secondAttribute="leading" id="ORX-FU-1KD"/>
-                                                <constraint firstItem="Xdv-g4-jY0" firstAttribute="top" secondItem="hqg-xS-6zj" secondAttribute="top" id="eYc-bd-mFb"/>
-                                                <constraint firstAttribute="trailing" secondItem="Xdv-g4-jY0" secondAttribute="trailing" id="sT4-5P-pv2"/>
-                                            </constraints>
-                                        </view>
-                                        <constraints>
-                                            <constraint firstAttribute="width" constant="315" id="aTI-iG-wY9"/>
-                                        </constraints>
-                                    </box>
-                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="A7s-pc-oH6">
-                                        <rect key="frame" x="-2" y="8" width="37" height="16"/>
-                                        <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="sOJ-pa-2O7">
-                                            <font key="font" usesAppearanceFont="YES"/>
-                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                        </textFieldCell>
-                                    </textField>
-                                </subviews>
-                                <constraints>
-                                    <constraint firstItem="Xdv-g4-jY0" firstAttribute="centerY" secondItem="A7s-pc-oH6" secondAttribute="centerY" id="1iH-GV-EX4"/>
-                                    <constraint firstItem="uk7-mo-ZMr" firstAttribute="top" secondItem="H2J-9d-Zrv" secondAttribute="top" id="58Y-iP-kZD"/>
-                                    <constraint firstAttribute="trailing" secondItem="uk7-mo-ZMr" secondAttribute="trailing" id="6we-aY-zAr"/>
-                                    <constraint firstAttribute="height" constant="32" id="86p-f3-3a7"/>
-                                    <constraint firstItem="A7s-pc-oH6" firstAttribute="leading" secondItem="H2J-9d-Zrv" secondAttribute="leading" id="E6V-sR-Biu"/>
-                                    <constraint firstAttribute="bottom" secondItem="uk7-mo-ZMr" secondAttribute="bottom" id="QQ5-xc-RHJ"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="Hqe-7Y-xOc">
-                                <rect key="frame" x="0.0" y="64" width="916" height="32"/>
-                                <subviews>
-                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6XK-Pz-ujn">
-                                        <rect key="frame" x="-2" y="8" width="37" height="16"/>
-                                        <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="kaR-yG-KYb">
-                                            <font key="font" usesAppearanceFont="YES"/>
-                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                        </textFieldCell>
-                                    </textField>
-                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6LX-3p-Wa9">
-                                        <rect key="frame" x="688" y="8" width="37" height="16"/>
-                                        <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="EWG-2f-7HR">
-                                            <font key="font" metaFont="system"/>
-                                            <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                        </textFieldCell>
-                                    </textField>
-                                    <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Urb-tD-cQm">
-                                        <rect key="frame" x="602" y="0.0" width="72" height="32"/>
-                                        <view key="contentView" id="dHM-jY-BRD">
-                                            <rect key="frame" x="0.0" y="0.0" width="72" height="32"/>
-                                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                        </view>
-                                        <constraints>
-                                            <constraint firstAttribute="width" constant="72" id="VCP-ml-nOI"/>
-                                        </constraints>
-                                    </box>
-                                </subviews>
-                                <constraints>
-                                    <constraint firstItem="6LX-3p-Wa9" firstAttribute="leading" secondItem="Urb-tD-cQm" secondAttribute="trailing" constant="16" id="7Em-6V-IIo"/>
-                                    <constraint firstItem="6LX-3p-Wa9" firstAttribute="centerY" secondItem="Urb-tD-cQm" secondAttribute="centerY" id="B3d-Va-k9B"/>
-                                    <constraint firstItem="6XK-Pz-ujn" firstAttribute="leading" secondItem="Hqe-7Y-xOc" secondAttribute="leading" id="Egl-8C-J57"/>
-                                    <constraint firstAttribute="bottom" secondItem="Urb-tD-cQm" secondAttribute="bottom" id="KQC-wp-MJb"/>
-                                    <constraint firstItem="Urb-tD-cQm" firstAttribute="top" secondItem="Hqe-7Y-xOc" secondAttribute="top" id="Nbc-7X-yfA"/>
-                                    <constraint firstItem="6XK-Pz-ujn" firstAttribute="centerY" secondItem="Hqe-7Y-xOc" secondAttribute="centerY" id="VXE-st-Cex"/>
-                                    <constraint firstAttribute="height" constant="32" id="sl6-1U-SQm"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="qXY-ql-qU4">
-                                <rect key="frame" x="0.0" y="220" width="916" height="22"/>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="22" id="DYt-Mv-u59"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="BEe-XQ-4yv">
-                                <rect key="frame" x="836" y="16" width="80" height="32"/>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="32" id="ELy-KZ-rr2"/>
-                                    <constraint firstAttribute="width" constant="80" id="ZVh-hQ-VjF"/>
-                                </constraints>
-                            </customView>
-                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="137-mQ-meg">
-                                <rect key="frame" x="740" y="16" width="80" height="32"/>
-                                <constraints>
-                                    <constraint firstAttribute="width" constant="80" id="Tdx-qT-DmD"/>
-                                    <constraint firstAttribute="height" constant="32" id="j2y-fh-TrC"/>
-                                </constraints>
-                            </customView>
-                        </subviews>
-                        <constraints>
-                            <constraint firstItem="Xdv-g4-jY0" firstAttribute="leading" secondItem="Urb-tD-cQm" secondAttribute="leading" id="1MB-x3-AFI"/>
-                            <constraint firstItem="H2J-9d-Zrv" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="1Uv-wV-2Q5"/>
-                            <constraint firstItem="wCP-ff-q0J" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="2kG-2l-g4O"/>
-                            <constraint firstItem="vPp-iu-2FN" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="6Q4-gd-ddF"/>
-                            <constraint firstAttribute="trailing" secondItem="qXY-ql-qU4" secondAttribute="trailing" id="EGM-Ng-g3h"/>
-                            <constraint firstItem="Py4-BC-ARo" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="Ef4-uD-1Eg"/>
-                            <constraint firstItem="Py4-BC-ARo" firstAttribute="top" secondItem="u8l-AB-pxk" secondAttribute="bottom" constant="13" id="FsH-WW-fbl"/>
-                            <constraint firstAttribute="trailing" secondItem="vPp-iu-2FN" secondAttribute="trailing" id="G4A-n4-3hx"/>
-                            <constraint firstItem="qXY-ql-qU4" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="HPn-oV-vfT"/>
-                            <constraint firstItem="BEe-XQ-4yv" firstAttribute="leading" secondItem="137-mQ-meg" secondAttribute="trailing" constant="16" id="IVH-s4-tiI"/>
-                            <constraint firstAttribute="trailing" secondItem="wCP-ff-q0J" secondAttribute="trailing" id="RZY-Vc-L0U"/>
-                            <constraint firstItem="H2J-9d-Zrv" firstAttribute="top" secondItem="1ob-vx-s0R" secondAttribute="bottom" constant="8" id="TJA-uy-YdO"/>
-                            <constraint firstAttribute="trailing" secondItem="Py4-BC-ARo" secondAttribute="trailing" id="Xvb-C0-k8d"/>
-                            <constraint firstItem="Hqe-7Y-xOc" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="Y5z-ai-Lds"/>
-                            <constraint firstAttribute="trailing" secondItem="Hqe-7Y-xOc" secondAttribute="trailing" id="aYH-qK-OZo"/>
-                            <constraint firstAttribute="bottom" secondItem="BEe-XQ-4yv" secondAttribute="bottom" constant="16" id="axQ-9u-Ogm"/>
-                            <constraint firstItem="vPp-iu-2FN" firstAttribute="top" secondItem="Py4-BC-ARo" secondAttribute="bottom" constant="8" id="b9M-vS-eh0"/>
-                            <constraint firstItem="1ob-vx-s0R" firstAttribute="top" secondItem="wCP-ff-q0J" secondAttribute="bottom" constant="16" id="cHU-jD-GRO"/>
-                            <constraint firstAttribute="trailing" secondItem="H2J-9d-Zrv" secondAttribute="trailing" id="dmJ-ho-1s4"/>
-                            <constraint firstItem="BEe-XQ-4yv" firstAttribute="centerY" secondItem="137-mQ-meg" secondAttribute="centerY" id="gFE-SN-YhO"/>
-                            <constraint firstAttribute="trailing" secondItem="u8l-AB-pxk" secondAttribute="trailing" id="gLK-SP-Am0"/>
-                            <constraint firstItem="wCP-ff-q0J" firstAttribute="top" secondItem="qXY-ql-qU4" secondAttribute="bottom" constant="8" id="i6n-Qh-7ne"/>
-                            <constraint firstAttribute="trailing" secondItem="BEe-XQ-4yv" secondAttribute="trailing" id="jY9-WR-ybU"/>
-                            <constraint firstItem="BEe-XQ-4yv" firstAttribute="top" secondItem="Hqe-7Y-xOc" secondAttribute="bottom" constant="16" id="jds-AS-Fk0"/>
-                            <constraint firstItem="1ob-vx-s0R" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="qyo-cu-fNc"/>
-                            <constraint firstItem="u8l-AB-pxk" firstAttribute="leading" secondItem="y7U-Dm-f0s" secondAttribute="leading" id="vTV-Ky-m8i"/>
-                            <constraint firstItem="qXY-ql-qU4" firstAttribute="top" secondItem="vPp-iu-2FN" secondAttribute="bottom" constant="16" id="w32-nd-Ghm"/>
-                            <constraint firstItem="Hqe-7Y-xOc" firstAttribute="top" secondItem="H2J-9d-Zrv" secondAttribute="bottom" constant="8" id="wJM-w1-5Pm"/>
-                            <constraint firstAttribute="trailing" secondItem="1ob-vx-s0R" secondAttribute="trailing" id="z0l-vC-sov"/>
-                            <constraint firstItem="u8l-AB-pxk" firstAttribute="top" secondItem="y7U-Dm-f0s" secondAttribute="top" constant="13" id="zbb-AU-0vW"/>
-                        </constraints>
-                    </customView>
-                </subviews>
-                <constraints>
-                    <constraint firstItem="y7U-Dm-f0s" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="16" id="LTM-tp-dzh"/>
-                    <constraint firstAttribute="bottom" secondItem="y7U-Dm-f0s" secondAttribute="bottom" id="aAm-7t-IUH"/>
-                    <constraint firstItem="y7U-Dm-f0s" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="wOZ-8s-PPz"/>
-                    <constraint firstAttribute="trailing" secondItem="y7U-Dm-f0s" secondAttribute="trailing" constant="16" id="zLY-Yl-Tgc"/>
-                </constraints>
-            </view>
-            <connections>
-                <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
-            </connections>
-            <point key="canvasLocation" x="311" y="255.5"/>
-        </window>
-    </objects>
-</document>

+ 340 - 0
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController/KMURLToPDFWindowController.swift

@@ -0,0 +1,340 @@
+//
+//  KMURLToPDFWindowController.swift
+//  PDF Master
+//
+//  Created by wanjun on 2023/1/29.
+//
+
+import Cocoa
+
+let kUrlToPDFFolderPath = (try? FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true).appendingPathComponent(Bundle.main.bundleIdentifier ?? "").appendingPathComponent("WebPage"))?.path ?? ""
+
+
+typealias KMURLToPDFWindowControllerComplete = (_ filePath: String) -> Void
+class KMURLToPDFWindowController: NSWindowController, NSTextFieldDelegate {
+    @IBOutlet var urlBtn: NSButton!
+    @IBOutlet var localHtmlBtn: NSButton!
+    @IBOutlet var outputBackView: NSView!
+    @IBOutlet var outputText: NSTextField!
+    @IBOutlet var outputButton: NSButton!
+    @IBOutlet var pageSizeComboBox: NSComboBox!
+    @IBOutlet var pageViewLabel: NSTextField!
+    @IBOutlet var pageSizeLabel: NSTextField!
+    @IBOutlet var pageGapLabel: NSTextField!
+    @IBOutlet var pageGapTextField: NSTextField!
+    @IBOutlet var pagesGapStepper: NSStepper!
+    @IBOutlet var btnConvert: NSButton!
+    @IBOutlet var btnCancel: NSButton!
+    @IBOutlet var urlTextField: NSTextField!
+    
+    var filePath: String?
+//    var posterMaskView: KMBookletMaskView?
+    var gap: CGFloat = 0
+    var pageSize: CGSize = CGSizeMake(298, 420)
+    
+    var handler: KMURLToPDFWindowControllerComplete?
+
+    override init(window: NSWindow?) {
+        super.init(window: window)
+    }
+
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+
+    override func windowDidLoad() {
+        super.windowDidLoad()
+
+        window?.title = NSLocalizedString("Web Page To PDF", comment: "")
+        
+        pageViewLabel.stringValue = NSLocalizedString("Page View", comment: "")
+        pageSizeLabel.stringValue = NSLocalizedString("Page size:", comment: "")
+        pageGapLabel.stringValue = "\(NSLocalizedString("Spacing", comment: "")):"
+        
+        urlBtn.title = NSLocalizedString("URL", comment: "")
+        localHtmlBtn.title = NSLocalizedString("File", comment: "")
+        btnConvert.title = NSLocalizedString("Save as PDF", comment: "")
+        btnCancel.title = NSLocalizedString("Cancel", comment: "")
+        outputButton.title = NSLocalizedString("Choose...", comment: "")
+        
+        outputBackView.wantsLayer = true
+        outputBackView.layer?.borderWidth = 0.8
+        outputBackView.layer?.borderColor = NSColor(red: 177.0/255, green: 178.0/255, blue: 177.0/255, alpha: 1).cgColor
+        urlTextField.placeholderString = "https://www.pdfreaderpro.com"
+        urlTextField.delegate = self
+        outputText.isEditable = false
+
+        pageSizeComboBox.addItems(withObjectValues: [
+            NSLocalizedString("Automatically Resize", comment: "Menu item title"),
+            "4A0 1682 × 2378 mm",
+            "2A0 1189 × 1682 mm",
+            "A0 841 × 1189 mm",
+            "A1 594 × 841 mm",
+            "A2 420 × 594 mm",
+            "A3 297 × 420 mm",
+            "A4 210 × 297 mm",
+            "A5 148 × 210 mm",
+            "A6 105 × 148 mm",
+            "A7 74 × 105 mm",
+            "A8 52 × 74 mm",
+            "A9 37 × 52 mm",
+            "A10 26 × 37 mm"
+        ])
+        pageSizeComboBox.selectItem(at: 0)
+        pageSizeComboBox.isEditable = false
+
+        pageSize = CGSizeMake(298, 420)
+        gap = 0
+
+        pagesGapStepper.stringValue = "0"
+        pagesGapStepper.isEnabled = false
+        pageGapTextField.isEnabled = false
+
+        if urlBtn.state == .on {
+            if urlTextField.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        } else {
+            if outputText.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        }
+
+        outputText.placeholderString = "\(NSLocalizedString("Select a File", comment: "")) (.html, .webarchive)"
+        outputButton.isEnabled = false
+    }
+
+    func isUrl(_ urlString: String?) -> Bool {
+        guard let urlString = urlString else { return false }
+        
+        // 实现方法有问题,暂不使用
+        var url: String
+        if urlString.count > 4, urlString.prefix(4) == "www." {
+            url = "http://\(urlString)"
+        } else {
+            url = urlString
+        }
+        let urlRegex = "\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?"
+        let urlTest = NSPredicate(format: "SELF MATCHES %@", urlRegex)
+        return urlTest.evaluate(with: url)
+    }
+
+    func beginSheetModalForWindow(_ window: NSWindow, completionHandler handler: ((String) -> Void)?) {
+        self.handler = handler
+        NSWindow.currentWindow().beginSheet(self.window!) { response in
+            self.handler?(self.filePath ?? "")
+        }
+    }
+
+    @IBAction func buttonItemClicked_Cancel(_ sender: NSButton) {
+        self.window?.endSheet(NSWindow.currentWindow())
+    }
+
+    func urlValueEncode(_ str: String) -> String? {
+        let allowedCharacterSet = CharacterSet(charactersIn: "!*'();:@&=+$,?%#[]{}").inverted
+        return str.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)
+    }
+
+
+    @IBAction func buttonItemClicked_Start(_ sender: NSButton) {
+        if !FileManager.default.fileExists(atPath: kUrlToPDFFolderPath) {
+            try? FileManager.default.createDirectory(atPath: kUrlToPDFFolderPath, withIntermediateDirectories: false, attributes: nil)
+        }
+
+        var url: URL?
+        var fileName: String?
+        if urlBtn.state == .on {
+            let urlString = urlTextField.stringValue
+            var tUrl = URL(string: urlString)
+            if tUrl?.scheme?.count ?? 0 < 1 {
+                tUrl = URL(string: "http://\(urlString)")
+            }
+            url = tUrl
+        } else {
+            url = URL(fileURLWithPath: outputText.stringValue)
+            fileName = outputText.stringValue.lastPathComponent.deletingPathExtension
+        }
+
+        let string = pageGapTextField.stringValue
+        let unitScale: CGFloat = (595.0 / 21.0) * 2.54
+
+        if string.stringToCGFloat() <= 0 {
+            pageGapTextField.stringValue = "0"
+        } else if string.stringToCGFloat() * unitScale > pageSize.width / 2 {
+            let maxF = pageSize.width / (string.stringToCGFloat() * 2)
+            pageGapTextField.stringValue = "\(maxF)"
+        }
+        
+        gap = formatFloat(Float(string.stringToCGFloat() * unitScale)).stringToCGFloat()
+
+        if let url = url {
+            showWaitting()
+            let convert = KMConvertURLToPDF.shareInstance()
+            convert.fileName = fileName ?? ""
+            convert.convertUrl(toPDF: [url], toPath: kUrlToPDFFolderPath, pageSize: pageSize, gap: gap, progress: { value in
+                // Progress update
+            }, completionHandler: { successArray, failArray in
+                self.hideWaitting()
+                if failArray.isEmpty {
+                    if let filePath = successArray.first as? String, FileManager.default.fileExists(atPath: filePath) {
+                        self.filePath = filePath
+                        NSApp.endSheet(self.window!, returnCode: sender.tag)
+                        self.window?.orderOut(self)
+                    }
+                } else {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.informativeText = NSLocalizedString("Conversion Failed", comment: "")
+                    alert.messageText = ""
+                    alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                    alert.runModal()
+                }
+            })
+        }
+    }
+
+    @IBAction func buttonItemClick_Add(_ sender: Any) {
+        urlBtn.state = .off
+        localHtmlBtn.state = .on
+        urlTextField.isEditable = false
+        urlTextField.stringValue = ""
+        btnConvert.isEnabled = false
+
+        let panel = NSOpenPanel()
+        panel.canChooseFiles = true
+        panel.canChooseDirectories = false
+        panel.allowsMultipleSelection = false
+        panel.allowedFileTypes = ["HTML", "html", "webarchive", "htm"]
+        panel.beginSheetModal(for: window!) { response in
+            if response == .OK {
+                self.outputText.stringValue = panel.url?.path ?? ""
+                self.btnConvert.isEnabled = true
+            }
+        }
+    }
+
+    @IBAction func buttonItemClick_ChangeType(_ sender: NSButton) {
+        if urlBtn.state == .on {
+            urlTextField.isEditable = true
+            urlTextField.becomeFirstResponder()
+            outputText.stringValue = ""
+            outputButton.isEnabled = false
+
+            if urlTextField.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        } else {
+            urlTextField.isEditable = false
+            urlTextField.stringValue = ""
+            outputButton.isEnabled = true
+
+            if outputText.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        }
+    }
+
+    @IBAction func comboBoxItemClick_PageSize(_ sender: NSComboBox) {
+        switch sender.indexOfSelectedItem {
+        case 0:
+            pageSize = CGSizeMake(298, 420)
+        case 1:
+            pageSize = CGSize(width: 4760, height: 6736)
+        case 2:
+            pageSize = CGSize(width: 3368, height: 4760)
+        case 3:
+            pageSize = CGSize(width: 2380, height: 3368)
+        case 4:
+            pageSize = CGSize(width: 1684, height: 2380)
+        case 5:
+            pageSize = CGSize(width: 1190, height: 1684)
+        case 6:
+            pageSize = CGSize(width: 842, height: 1190)
+        case 7:
+            pageSize = CGSize(width: 595, height: 842)
+        case 8:
+            pageSize = CGSize(width: 420, height: 595)
+        case 9:
+            pageSize = CGSize(width: 297, height: 420)
+        default:
+            pageSize = CGSize(width: 210, height: 297)
+        }
+        
+        if sender.indexOfSelectedItem != 0 {
+            pagesGapStepper.stringValue = "0"
+            pageGapTextField.stringValue = "0"
+            pageGapTextField.isEnabled = true
+            pagesGapStepper.isEnabled = true
+        } else {
+            pagesGapStepper.stringValue = "0"
+            pageGapTextField.stringValue = ""
+            pageGapTextField.isEnabled = false
+            pagesGapStepper.isEnabled = false
+        }
+    }
+
+    @IBAction func stepperItemClick_Gap(_ sender: NSStepper) {
+        let unitScale: CGFloat = (595.0 / 21.0) * 2.54
+        pageGapTextField.stringValue = String(format: "%.2f", pagesGapStepper.floatValue)
+        gap = formatFloat(pagesGapStepper.floatValue * Float(unitScale)).stringToCGFloat()
+    }
+
+    func controlTextDidEndEditing(_ obj: Notification) {
+        if let object = obj.object as? NSTextField, object == pageGapTextField {
+            let unitScale: CGFloat = (595.0 / 21.0) * 2.54
+            if object.stringValue.stringToCGFloat() <= 0 {
+                pageGapTextField.stringValue = "0"
+            } else if object.stringValue.stringToCGFloat() * unitScale > pageSize.width / 2 {
+                let maxF = pageSize.width / (object.stringValue.stringToCGFloat() * 2)
+                pageGapTextField.stringValue = "\(maxF)"
+            }
+            gap = formatFloat(Float(object.stringValue.stringToCGFloat() * unitScale)).stringToCGFloat()
+            pagesGapStepper.floatValue = Float(object.stringValue.stringToCGFloat())
+        }
+    }
+
+    func controlTextDidChange(_ notification: Notification) {
+        if urlBtn.state == .on {
+            if urlTextField.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        } else {
+            if outputText.stringValue.count > 0 {
+                btnConvert.isEnabled = true
+            } else {
+                btnConvert.isEnabled = false
+            }
+        }
+    }
+
+    func formatFloat(_ f: Float) -> String {
+        if f.truncatingRemainder(dividingBy: 1) == 0 {
+            return String(format: "%.0f", f)
+        } else if (f * 10).truncatingRemainder(dividingBy: 1) == 0 {
+            return String(format: "%.1f", f)
+        } else {
+            return String(format: "%.2f", f)
+        }
+    }
+
+    func showWaitting() {
+//        if posterMaskView == nil {
+//            posterMaskView = KMBookletMaskView(frame: NSMakeRect(0, 0, window?.frame.size.width ?? 0, window?.frame.size.height ?? 0))
+//        }
+//        window?.contentView?.addSubview(posterMaskView!)
+    }
+
+    func hideWaitting() {
+//        /*posterMaskView*/?.removeFromSuperview()
+    }
+}

+ 267 - 0
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController/KMURLToPDFWindowController.xib

@@ -0,0 +1,267 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+    <dependencies>
+        <deployment identifier="macosx"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <objects>
+        <customObject id="-2" userLabel="File's Owner" customClass="KMURLToPDFWindowController" customModule="PDF_Master" customModuleProvider="target">
+            <connections>
+                <outlet property="btnCancel" destination="RBm-Bc-rao" id="CGU-CY-d09"/>
+                <outlet property="btnConvert" destination="pGf-Iz-7zg" id="Nb0-CU-xQo"/>
+                <outlet property="localHtmlBtn" destination="lzo-55-xro" id="e1j-Mi-NAV"/>
+                <outlet property="outputBackView" destination="9as-I6-zpb" id="Mmf-50-4LV"/>
+                <outlet property="outputButton" destination="ivv-Jx-DtL" id="0rk-2K-u4y"/>
+                <outlet property="outputText" destination="CHD-gL-zXA" id="edK-6C-Ybt"/>
+                <outlet property="pageGapLabel" destination="Nyc-8R-qOb" id="zyg-eC-M2l"/>
+                <outlet property="pageGapTextField" destination="Cp6-0C-kLI" id="Rzi-4u-Cax"/>
+                <outlet property="pageSizeComboBox" destination="V7a-Ei-Dbd" id="U3R-we-Xjb"/>
+                <outlet property="pageSizeLabel" destination="cM6-kD-ec2" id="v27-jQ-Ew3"/>
+                <outlet property="pageViewLabel" destination="TbI-Vb-tNK" id="vpM-YB-QdK"/>
+                <outlet property="pagesGapStepper" destination="Edm-Zn-7sR" id="sQu-yk-Dzg"/>
+                <outlet property="urlBtn" destination="KNR-nf-HXd" id="qyj-SH-t5V"/>
+                <outlet property="urlTextField" destination="Z7f-fU-KFb" id="ElL-Vc-y7C"/>
+                <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
+            </connections>
+        </customObject>
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
+            <windowStyleMask key="styleMask" titled="YES"/>
+            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
+            <rect key="contentRect" x="196" y="240" width="948" height="493"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
+            <view key="contentView" id="se5-gp-TjO">
+                <rect key="frame" x="0.0" y="0.0" width="948" height="281"/>
+                <autoresizingMask key="autoresizingMask"/>
+                <subviews>
+                    <view wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Tqy-vm-qC1">
+                        <rect key="frame" x="0.0" y="0.0" width="948" height="281"/>
+                        <subviews>
+                            <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Z7f-fU-KFb">
+                                <rect key="frame" x="40" y="213" width="888" height="22"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="22" id="Rad-lJ-oiP"/>
+                                </constraints>
+                                <textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="20f-Fu-B8e">
+                                    <font key="font" metaFont="system"/>
+                                    <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                    <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                </textFieldCell>
+                            </textField>
+                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="pGf-Iz-7zg">
+                                <rect key="frame" x="825" y="13" width="110" height="32"/>
+                                <buttonCell key="cell" type="push" title="Save as PDF" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AQ2-ge-gzy">
+                                    <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                    <string key="keyEquivalent" base64-UTF8="YES">
+Gw
+</string>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="buttonItemClicked_Start:" target="-2" id="jzQ-rL-KD3"/>
+                                </connections>
+                            </button>
+                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RBm-Bc-rao">
+                                <rect key="frame" x="743" y="13" width="76" height="32"/>
+                                <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="JTu-XM-0VY">
+                                    <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                    <string key="keyEquivalent" base64-UTF8="YES">
+Gw
+</string>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="buttonItemClicked_Cancel:" target="-2" id="Ekg-td-PxQ"/>
+                                </connections>
+                            </button>
+                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KNR-nf-HXd">
+                                <rect key="frame" x="18" y="244" width="56" height="18"/>
+                                <buttonCell key="cell" type="radio" title="URL:" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="Uh4-mi-pjX">
+                                    <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="buttonItemClick_ChangeType:" target="-2" id="hxH-7L-y56"/>
+                                </connections>
+                            </button>
+                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lzo-55-xro">
+                                <rect key="frame" x="18" y="186" width="138" height="18"/>
+                                <buttonCell key="cell" type="radio" title="Import local HTML" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="x5D-4h-UO1">
+                                    <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="buttonItemClick_ChangeType:" target="-2" id="EqF-Oe-XMb"/>
+                                </connections>
+                            </button>
+                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="9as-I6-zpb">
+                                <rect key="frame" x="40" y="155" width="816" height="22"/>
+                                <subviews>
+                                    <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CHD-gL-zXA">
+                                        <rect key="frame" x="0.0" y="0.0" width="816" height="20"/>
+                                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" drawsBackground="YES" id="aIt-sK-xvj">
+                                            <font key="font" metaFont="system"/>
+                                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                        </textFieldCell>
+                                    </textField>
+                                </subviews>
+                                <constraints>
+                                    <constraint firstItem="CHD-gL-zXA" firstAttribute="top" secondItem="9as-I6-zpb" secondAttribute="top" constant="2" id="7Pi-jK-Drl"/>
+                                    <constraint firstAttribute="trailing" secondItem="CHD-gL-zXA" secondAttribute="trailing" id="COJ-1W-O6s"/>
+                                    <constraint firstAttribute="bottom" secondItem="CHD-gL-zXA" secondAttribute="bottom" id="VhB-vk-x3G"/>
+                                    <constraint firstAttribute="height" constant="22" id="X4h-8U-bgj"/>
+                                    <constraint firstItem="CHD-gL-zXA" firstAttribute="leading" secondItem="9as-I6-zpb" secondAttribute="leading" id="zi9-JF-Tqh"/>
+                                </constraints>
+                            </customView>
+                            <box boxType="custom" borderType="none" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="z2n-2N-gFR">
+                                <rect key="frame" x="20" y="60" width="908" height="75"/>
+                                <view key="contentView" id="5yg-ty-rMO">
+                                    <rect key="frame" x="0.0" y="0.0" width="908" height="75"/>
+                                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                                    <subviews>
+                                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TbI-Vb-tNK">
+                                            <rect key="frame" x="-2" y="59" width="67" height="16"/>
+                                            <textFieldCell key="cell" lineBreakMode="clipping" title="Page View" id="7ZZ-G7-Qyf">
+                                                <font key="font" usesAppearanceFont="YES"/>
+                                                <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cM6-kD-ec2">
+                                            <rect key="frame" x="18" y="33" width="70" height="16"/>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Page Size:" id="XDg-YE-dH8">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                        <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="V7a-Ei-Dbd">
+                                            <rect key="frame" x="90" y="29" width="204" height="23"/>
+                                            <constraints>
+                                                <constraint firstAttribute="width" constant="200" id="TL9-WY-EbM"/>
+                                            </constraints>
+                                            <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="xhz-r8-sXZ">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                            </comboBoxCell>
+                                            <connections>
+                                                <action selector="comboBoxItemClick_PageSize:" target="-2" id="Wba-5w-30o"/>
+                                            </connections>
+                                        </comboBox>
+                                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Nyc-8R-qOb">
+                                            <rect key="frame" x="18" y="3" width="33" height="16"/>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Gap:" id="sQu-Ai-Hwl">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                        <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Cp6-0C-kLI">
+                                            <rect key="frame" x="54" y="0.0" width="50" height="21"/>
+                                            <constraints>
+                                                <constraint firstAttribute="width" constant="50" id="GON-5g-8vI"/>
+                                            </constraints>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="0" drawsBackground="YES" id="m1c-rH-6T7">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                        <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Edm-Zn-7sR">
+                                            <rect key="frame" x="101" y="-3" width="19" height="28"/>
+                                            <stepperCell key="cell" continuous="YES" alignment="left" increment="0.10000000000000001" maxValue="1000" doubleValue="1" id="QiQ-Ii-MfL"/>
+                                            <connections>
+                                                <action selector="stepperItemClick_Gap:" target="-2" id="GR6-UD-lfI"/>
+                                            </connections>
+                                        </stepper>
+                                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZPM-dH-KQV">
+                                            <rect key="frame" x="115" y="3" width="27" height="16"/>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="mm" id="WiA-nn-tTh">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                        <textField hidden="YES" focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iTC-o3-i7q">
+                                            <rect key="frame" x="291" y="33" width="27" height="16"/>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="mm" id="qbG-7z-daY">
+                                                <font key="font" metaFont="system"/>
+                                                <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                                <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                                            </textFieldCell>
+                                        </textField>
+                                    </subviews>
+                                    <constraints>
+                                        <constraint firstItem="Edm-Zn-7sR" firstAttribute="leading" secondItem="Cp6-0C-kLI" secondAttribute="trailing" id="2Wo-Qn-RJh"/>
+                                        <constraint firstItem="ZPM-dH-KQV" firstAttribute="centerY" secondItem="Edm-Zn-7sR" secondAttribute="centerY" id="8QG-Mm-Dbb"/>
+                                        <constraint firstItem="Cp6-0C-kLI" firstAttribute="top" secondItem="V7a-Ei-Dbd" secondAttribute="bottom" constant="10" id="NCg-jP-sYb"/>
+                                        <constraint firstItem="cM6-kD-ec2" firstAttribute="leading" secondItem="5yg-ty-rMO" secondAttribute="leading" constant="20" id="Osg-sR-i6i"/>
+                                        <constraint firstItem="ZPM-dH-KQV" firstAttribute="leading" secondItem="Edm-Zn-7sR" secondAttribute="trailing" id="PPa-j2-KjQ"/>
+                                        <constraint firstItem="Edm-Zn-7sR" firstAttribute="centerY" secondItem="Cp6-0C-kLI" secondAttribute="centerY" id="Pa2-ov-nW6"/>
+                                        <constraint firstItem="iTC-o3-i7q" firstAttribute="centerY" secondItem="V7a-Ei-Dbd" secondAttribute="centerY" id="Tdl-fu-mF5"/>
+                                        <constraint firstItem="Cp6-0C-kLI" firstAttribute="centerY" secondItem="Nyc-8R-qOb" secondAttribute="centerY" id="Tpg-r5-UBH"/>
+                                        <constraint firstItem="V7a-Ei-Dbd" firstAttribute="centerY" secondItem="cM6-kD-ec2" secondAttribute="centerY" id="UYn-yI-LJg"/>
+                                        <constraint firstItem="TbI-Vb-tNK" firstAttribute="leading" secondItem="5yg-ty-rMO" secondAttribute="leading" id="Wi2-ze-8Al"/>
+                                        <constraint firstItem="cM6-kD-ec2" firstAttribute="top" secondItem="TbI-Vb-tNK" secondAttribute="bottom" constant="10" id="Wp9-Gu-QJV"/>
+                                        <constraint firstAttribute="bottom" secondItem="Cp6-0C-kLI" secondAttribute="bottom" id="X4S-8z-pF3"/>
+                                        <constraint firstItem="TbI-Vb-tNK" firstAttribute="top" secondItem="5yg-ty-rMO" secondAttribute="top" id="eFA-6x-8au"/>
+                                        <constraint firstItem="V7a-Ei-Dbd" firstAttribute="leading" secondItem="cM6-kD-ec2" secondAttribute="trailing" constant="5" id="eij-ab-n3f"/>
+                                        <constraint firstItem="iTC-o3-i7q" firstAttribute="leading" secondItem="V7a-Ei-Dbd" secondAttribute="trailing" constant="2" id="faz-MU-vRg"/>
+                                        <constraint firstItem="Cp6-0C-kLI" firstAttribute="leading" secondItem="Nyc-8R-qOb" secondAttribute="trailing" constant="5" id="iYZ-Eb-YPH"/>
+                                        <constraint firstItem="Nyc-8R-qOb" firstAttribute="leading" secondItem="5yg-ty-rMO" secondAttribute="leading" constant="20" id="xrC-uW-cDU"/>
+                                    </constraints>
+                                </view>
+                            </box>
+                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ivv-Jx-DtL">
+                                <rect key="frame" x="860" y="149" width="75" height="32"/>
+                                <buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AML-js-IGv">
+                                    <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                                    <font key="font" metaFont="system"/>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="buttonItemClick_Add:" target="-2" id="c57-gn-vvz"/>
+                                </connections>
+                            </button>
+                        </subviews>
+                        <constraints>
+                            <constraint firstItem="KNR-nf-HXd" firstAttribute="top" secondItem="Tqy-vm-qC1" secondAttribute="top" constant="20" id="5j8-mt-tR1"/>
+                            <constraint firstItem="pGf-Iz-7zg" firstAttribute="centerY" secondItem="RBm-Bc-rao" secondAttribute="centerY" id="6lh-IN-JF6"/>
+                            <constraint firstItem="RBm-Bc-rao" firstAttribute="top" secondItem="z2n-2N-gFR" secondAttribute="bottom" constant="20" id="Bc9-v5-rty"/>
+                            <constraint firstItem="lzo-55-xro" firstAttribute="leading" secondItem="KNR-nf-HXd" secondAttribute="leading" id="BhK-R9-jeB"/>
+                            <constraint firstItem="ivv-Jx-DtL" firstAttribute="leading" secondItem="9as-I6-zpb" secondAttribute="trailing" constant="11" id="DRG-3o-0aZ"/>
+                            <constraint firstItem="z2n-2N-gFR" firstAttribute="top" secondItem="9as-I6-zpb" secondAttribute="bottom" constant="20" id="F1R-3w-84l"/>
+                            <constraint firstAttribute="trailing" secondItem="pGf-Iz-7zg" secondAttribute="trailing" constant="20" id="GVv-1D-s2a"/>
+                            <constraint firstItem="ivv-Jx-DtL" firstAttribute="centerY" secondItem="9as-I6-zpb" secondAttribute="centerY" id="IkZ-iF-gDn"/>
+                            <constraint firstItem="KNR-nf-HXd" firstAttribute="leading" secondItem="Tqy-vm-qC1" secondAttribute="leading" constant="20" id="KMH-n4-5WN"/>
+                            <constraint firstItem="Z7f-fU-KFb" firstAttribute="top" secondItem="KNR-nf-HXd" secondAttribute="bottom" constant="10" id="PdE-kI-gEE"/>
+                            <constraint firstItem="9as-I6-zpb" firstAttribute="leading" secondItem="Z7f-fU-KFb" secondAttribute="leading" id="Q2h-wB-8mx"/>
+                            <constraint firstItem="Z7f-fU-KFb" firstAttribute="leading" secondItem="Tqy-vm-qC1" secondAttribute="leading" constant="40" id="R62-8t-Hpm"/>
+                            <constraint firstItem="ivv-Jx-DtL" firstAttribute="trailing" secondItem="Z7f-fU-KFb" secondAttribute="trailing" id="ZPM-gn-CJZ"/>
+                            <constraint firstAttribute="trailing" secondItem="z2n-2N-gFR" secondAttribute="trailing" constant="20" id="Zg6-3l-bpT"/>
+                            <constraint firstAttribute="trailing" secondItem="Z7f-fU-KFb" secondAttribute="trailing" constant="20" id="dh4-4n-dZu"/>
+                            <constraint firstItem="pGf-Iz-7zg" firstAttribute="leading" secondItem="RBm-Bc-rao" secondAttribute="trailing" constant="20" id="hO6-Wy-1M5"/>
+                            <constraint firstItem="z2n-2N-gFR" firstAttribute="leading" secondItem="KNR-nf-HXd" secondAttribute="leading" id="jmG-cD-2jb"/>
+                            <constraint firstItem="9as-I6-zpb" firstAttribute="top" secondItem="lzo-55-xro" secondAttribute="bottom" constant="10" id="oOE-ND-STd"/>
+                            <constraint firstItem="lzo-55-xro" firstAttribute="top" secondItem="Z7f-fU-KFb" secondAttribute="bottom" constant="10" id="tQO-Sv-w71"/>
+                            <constraint firstAttribute="bottom" secondItem="pGf-Iz-7zg" secondAttribute="bottom" constant="20" id="xDy-1h-dx9"/>
+                        </constraints>
+                    </view>
+                </subviews>
+                <constraints>
+                    <constraint firstAttribute="bottom" secondItem="Tqy-vm-qC1" secondAttribute="bottom" id="FZb-2f-iKU"/>
+                    <constraint firstItem="Tqy-vm-qC1" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" id="HJs-Dc-n32"/>
+                    <constraint firstAttribute="trailing" secondItem="Tqy-vm-qC1" secondAttribute="trailing" id="Wkl-eP-uPd"/>
+                    <constraint firstItem="Tqy-vm-qC1" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" id="zlA-8P-S9H"/>
+                </constraints>
+            </view>
+            <connections>
+                <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
+            </connections>
+            <point key="canvasLocation" x="311" y="255.5"/>
+        </window>
+    </objects>
+</document>

+ 27 - 0
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController/Model/KMConvertURLToPDF.h

@@ -0,0 +1,27 @@
+//
+//  KMConvertURLToPDF.h
+//  PDF Reader
+//
+//  Created by 丁林圭 on 2019/3/11.
+//  Copyright © 2019年 Kdan Mobile. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface KMConvertURLToPDF : NSObject
+
+@property (nonatomic,retain) NSString * fileName;
+
++ (KMConvertURLToPDF *)shareInstance;
+
+- (void)convertUrlToPDF:(NSArray <NSURL *>*)urls
+                  toPath:(NSString *)toPath
+                  pageSize:(CGSize)pageSize
+                  gap:(CGFloat)gap
+                progress:(void (^)(CGFloat value))progress
+       completionHandler:(void (^) (NSArray *successArray,NSArray *failArray))handler;
+@end
+
+NS_ASSUME_NONNULL_END

+ 228 - 0
PDF Office/PDF Master/Class/Home/WindowController/KMURLToPDFWindowController/Model/KMConvertURLToPDF.m

@@ -0,0 +1,228 @@
+//
+//  KMConvertURLToPDF.m
+//  PDF Reader
+//
+//  Created by 丁林圭 on 2019/3/11.
+//  Copyright © 2019年 Kdan Mobile. All rights reserved.
+//
+
+#import "KMConvertURLToPDF.h"
+#import <WebKit/WebKit.h>
+#import <Quartz/Quartz.h>
+
+@interface KMConvertURLToPDF () <WebFrameLoadDelegate,WebResourceLoadDelegate>{
+    BOOL isProgressing;
+}
+
+@property (nonatomic,retain) NSString *savePath;
+@property (nonatomic,assign) NSInteger pageIndex;
+@property (nonatomic,retain) NSMutableArray * urls;
+@property (nonatomic,retain) NSMutableArray * failArray;
+@property (nonatomic,retain) NSMutableArray * successArray;
+@property (nonatomic,assign) CGSize pageSize;
+@property (nonatomic,assign) CGFloat gap;
+
+@property (nonatomic,retain) WebView *webView;
+
+@property (nonatomic,copy) void (^progress)(CGFloat value);
+@property (nonatomic,copy) void (^handler)(NSArray *successArray,NSArray *failArray);
+
+@end
+
+@implementation KMConvertURLToPDF
+
+
+-(void)dealloc {
+
+}
+
++ (KMConvertURLToPDF *)shareInstance
+{
+    static KMConvertURLToPDF *sharedConvertUrlToPDF = nil;
+    static dispatch_once_t predicate;
+    dispatch_once(&predicate, ^{
+        sharedConvertUrlToPDF = [[KMConvertURLToPDF alloc] init];
+    });
+    return sharedConvertUrlToPDF;
+}
+
+
+- (void)convertUrlToPDF:(NSArray <NSURL *>*)urls
+                 toPath:(NSString *)toPath
+               pageSize:(CGSize)pageSize
+                    gap:(CGFloat)gap
+               progress:(void (^)(CGFloat value))progress
+      completionHandler:(void (^) (NSArray *successArray,NSArray *failArray))handler
+{
+    self.urls = [NSMutableArray arrayWithArray:urls];
+    self.failArray = [NSMutableArray array];
+    self.successArray = [NSMutableArray array];
+    self.savePath = toPath;
+    self.progress = progress;
+    self.pageSize = pageSize;
+    self.gap = gap;
+    self.handler = handler;
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        self.pageIndex = 0;
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self convertFileAtPageIndex:self.pageIndex];
+        });
+    });
+}
+
+- (void)convertFileAtPageIndex:(NSInteger)pageIndex
+{
+    if (pageIndex >= self.urls.count) {
+        
+        if (self.handler) {
+            self.handler (self.successArray,self.failArray);
+            self.handler = nil;
+        }
+        return;
+    }
+    
+    NSURL *url = self.urls[pageIndex];
+    
+    if ([url.pathExtension.lowercaseString isEqualToString:@"pdf"]) {
+        NSData *urlData = [NSData dataWithContentsOfURL:url];
+        NSString *name = [NSString stringWithFormat:@"webpage%ld",self.pageIndex];
+        NSString *savePath = [self.savePath  stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",self.fileName?:name]];
+        
+        if ([urlData writeToFile:savePath atomically:YES]) {
+            [self.successArray addObject:savePath];
+            if (self.pageIndex + 1 >= self.urls.count) {
+                if (self.handler) {
+                    self.handler (self.successArray,self.failArray);
+                    self.handler= nil;
+                }
+            } else {
+                [self convertFileAtPageIndex:++self.pageIndex];
+                
+            }
+        } else {
+            [self.failArray addObject:self.urls[self.pageIndex]];
+            if (self.handler) {
+                self.handler (self.successArray,self.failArray);
+                self.handler= nil;
+            }
+        }
+    } else {
+       
+        if (!self.webView) {
+            _webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)];
+            WebPreferences *webPrefs = [[WebPreferences alloc] init];
+            [webPrefs setShouldPrintBackgrounds:YES];
+            [self.webView setPreferences:webPrefs];
+            [self.webView setFrameLoadDelegate:self];
+            [self.webView setResourceLoadDelegate:self];
+        }
+        [[self.webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
+    }
+
+    if (pageIndex != 0 && self.progress) {
+        self.progress((float)self.pageIndex/self.urls.count);
+    }
+}
+
+- (void)convertWebViewFrame:(WebFrame *)frame
+{
+    if (isProgressing) {
+        return;
+    }
+    isProgressing = YES;
+    
+    NSString *name = [NSString stringWithFormat:@"webpage%ld",self.pageIndex];
+    if (self.fileName.length != 0) {
+        name = self.fileName;
+    }
+    NSString *savePath = [self.savePath  stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",name]];
+    CGFloat margin = self.gap;
+    NSSize paperSize = self.pageSize;
+    WebFrameView *frameView = [frame frameView];
+    NSPrintInfo *sharedInfo = [NSPrintInfo sharedPrintInfo];
+    NSMutableDictionary *printInfoDict = [NSMutableDictionary dictionaryWithDictionary:[sharedInfo dictionary]];
+    [printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
+    [printInfoDict setObject:[NSURL fileURLWithPath:savePath] forKey:NSPrintJobSavingURL];
+    
+    NSPrintInfo *printInfo = [[NSPrintInfo alloc] initWithDictionary:printInfoDict];
+    [printInfo setHorizontalPagination:NSPrintingPaginationModeAutomatic];
+    [printInfo setVerticalPagination:NSPrintingPaginationModeAutomatic];
+    [printInfo setVerticallyCentered:NO];
+    if (!CGSizeEqualToSize(paperSize, CGSizeZero)) {
+        [printInfo setBottomMargin:margin];
+        [printInfo setTopMargin:margin];
+        [printInfo setLeftMargin:margin];
+        [printInfo setRightMargin:margin];
+        [printInfo setPaperSize:paperSize];
+    }
+    [printInfo setOrientation:NSPaperOrientationPortrait];
+    
+    NSPrintOperation *printOp = [frameView printOperationWithPrintInfo:printInfo];
+    [printOp setShowsPrintPanel:NO];
+    [printOp setShowsProgressPanel:NO];
+    
+    if ([printOp runOperation]) {
+        [self.successArray addObject:savePath];
+        
+        if (self.pageIndex + 1 >= self.urls.count) {
+            if (self.handler) {
+                self.handler (self.successArray,self.failArray);
+                self.handler= nil;
+            }
+        } else {
+            [self convertFileAtPageIndex:++self.pageIndex];
+        }
+    } else {
+        [self.failArray addObject:self.urls[self.pageIndex]];
+        if (self.handler) {
+            self.handler (self.successArray,self.failArray);
+            self.handler= nil;
+        }
+    }
+}
+
+#pragma mark - WebView Delegate Methods
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
+    if (frame == [sender mainFrame]) {
+        NSString *htmlTitle = @"document.title";
+        
+        if (!self.fileName) {
+            self.fileName = [sender stringByEvaluatingJavaScriptFromString:htmlTitle];
+            
+            if ([self.fileName length] < 1) {
+                self.fileName = sender.mainFrameTitle;
+            }
+            
+            if ([self.fileName length] < 1) {
+                self.fileName = @"Untitled";
+            }
+        }
+        
+        [self performSelector:@selector(convertWebViewFrame:) withObject:frame afterDelay:0.3];
+    }
+}
+
+- (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
+{
+    if([error code] == NSURLErrorCancelled)  {
+      return;
+    }
+
+    [self.failArray addObject:self.urls[self.pageIndex]];
+    if (self.handler) {
+        self.handler (self.successArray,self.failArray);
+        self.handler= nil;
+    }
+}
+
+- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
+{
+    [self.failArray addObject:self.urls[self.pageIndex]];
+    if (self.handler) {
+        self.handler (self.successArray,self.failArray);
+        self.handler= nil;
+    }
+}
+
+@end

+ 2 - 0
PDF Office/PDF Master/PDF_Master DMG-Bridging-Header.h

@@ -61,3 +61,5 @@
 #import "SKLocalization.h"
 #import "NSImage+PDFListView.h"
 #import "KMColorPickerViewController.h"
+
+#import "KMConvertURLToPDF.h"

+ 2 - 0
PDF Office/PDF Master/PDF_Master Pro-Bridging-Header.h

@@ -42,3 +42,5 @@
 #import "NSImage+PDFListView.h"
 
 #import "KMColorPickerViewController.h"
+
+#import "KMConvertURLToPDF.h"

+ 2 - 0
PDF Office/PDF Master/PDF_Master-Bridging-Header.h

@@ -53,3 +53,5 @@
 #import "SKLocalization.h"
 #import "NSImage+PDFListView.h"
 #import "KMColorPickerViewController.h"
+
+#import "KMConvertURLToPDF.h"