I think I found a workaround:
Draw text without a link attribute:
let text = "https://www.stackoverflow.com"
let attributes = [
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.foregroundColor: UIColor.black, // Set colour here
] as [NSAttributedString.Key : Any]
text.draw(at: textViewOrigin, withAttributes: attributes)
Create PDFDocument from the url where PDF is rendered and allow PDFKit add hyperlink automatically:
let pdfDocument = PDFDocument(url: url)
let pdfData = pdfDocument?.dataRepresentation()
Text attributes will be those set in Step 1 and thanks to some magic that happens in PDFDocument(url: url) link will be clickable. Then we can share PDF or whatever else was the goal.