|
@@ -78,6 +78,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
case .pageEdit:
|
|
|
self.enterViewerMode()
|
|
|
self.enterPDFPageEdit()
|
|
|
+
|
|
|
case .signature:
|
|
|
enterSignatureMode()
|
|
|
default:
|
|
@@ -89,6 +90,8 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(signatureTrustCerDidChangeNotification(_:)), name: CSignatureTrustCerDidChangeNotification, object: nil)
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(PDFPageDidRemoveAnnotationNotification), name: NSNotification.Name.CPDFPageDidRemoveAnnotation, object: nil)
|
|
|
+
|
|
|
+ self.pdfListView?.performDelegate = self
|
|
|
}
|
|
|
|
|
|
func initAnnotationBar() {
|
|
@@ -162,10 +165,9 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
|
|
|
if self.popMenu?.superview != nil {
|
|
|
if #available(iOS 11.0, *) {
|
|
|
- self.popMenu?.showMenu(in: CGRect(x: self.view.frame.size.width - self.view.safeAreaInsets.right - 250, y: self.navigationController?.navigationBar.frame.maxY ?? 0, width: 250, height: 250))
|
|
|
+ self.popMenu?.showMenu(in: CGRect(x: self.view.frame.size.width - self.view.safeAreaInsets.right - 250, y: (self.navigationController?.navigationBar.frame)!.maxY, width: 250, height: CGFloat((self.configuration?.showMoreItems.count ?? 0) * 50)))
|
|
|
} else {
|
|
|
- // Fallback on earlier versions
|
|
|
- self.popMenu?.showMenu(in: CGRect(x: self.view.frame.size.width - 250, y: self.navigationController?.navigationBar.frame.maxY ?? 0, width: 250, height: 250))
|
|
|
+ self.popMenu?.showMenu(in: CGRect(x: self.view.frame.size.width - 250, y: (self.navigationController?.navigationBar.frame)!.maxY, width: 250, height: CGFloat((self.configuration?.showMoreItems.count ?? 0) * 50)))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -234,12 +236,12 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
// MARK: - Public Methods
|
|
|
|
|
|
override func selectDocumentRefresh() {
|
|
|
- if self.pdfListView?.toolModel == .annotation {
|
|
|
+ if self.functionTypeState == .annotation {
|
|
|
self.pdfListView?.setAnnotationMode(.CPDFViewAnnotationModenone)
|
|
|
self.annotationBar?.updatePropertiesButtonState()
|
|
|
self.annotationBar?.reloadData()
|
|
|
self.annotationBar?.updateUndoRedoState()
|
|
|
- } else if self.pdfListView?.toolModel == .form {
|
|
|
+ } else if self.functionTypeState == .form {
|
|
|
self.formBar?.initUndoRedo()
|
|
|
}
|
|
|
}
|
|
@@ -274,34 +276,6 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
} else {
|
|
|
self.pdfListView?.document = document
|
|
|
|
|
|
- if (self.digitalSignatureBar?.superview) != nil {
|
|
|
- if let signatures = self.pdfListView?.document.signatures() {
|
|
|
- for signature in signatures {
|
|
|
- if let signatureWidgetAnnotation = signature.signatureWidgetAnnotation(with: self.pdfListView?.document), signatureWidgetAnnotation.page == nil {
|
|
|
- self.pdfListView?.document.removeSignature(signature)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.digitalSignatureBar?.updateStatusWith(signatures: signatures)
|
|
|
-
|
|
|
- completion(true)
|
|
|
-
|
|
|
- if (self.signtureViewController.view.superview) != nil {
|
|
|
- let signatures = self.pdfListView?.document.signatures() ?? []
|
|
|
- var mSignatures: [CPDFSignature] = []
|
|
|
-
|
|
|
- for sign in signatures {
|
|
|
- if sign.signers.count > 0 {
|
|
|
- mSignatures.append(sign)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.signatures = mSignatures
|
|
|
- self.verifySignature()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
completion(true)
|
|
|
}
|
|
|
}
|
|
@@ -313,6 +287,8 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
// MARK: - Private Methods
|
|
|
|
|
|
func enterEditMode() {
|
|
|
+ self.functionTypeState = .edit
|
|
|
+
|
|
|
self.selectDocumentRefresh()
|
|
|
|
|
|
self.toolBar?.isHidden = false
|
|
@@ -349,6 +325,8 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
func enterAnnotationMode() {
|
|
|
+ self.functionTypeState = .annotation
|
|
|
+
|
|
|
self.toolBar?.isHidden = true
|
|
|
self.annotationBar?.isHidden = false
|
|
|
self.formBar?.isHidden = true
|
|
@@ -392,6 +370,8 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
func enterViewerMode() {
|
|
|
+ self.functionTypeState = .viewer
|
|
|
+
|
|
|
self.toolBar?.isHidden = true
|
|
|
self.formBar?.isHidden = true
|
|
|
self.annotationBar?.isHidden = true
|
|
@@ -434,6 +414,8 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
func enterFormMode() {
|
|
|
+ self.functionTypeState = .form
|
|
|
+
|
|
|
self.toolBar?.isHidden = true
|
|
|
self.annotationBar?.isHidden = true
|
|
|
self.formBar?.isHidden = false
|
|
@@ -476,11 +458,24 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
func enterSignatureMode() {
|
|
|
+ self.functionTypeState = .signature
|
|
|
+
|
|
|
self.toolBar?.isHidden = true
|
|
|
self.formBar?.isHidden = true
|
|
|
self.annotationBar?.isHidden = true
|
|
|
self.digitalSignatureBar?.isHidden = false
|
|
|
|
|
|
+ if pdfListView?.isEdited() == true {
|
|
|
+ DispatchQueue.global(qos: .default).async {
|
|
|
+ self.pdfListView?.commitEditing()
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.pdfListView?.endOfEditing()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.pdfListView?.endOfEditing()
|
|
|
+ }
|
|
|
+
|
|
|
if isSelctSignature {
|
|
|
pdfListView?.setToolModel(.form)
|
|
|
} else {
|
|
@@ -491,7 +486,11 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
view.addSubview(digitalSignatureBar!)
|
|
|
}
|
|
|
|
|
|
- navigationTitle = NSLocalizedString("Digital Signature", comment: "")
|
|
|
+ if self.digitalSignatureBar?.superview != nil {
|
|
|
+ self.digitalSignatureBar?.updateStatusWith(signatures: self.signatures)
|
|
|
+ }
|
|
|
+
|
|
|
+ navigationTitle = NSLocalizedString("Signatures", comment: "")
|
|
|
titleButton?.setTitle(navigationTitle as String?, for: .normal)
|
|
|
|
|
|
var tPosY: CGFloat = 0
|
|
@@ -524,14 +523,16 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
override func setTitleRefresh() {
|
|
|
- if self.pdfListView?.toolModel == .edit {
|
|
|
+ if self.functionTypeState == .edit {
|
|
|
self.enterEditMode()
|
|
|
- } else if self.pdfListView?.toolModel == .viewer {
|
|
|
+ } else if self.functionTypeState == .viewer {
|
|
|
self.enterViewerMode()
|
|
|
- } else if self.pdfListView?.toolModel == .annotation {
|
|
|
+ } else if self.functionTypeState == .annotation {
|
|
|
self.enterAnnotationMode()
|
|
|
- } else if self.pdfListView?.toolModel == .form {
|
|
|
+ } else if self.functionTypeState == .form {
|
|
|
self.enterFormMode()
|
|
|
+ } else if self.functionTypeState == .signature {
|
|
|
+ self.enterSignatureMode()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -543,22 +544,15 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
}
|
|
|
|
|
|
func writeSignatureToWidget(_ widget: CPDFSignatureWidgetAnnotation, PKCS12Cert path: String, password: String, config: CPDFSignatureConfig, lockDocument isLock: Bool) {
|
|
|
- let homePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
|
- let writeDirectoryPath = homePath.appendingPathComponent("Signature")
|
|
|
-
|
|
|
- do {
|
|
|
- try FileManager.default.createDirectory(at: writeDirectoryPath, withIntermediateDirectories: true, attributes: nil)
|
|
|
- } catch {
|
|
|
- print("Error creating directory: \(error)")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+ let writeDirectoryPath = SIGNATURESFOLDER
|
|
|
+
|
|
|
let documentURL = self.pdfListView?.document.documentURL
|
|
|
let documentName = documentURL?.lastPathComponent.components(separatedBy: ".").first ?? ""
|
|
|
- let writeFilePath = writeDirectoryPath.appendingPathComponent("\(documentName)_Widget_\(tagString()).pdf")
|
|
|
+ let writeFilePath = writeDirectoryPath + "/" + "\(documentName)_Widget_\(tagString()).pdf"
|
|
|
|
|
|
- if FileManager.default.fileExists(atPath: writeFilePath.path) {
|
|
|
- try? FileManager.default.removeItem(at: writeFilePath)
|
|
|
+
|
|
|
+ if FileManager.default.fileExists(atPath: writeFilePath) {
|
|
|
+ try? FileManager.default.removeItem(at: URL(fileURLWithPath: writeFilePath))
|
|
|
}
|
|
|
|
|
|
var locationStr = ""
|
|
@@ -574,12 +568,12 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
|
|
|
let permissions: CPDFSignaturePermissions = isLock ? .forbidChange : .none
|
|
|
|
|
|
- let isSuccess = self.pdfListView?.document.writeSignature(to: writeFilePath, withWidget: widget, pkcs12Cert: path, password: password, location: locationStr, reason: reasonStr, permissions: permissions) ?? false
|
|
|
+ let isSuccess = self.pdfListView?.document.writeSignature(to: URL(fileURLWithPath: writeFilePath), withWidget: widget, pkcs12Cert: path, password: password, location: locationStr, reason: reasonStr, permissions: permissions) ?? false
|
|
|
|
|
|
if isSuccess {
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
- if FileManager.default.fileExists(atPath: writeFilePath.path) {
|
|
|
- self.reloadDocument(withFilePath: writeFilePath.path, password: nil, completion: { result in
|
|
|
+ if FileManager.default.fileExists(atPath: writeFilePath) {
|
|
|
+ self.reloadDocument(withFilePath: writeFilePath, password: nil, completion: { result in
|
|
|
// Handle the completion as needed
|
|
|
})
|
|
|
}
|
|
@@ -735,8 +729,13 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
super.pdfViewDocumentDidLoaded(pdfView)
|
|
|
|
|
|
if self.digitalSignatureBar?.superview != nil {
|
|
|
- self.digitalSignatureBar?.updateStatusWith(signatures: self.signatures ?? [])
|
|
|
+ self.digitalSignatureBar?.updateStatusWith(signatures: self.signatures)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.signtureViewController.view.superview != nil {
|
|
|
+ verifySignature()
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -961,7 +960,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
} else if self.pdfListView?.toolModel == .viewer {
|
|
|
self.signatureAnnotation = annotation
|
|
|
|
|
|
- if let annotationSignature = annotation.signature(), annotationSignature.signers.count > 0 {
|
|
|
+ if let annotationSignature = annotation.signature(), let signers = annotationSignature.signers, signers.count > 0 {
|
|
|
let vc = CPDFSigntureVerifyDetailsViewController()
|
|
|
let nav = CNavigationController(rootViewController: vc)
|
|
|
vc.signature = annotationSignature
|
|
@@ -970,6 +969,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
if (digitalSignatureBar?.superview) != nil {
|
|
|
signatureAnnotation = annotation
|
|
|
let signatureTypeSelectView = CSignatureTypeSelectView(frame: view.frame, height: 216.0)
|
|
|
+ signatureTypeSelectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
signatureTypeSelectView.delegate = self
|
|
|
signatureTypeSelectView.showinView(view)
|
|
|
} else {
|
|
@@ -1161,13 +1161,22 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
if let signatures = pdfListView?.document.signatures() {
|
|
|
var mSignatures = [CPDFSignature]()
|
|
|
for sign in signatures {
|
|
|
- mSignatures.append(sign)
|
|
|
+ if sign.signers.count > 0 {
|
|
|
+ mSignatures.append(sign)
|
|
|
+ }
|
|
|
}
|
|
|
self.signatures = mSignatures
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- verifySignature()
|
|
|
+ if self.digitalSignatureBar?.superview != nil {
|
|
|
+ self.digitalSignatureBar?.updateStatusWith(signatures: self.signatures)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.signtureViewController.view.superview != nil {
|
|
|
+ verifySignature()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@objc func signatureTrustCerDidChangeNotification(_ notification: Notification) {
|
|
@@ -1175,12 +1184,20 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
if let signatures = pdfListView?.document.signatures() {
|
|
|
var mSignatures = [CPDFSignature]()
|
|
|
for sign in signatures {
|
|
|
- mSignatures.append(sign)
|
|
|
+ if sign.signers.count > 0 {
|
|
|
+ mSignatures.append(sign)
|
|
|
+ }
|
|
|
}
|
|
|
self.signatures = mSignatures
|
|
|
}
|
|
|
- verifySignature()
|
|
|
|
|
|
+ if self.digitalSignatureBar?.superview != nil {
|
|
|
+ self.digitalSignatureBar?.updateStatusWith(signatures: self.signatures)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.signtureViewController.view.superview != nil {
|
|
|
+ verifySignature()
|
|
|
+ }
|
|
|
if let signtureVerifyViewController = self.signtureVerifyViewController {
|
|
|
signtureVerifyViewController.signatures = signatures ?? []
|
|
|
signtureVerifyViewController.PDFListView = pdfListView
|
|
@@ -1323,42 +1340,37 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
if fileUrlAuthozied {
|
|
|
if self.pdfListView!.isEditing() == true {
|
|
|
DispatchQueue.global(qos: .default).async {
|
|
|
- if self.pdfListView!.isEdited() == true {
|
|
|
- self.pdfListView!.commitEditing()
|
|
|
+ if self.pdfListView?.isEdited() == true {
|
|
|
+ self.pdfListView?.commitEditing()
|
|
|
}
|
|
|
DispatchQueue.main.async {
|
|
|
- self.pdfListView!.endOfEditing()
|
|
|
+ self.pdfListView?.endOfEditing()
|
|
|
DispatchQueue.global(qos: .default).async {
|
|
|
- if self.pdfListView!.document.isModified() {
|
|
|
- self.pdfListView!.document.write(to: self.pdfListView!.document.documentURL)
|
|
|
+ if self.pdfListView?.document.isModified() == true {
|
|
|
+ self.pdfListView?.document.write(to: self.pdfListView!.document.documentURL)
|
|
|
}
|
|
|
DispatchQueue.main.async {
|
|
|
self.openFile(with: urls)
|
|
|
|
|
|
- if let signtureViewControllerSuperview = self.signtureViewController.view.superview {
|
|
|
- signtureViewControllerSuperview.removeFromSuperview()
|
|
|
+ if self.signtureViewController.view.superview != nil {
|
|
|
+ self.signtureViewController.view.removeFromSuperview()
|
|
|
}
|
|
|
|
|
|
- let signatures = self.pdfListView?.document.signatures() ?? []
|
|
|
- self.digitalSignatureBar?.updateStatusWith(signatures: signatures)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
DispatchQueue.global(qos: .default).async {
|
|
|
- if self.pdfListView!.document.isModified() == true {
|
|
|
- self.pdfListView!.document.write(to: self.pdfListView!.document.documentURL)
|
|
|
+ if self.pdfListView?.document.isModified() == true {
|
|
|
+ self.pdfListView?.document.write(to: self.pdfListView!.document.documentURL)
|
|
|
}
|
|
|
DispatchQueue.main.async {
|
|
|
self.openFile(with: urls)
|
|
|
|
|
|
- if let signtureViewControllerSuperview = self.signtureViewController.view.superview {
|
|
|
- signtureViewControllerSuperview.removeFromSuperview()
|
|
|
+ if self.signtureViewController.view.superview != nil {
|
|
|
+ self.signtureViewController.view.removeFromSuperview()
|
|
|
}
|
|
|
-
|
|
|
- let signatures = self.pdfListView?.document.signatures() ?? []
|
|
|
- self.digitalSignatureBar?.updateStatusWith(signatures: signatures)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1391,7 +1403,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
|
|
|
func importCertificateViewControllerSave(_ importCertificateViewController: CImportCertificateViewController, PKCS12Cert path: String, password: String, config: CPDFSignatureConfig) {
|
|
|
self.dismiss(animated: false)
|
|
|
- writeSignatureToWidget(self.signatureAnnotation ?? CPDFSignatureWidgetAnnotation(), PKCS12Cert: path, password: password, config: config, lockDocument: pdfListView?.document.isLocked ?? false)
|
|
|
+ writeSignatureToWidget(self.signatureAnnotation ?? CPDFSignatureWidgetAnnotation(), PKCS12Cert: path, password: password, config: config, lockDocument: true)
|
|
|
}
|
|
|
|
|
|
func importCertificateViewControllerCancel(_ importCertificateViewController: CImportCertificateViewController) {
|
|
@@ -1401,6 +1413,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
pdfListView?.setNeedsDisplayFor(self.signatureAnnotation?.page)
|
|
|
|
|
|
let signatureTypeSelectView = CSignatureTypeSelectView(frame: view.frame, height: 216.0)
|
|
|
+ signatureTypeSelectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
signatureTypeSelectView.delegate = self
|
|
|
signatureTypeSelectView.showinView(view)
|
|
|
}
|
|
@@ -1414,6 +1427,7 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
pdfListView?.setNeedsDisplayFor(self.signatureAnnotation?.page)
|
|
|
|
|
|
let signatureTypeSelectView = CSignatureTypeSelectView(frame: view.frame, height: 216.0)
|
|
|
+ signatureTypeSelectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
signatureTypeSelectView.delegate = self
|
|
|
signatureTypeSelectView.showinView(view)
|
|
|
}
|
|
@@ -1421,11 +1435,12 @@ class CPDFViewController: CPDFViewBaseController,CPDFFormBarDelegate,CPDFSoundPl
|
|
|
func createCertificateInfoViewControllerSave(_ createCertificateInfoViewController: CCreateCertificateInfoViewController, PKCS12Cert path: String, password: String, config: CPDFSignatureConfig) {
|
|
|
pdfListView?.setNeedsDisplayFor(self.signatureAnnotation?.page)
|
|
|
self.dismiss(animated: false)
|
|
|
- writeSignatureToWidget(self.signatureAnnotation ?? CPDFSignatureWidgetAnnotation(), PKCS12Cert: path, password: password, config: config, lockDocument: pdfListView?.document.isLocked ?? false)
|
|
|
+ writeSignatureToWidget(self.signatureAnnotation ?? CPDFSignatureWidgetAnnotation(), PKCS12Cert: path, password: password, config: config, lockDocument: true)
|
|
|
}
|
|
|
|
|
|
func verifySignature() {
|
|
|
- let signatures = self.pdfListView?.document.signatures() ?? []
|
|
|
+ let signatures = self.signatures ?? []
|
|
|
+
|
|
|
if signatures.count > 0 {
|
|
|
self.navigationController?.view.isUserInteractionEnabled = false
|
|
|
|