PDFKit cant create Label or FreeText annotation

Hi,


how can i create a annotation with free text?

If I create text annotation, the annotation is editable and I want to create text anntation looks like label, or freetext.


property .isReadOnly = true doesnt work.

if PDFAnnotationSubtype is PDFAnnotationSubtype.freeText in PDF is showed only yellow box with no text.


let labelText = PDFAnnotation(bounds: textBounds, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
        //let labelText = PDFAnnotation(bounds: textBounds, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.freeText.rawValue), withProperties: nil)
        
 labelText.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
 labelText.widgetDefaultStringValue = "My free text showed in PDF"
        
 labelText.isReadOnly = true 
 labelText.fontColor = .blue
 labelText.font = .systemFont(ofSize: 13)
 labelText.alignment = .center
        
 labelText.backgroundColor = .red


 pdfPage.addAnnotation(labelText)

Replies

I was have the save question until today, I found the way around:


let textFieldNameBounds = CGRect(x: 186, y: pageBounds.size.height - 69, width: 178, height: 14)

let textFieldName = PDFAnnotation(bounds: textFieldNameBounds, forType: PDFAnnotationSubtype.freeText, withProperties: nil)

textFieldName.contents = "Free Text"

textFieldName.color = .clear

textFieldName.font = UIFont.systemFont(ofSize: 12)

page.addAnnotation(textFieldName)