|
@@ -27,7 +27,7 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
|
|
|
func getAnnotations() -> [Dictionary<String, Any>] {
|
|
|
var annotaionDicts:[Dictionary<String, Any>] = []
|
|
|
-
|
|
|
+
|
|
|
let annoations = page?.annotations ?? []
|
|
|
|
|
|
for annoation in annoations {
|
|
@@ -42,7 +42,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Highlight", "Squiggly", "Underline", "Strikeout":
|
|
|
if let markupAnnotation = annoation as? CPDFMarkupAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(markupAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = markupAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -51,7 +53,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Circle":
|
|
|
if let circleAnnotation = annoation as? CPDFCircleAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(circleAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = circleAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -60,7 +64,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Square":
|
|
|
if let squareAnnotation = annoation as? CPDFSquareAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(squareAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = squareAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -69,7 +75,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Line", "Arrow":
|
|
|
if let lineAnnotation = annoation as? CPDFLineAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(lineAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = lineAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -77,6 +85,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
}
|
|
|
case "Freehand":
|
|
|
if let inkAnnotation = annoation as? CPDFInkAnnotation {
|
|
|
+ let memory = getMemoryAddress(inkAnnotation)
|
|
|
+
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = "ink"
|
|
|
annotaionDict["title"] = inkAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -86,7 +97,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Note":
|
|
|
if let noteAnnotation = annoation as? CPDFTextAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(noteAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = noteAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -95,6 +108,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
|
|
|
case "FreeText":
|
|
|
if let freeTextAnnotation = annoation as? CPDFFreeTextAnnotation {
|
|
|
+ let memory = getMemoryAddress(freeTextAnnotation)
|
|
|
+
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = "freetext"
|
|
|
annotaionDict["title"] = freeTextAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -104,7 +120,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Stamp", "Image":
|
|
|
if let stampAnnotation = annoation as? CPDFStampAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
-
|
|
|
+ let memory = getMemoryAddress(stampAnnotation)
|
|
|
+
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
if type == "Image" {
|
|
|
annotaionDict["type"] = "pictures"
|
|
@@ -117,7 +135,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "Link":
|
|
|
if let linkAnnotation = annoation as? CPDFLinkAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: type)
|
|
|
+ let memory = getMemoryAddress(linkAnnotation)
|
|
|
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = lowertype
|
|
|
annotaionDict["title"] = linkAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -126,6 +146,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
|
|
|
case "Media":
|
|
|
if let mediaAnnotation = annoation as? CPDFSoundAnnotation {
|
|
|
+ let memory = getMemoryAddress(mediaAnnotation)
|
|
|
+
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = "sound"
|
|
|
annotaionDict["title"] = mediaAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -133,6 +156,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
}
|
|
|
case "":
|
|
|
if let signatureAnnotation = annoation as? CPDFSignatureAnnotation {
|
|
|
+ let memory = getMemoryAddress(signatureAnnotation)
|
|
|
+
|
|
|
+ annotaionDict["uuid"] = memory
|
|
|
annotaionDict["type"] = "signature"
|
|
|
annotaionDict["title"] = signatureAnnotation.userName()
|
|
|
annotaionDict["page"] = pageIndex
|
|
@@ -153,7 +179,7 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
|
|
|
func getForms() -> [Dictionary<String, Any>] {
|
|
|
var formDicts:[Dictionary<String, Any>] = []
|
|
|
-
|
|
|
+
|
|
|
let forms = page?.annotations ?? []
|
|
|
|
|
|
for form in forms {
|
|
@@ -168,7 +194,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "CheckBox", "RadioButton", "PushButton":
|
|
|
if let buttonWidget = form as? CPDFButtonWidgetAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: widgetType)
|
|
|
+ let memory = getMemoryAddress(buttonWidget)
|
|
|
|
|
|
+ formDict["uuid"] = memory
|
|
|
formDict["type"] = lowertype
|
|
|
formDict["title"] = buttonWidget.fieldName()
|
|
|
formDict["page"] = pageIndex
|
|
@@ -185,7 +213,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "TextField":
|
|
|
if let textFieldWidget = form as? CPDFTextWidgetAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: widgetType)
|
|
|
+ let memory = getMemoryAddress(textFieldWidget)
|
|
|
|
|
|
+ formDict["uuid"] = memory
|
|
|
formDict["type"] = lowertype
|
|
|
formDict["title"] = textFieldWidget.fieldName()
|
|
|
formDict["page"] = pageIndex
|
|
@@ -195,7 +225,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
case "ListBox", "ComboBox":
|
|
|
if let choiceWidget = form as? CPDFChoiceWidgetAnnotation {
|
|
|
let lowertype = lowercaseFirstLetter(of: widgetType)
|
|
|
+ let memory = getMemoryAddress(choiceWidget)
|
|
|
|
|
|
+ formDict["uuid"] = memory
|
|
|
formDict["type"] = lowertype
|
|
|
formDict["title"] = choiceWidget.fieldName()
|
|
|
formDict["page"] = pageIndex
|
|
@@ -203,6 +235,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
|
|
|
case "SignatureFields":
|
|
|
if let signatureWidget = form as? CPDFSignatureWidgetAnnotation {
|
|
|
+ let memory = getMemoryAddress(signatureWidget)
|
|
|
+
|
|
|
+ formDict["uuid"] = memory
|
|
|
formDict["type"] = "signaturesFields"
|
|
|
formDict["title"] = signatureWidget.fieldName()
|
|
|
formDict["page"] = pageIndex
|
|
@@ -216,12 +251,95 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return formDicts
|
|
|
}
|
|
|
|
|
|
+ func setWidgetIsChecked(uuid: String, isChecked: Bool) {
|
|
|
+ if let widget = self.getForm(formUUID: uuid) {
|
|
|
+ if let buttonWidget = widget as? CPDFButtonWidgetAnnotation {
|
|
|
+ buttonWidget.setState(isChecked ? 1 : 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func setTextWidgetText(uuid: String, text: String) {
|
|
|
+ if let widget = self.getForm(formUUID: uuid) {
|
|
|
+ if let textFieldWidget = widget as? CPDFTextWidgetAnnotation {
|
|
|
+ textFieldWidget.stringValue = text
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func addWidgetImageSignature(uuid: String, imagePath: URL, completionHandler: @escaping (Bool) -> Void) {
|
|
|
+ if let widget = self.getForm(formUUID: uuid) {
|
|
|
+ if let signatureWidget = widget as? CPDFSignatureWidgetAnnotation {
|
|
|
+ let image = UIImage(contentsOfFile: imagePath.path)
|
|
|
+ signatureWidget.sign(with: image)
|
|
|
+ completionHandler(true)
|
|
|
+ }
|
|
|
+ } else if let annotation = self.getAnnotation(formUUID: uuid) {
|
|
|
+ if let signatureAnnotation = annotation as? CPDFSignatureAnnotation {
|
|
|
+ let image = UIImage(contentsOfFile: imagePath.path)
|
|
|
+ signatureAnnotation.setImage(image)
|
|
|
+ completionHandler(true)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ completionHandler(false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateAp(uuid: String) {
|
|
|
+ if let widget = self.getForm(formUUID: uuid) {
|
|
|
+ widget.updateAppearanceStream()
|
|
|
+ } else if let annotation = self.getAnnotation(formUUID: uuid) {
|
|
|
+ annotation.updateAppearanceStream()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//MARK: - Private Methods
|
|
|
|
|
|
+
|
|
|
+ func getAnnotation(formUUID uuid: String) -> CPDFAnnotation? {
|
|
|
+ let annoations = page?.annotations ?? []
|
|
|
+
|
|
|
+ for annoation in annoations {
|
|
|
+ let type: String = annoation.type
|
|
|
+ if annoation.type == "Widget" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ let _uuid = getMemoryAddress(annoation)
|
|
|
+
|
|
|
+ if _uuid == uuid {
|
|
|
+ return annoation
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ func getForm(formUUID uuid: String) -> CPDFWidgetAnnotation? {
|
|
|
+ let annoations = page?.annotations ?? []
|
|
|
+
|
|
|
+ for annoation in annoations {
|
|
|
+ let type: String = annoation.type
|
|
|
+ if annoation.type == "Widget" {
|
|
|
+ if let widgetAnnotation = annoation as? CPDFWidgetAnnotation {
|
|
|
+
|
|
|
+ let _uuid = getMemoryAddress(annoation)
|
|
|
+
|
|
|
+ if _uuid == uuid {
|
|
|
+ return widgetAnnotation
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
func lowercaseFirstLetter(of string: String) -> String {
|
|
|
guard !string.isEmpty else { return string }
|
|
|
|
|
@@ -230,4 +348,9 @@ class RCTCPDFPageUtil: NSObject {
|
|
|
return lowercaseString
|
|
|
}
|
|
|
|
|
|
+ func getMemoryAddress<T: AnyObject>(_ object: T) -> String {
|
|
|
+ let pointer = Unmanaged.passUnretained(object).toOpaque()
|
|
|
+ return String(describing: pointer)
|
|
|
+ }
|
|
|
+
|
|
|
}
|