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.