Posts

Post not yet marked as solved
3 Replies
3.1k Views
Hi,In all Apple documentation I can't find how to disable editing a pdf annotation.I have a pdf document with annotations (acrofield) as textbox, checkbox and radio button.I want to disable editing all of this annotations when, for example I press a button.I dont know how do this. There is no information in the documentation.Edit:Set annotation property to isReadOnly = true doesnt work
Posted
by One Puty.
Last updated
.
Post not yet marked as solved
2 Replies
851 Views
I use PDFKit in iOS as PDF renderer and I have problem with background color in radio button.I iterate all PDF annotations on all pages in the document.override func viewDidAppear(_ animated: Bool) { //let pdfData = ... received data from file storage ... if let document = PDFDocument(data: pdfData) { for i in 0...document.pageCount { if let page = document.page(at: i) { for annot in page.annotations { if annot.widgetControlType == .radioButtonControl { annot.backgroundColor = UIColor.red } } } } } }When I set the background color, nothing happens.But when I try to set the background color to the type of Text annotation, the color changes.The difference between the Radio button and the Text annotation is in its type.The Radio button has a widgetFieldType == .button and the Text has a widgetFieldType == .text.I think this is the reason why it doesn't work.Next I try to remove annotation, change his background color and add again. This also doesn't work.if annot.widgetControlType == .radioButtonControl { page.removeAnnotation(annot) annot.backgroundColor = UIColor.red page.addAnnotation(annot) }But when I create a new instance of PDFAnnotaion, and I add it to the page, it works.if annot.widgetControlType == .radioButtonControl { page.removeAnnotation(annot) let newAnnot = PDFAnnotation(bounds: annot.bounds, forType: .widget, withProperties: nil) newAnnot.backgroundColor = UIColor.red newAnnot.widgetStringValue = annot.widgetStringValue page.addAnnotation(newAnnot) }The big problem is that the value of this Radio button is not displayed, even though it contains the value itself.If in another method I get all the values from PDF annotations, there is also the right value from this radio button.The Radio button contains the value, only it is displayed.I tried to copy all the properties PDF annotation from the annot to newAnnot, but it didn't help.How to properly change the background color of the Radio button and display its value?
Posted
by One Puty.
Last updated
.
Post not yet marked as solved
0 Replies
304 Views
Hi,I want to iterate all PDFAnnotation through the "Next" button and change focus to the next PDFAnnotation.I have a list of all PDFAnnotation, but I can't change it as active / focused.I can scroll PDFView to the location where the PDFAnnotation is located,but I can't display the keyboard and set focus inside the text PDFAnnotation.How can I do it?
Posted
by One Puty.
Last updated
.
Post not yet marked as solved
0 Replies
488 Views
Hi,I try to flatten all form fields in PDFDocument, but nothing work.I need to remove all active form field and display only values.I try set all annotation (form fields) propertyannot.isReadOnly = truebut this only set form field to read only mode, it still rendered, but it is only inactive.I need completty remove it and show only value.How can I flatten all form field over PDFDocument?
Posted
by One Puty.
Last updated
.
Post marked as solved
2 Replies
529 Views
Hi,I try to check which signature fields annotations are filed in.I tried to get some values from the annotation but I can't tell if the signature field is filled.I only found one thing. If signature field was filled annot.widgetStringValue return empty string ("").If the field wasn't filled, annot.widgetStringValue return nil.Here is me code:private func setupAnnotation(page: PDFPage) { for annot in page.annotations { if annot.widgetFieldType == .button { } else if annot.widgetFieldType == .choice { } else if annot.widgetFieldType == .signature { let value = annot.value(forAnnotationKey: .widgetValue) print(value) print(annot.widgetStringValue) print(annot.accessibilityValue) print(annot.annotationKeyValues) } else if annot.widgetFieldType == .text { } } }There is no property such as "isFilled", or "isSigned", or "hasValue".How can I check if signature field is filled?
Posted
by One Puty.
Last updated
.
Post marked as solved
5 Replies
1.8k Views
Hi,I use PDFKit in iOS as a pdf document renderer.In me case I need "flatten all form fields" and render it in me custom layer over pdf page.This is because I need to have full control over the fields.I can render watermark over every page when I registred classForPage in ViewController as:func classForPage() -> AnyClass { return CustomPage.self }CustomPage class:class CustomPage: PDFPage { override func draw(with box: PDFDisplayBox, to context: CGContext { super.draw(with: box, to: context) UIGraphicsPushContext(context) context.saveGState() let string: NSString = "Custom string" string.draw(at: CGPoint(x:250, y:40), withAttributes: attributes) context.restoreGState() UIGraphicsPopContext() } }I need to add custom UITextField in a similar way but when I try: let sampleTextField = UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40)) sampleTextField.placeholder = "Enter text here" sampleTextField.draw(CGRect(x: 20, y: 100, width: 300, height: 40))in run time XCode show warning "-[UITextField initWithFrame:] must be used from main thread only" and UITextField is not rendered.If I try to encapsulate the main thread:DispatchQueue.main.async { }warning from XCode not showed but UITextField still not rendered.I expect new UITextField on page 1, but the actual is page clear, without it.I want to render custom active element like as textfield, radio button, checkbox and signature field.
Posted
by One Puty.
Last updated
.