![]() Let us see a code example of adding highlight to PDF page.Īdd the following code snippet after openPDFDocument function. Various annotation can be added like Circle, line, Strikeout, Square, Underline, Highlight etc. PDFKit provides option to add annotation to PDF file using PDFAnnoation class. Swift: PDFKit Introduction (2021, Xcode, iOS) - Swift for Beginners 8,694 views 200 Dislike Share Save iOS Academy 61. Add import statement after import UIKit and now you should be able to run the app on the simulator and select text on the PDF You will be seeing couple of unresolved identified errors because of missing import PDFKit statement. Loads the pdf file in a PDFDocument object let document = PDFDocument(url: path)Ĭreates an instance of PDFView and sets the frame to ViewController’s view then assigns the PDFDocument to PDFView instance. This function does the following guard let path = (forResource: "TheWakingLights",Ĭreates URL instance with the path of “TheWalkingLights.pdf” file. Before we can use these classes we need to import PDFKit. PDFDocument loads the PDF file and allows us to set the document property on the PDFView. PDFView is a subclass of UIView and it will be the view that shows the PDF file. These two classes are PDFView and PDFDocument. Guard let path = (forResource: "TheWakingLights", withExtension: "pdf") When using PDFKit there are two main classes that we are going to use. ![]() In Xcode’s project navigator, select ViewController.swift and add the following lines after viewDidLoad function. Now drag and drop this file to Xcode project and in “Choose options for adding these files” select “Copy items if needed” Let us start by selecting a Single View App template and name the project as PDFDemo.įor this demo, we will be using a PDF file “TheWakingLights.pdf” and this can downloaded from the github project folder. In this demo, we will be using PDFKit to View and Annotate PDF file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |