Rendering NSAttributedStrings with link attributes to PDF doesn’t result in clickable links

Originator:marco
Number:rdar://FB8728485 Date Originated:2020-09-22
Status:Open Resolved:No
Product:iOS + iPadOS Product Version:14.0
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
When rendering an NSAttributedString with link attributes to a PDF using a CGContext, the resulting PDF contains the expected text and it automatically is rendered in blue with an underline to indicate it has a link, but there is no actual link there, i.e. it can’t be clicked. When running the equivalent code on macOS, the text does have the expected link (but it’s neither blue, nor underlined there 🤷‍♂️).

Steps to reproduce:
- Create a CGContext for rendering a PDF
- Create an NSAttributedString that contains a `.link` attribute
- Draw the string, write the PDF to a file
- Open the resulting PDF in Preview.app on macOS
- Try to click the text

Expected result:
The text has a link and is clickable.

Actual result:
The text does not have a link and is not clickable.

The attached sample project generates such a PDF, writes it to a temporary directory, prints the PDF file path, and terminates the process. The project contains two schemes: one for iOS, one for macOS. When you compare the resulting PDFs, you can see that the exact same code running on macOS generates a PDF that contains a clickable link, as you would expect. Only running the code on iOS results in a missing link.

Tested using:
- Xcode 11.7 on macOS 10.15.6 as well as Xcode 12.2 Beta 1 on macOS 11 Beta 7
- iOS 14 on an iPhone X, iOS 14 Simulator

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!