|
@@ -95,10 +95,11 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
|
|
|
var indexSet = IndexSet()
|
|
|
for page in pages {
|
|
|
- indexSet.insert(IndexSet.Element(page+1))
|
|
|
+ indexSet.insert(IndexSet.Element(page))
|
|
|
}
|
|
|
|
|
|
let success = pdfListView.document.importPages(indexSet, from: document, at: _index)
|
|
|
+ pdfListView.layoutDocumentView()
|
|
|
|
|
|
return success
|
|
|
} else {
|
|
@@ -106,7 +107,7 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func extractPDFDocument(_ savePath: String, Pages pages: [Int]) -> Bool {
|
|
|
+ func extractPDFDocument(_ savePath: URL, Pages pages: [Int]) -> Bool {
|
|
|
if let pdfListView = self.pdfViewController?.pdfListView {
|
|
|
var indexSet = IndexSet()
|
|
|
for page in pages {
|
|
@@ -116,7 +117,7 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
let document = CPDFDocument()
|
|
|
document?.importPages(indexSet, from: pdfListView.document, at: 0)
|
|
|
|
|
|
- let success = document?.write(to: URL(fileURLWithPath: savePath), isSaveFontSubset: true) ?? false
|
|
|
+ let success = document?.write(to: savePath, isSaveFontSubset: true) ?? false
|
|
|
|
|
|
return success
|
|
|
} else {
|
|
@@ -687,14 +688,10 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func flattenAllPages(info : NSDictionary, completionHandler: @escaping (Bool) -> Void) {
|
|
|
+ func flattenAllPages(savePath: URL, fontSubset: Bool, completionHandler: @escaping (Bool) -> Void) {
|
|
|
if let pdfListView = self.pdfViewController?.pdfListView {
|
|
|
- let _info = info as? [String: Any]
|
|
|
-
|
|
|
- let savePath: String = self.getValue(from: _info, key: "save_path", defaultValue: "")
|
|
|
- let fontSubset: Bool = self.getValue(from: _info, key: "font_sub_set", defaultValue: true)
|
|
|
|
|
|
- let success = pdfListView.document.writeFlatten(to: URL(fileURLWithPath: savePath), isSaveFontSubset: fontSubset)
|
|
|
+ let success = pdfListView.document.writeFlatten(to: savePath, isSaveFontSubset: fontSubset)
|
|
|
|
|
|
completionHandler(success)
|
|
|
} else {
|
|
@@ -702,19 +699,14 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func saveAs(info : NSDictionary, completionHandler: @escaping (Bool) -> Void) {
|
|
|
+ func saveAs(savePath: URL, removeSecurity: Bool, fontSubset: Bool, completionHandler: @escaping (Bool) -> Void) {
|
|
|
if let pdfListView = self.pdfViewController?.pdfListView {
|
|
|
- let _info = info as? [String: Any]
|
|
|
-
|
|
|
- let savePath: String = self.getValue(from: _info, key: "save_path", defaultValue: "")
|
|
|
- let fontSubset: Bool = self.getValue(from: _info, key: "font_sub_set", defaultValue: true)
|
|
|
- let removeSecurity: Bool = self.getValue(from: _info, key: "remove_security", defaultValue: true)
|
|
|
-
|
|
|
+
|
|
|
var success: Bool = false
|
|
|
if removeSecurity {
|
|
|
- pdfListView.document.writeDecrypt(to: URL(fileURLWithPath: savePath), isSaveFontSubset: fontSubset)
|
|
|
+ success = pdfListView.document.writeDecrypt(to: savePath, isSaveFontSubset: fontSubset)
|
|
|
} else {
|
|
|
- pdfListView.document.write(to: URL(fileURLWithPath: savePath), isSaveFontSubset: fontSubset)
|
|
|
+ success = pdfListView.document.write(to: savePath, isSaveFontSubset: fontSubset)
|
|
|
}
|
|
|
completionHandler(success)
|
|
|
} else {
|
|
@@ -728,7 +720,8 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
|
|
|
let password: String = self.getValue(from: _info, key: "password", defaultValue: "")
|
|
|
let pages: [Int] = self.getValue(from: _info, key: "pages", defaultValue: [])
|
|
|
- let insert_position: UInt = self.getValue(from: _info, key: "insert_position", defaultValue: 0)
|
|
|
+ let insert_position: Int = self.getValue(from: _info, key: "insert_position", defaultValue: 0)
|
|
|
+
|
|
|
|
|
|
let _document = CPDFDocument(url: filePath)
|
|
|
|
|
@@ -736,19 +729,15 @@ class RCTCPDFView: UIView, CPDFViewBaseControllerDelete {
|
|
|
_document?.unlock(withPassword: password)
|
|
|
}
|
|
|
|
|
|
- let success = self.insertPDFDocument(_document!, Pages: pages, Position: insert_position)
|
|
|
+ let success = self.insertPDFDocument(_document!, Pages: pages, Position: UInt(insert_position))
|
|
|
completionHandler(success)
|
|
|
} else {
|
|
|
completionHandler(false)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func splitDocumentPages(info : NSDictionary, completionHandler: @escaping (Bool) -> Void) {
|
|
|
+ func splitDocumentPages(savePath: URL, pages: [Int], completionHandler: @escaping (Bool) -> Void) {
|
|
|
if let pdfListView = self.pdfViewController?.pdfListView {
|
|
|
- let _info = info as? [String: Any]
|
|
|
-
|
|
|
- let savePath: String = self.getValue(from: _info, key: "save_path", defaultValue: "")
|
|
|
- let pages: [Int] = self.getValue(from: _info, key: "pages", defaultValue: [])
|
|
|
|
|
|
let success = self.extractPDFDocument(savePath, Pages: pages)
|
|
|
|