PSPDFKit supports all common types of link annotations, including page, web, and email links. Tapping on a link will automatically invoke both the saved action (see PDF Actions) and the correct task, such as changing the page or displaying another document/opening a URL.
By default, PSPDFKit will parse annotations, including links, from the document.
It’s possible to create a link annotation in the UI by either selecting text and tapping the link annotation symbol in the contextual menu, or by using the link tool on the annotation toolbar and selecting text or an arbitrary rectangular area on the page. This will show a UI where you can choose between linking to a page in the current document or linking to a website.
You can also manually create link annotations and add them to a document (see Programmatically Creating Annotations). For adding link annotations, you should create objects of the
Additionally, you can change the background color of link annotation views via
UIAppearance. The set background color will always be shown for all link annotations. It should be used to highlight them, so it is recommended that this color has a high transparency. Setting the background color can be achieved with this logic:
// Customize the link annotation's appearance. PSPDFLinkAnnotationView.appearance().backgroundColor = UIColor.blue.withAlphaComponent(0.1)
// Customize the link annotation's appearance. [[PSPDFLinkAnnotationView appearance] setBackgroundColor:[UIColor.blueColor colorWithAlphaComponent:0.1]];
PSPDFKit is capable of analyzing the page contents and automatically adding links to URLs and phone numbers. This is slightly expensive since text needs to be parsed and analyzed, but it’s done in a background process, so in most cases, it’s not noticeably slower. Set
PSPDFTextCheckingTypeAll to enable detection for all supported types.
Note that autodetecting a link only works if there is no overlapping link annotation at the same location the autodetected link would be located at on a PDF page. This is done to avoid creating duplicate link annotations over text that already has a link annotation saved in the PDF.