
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make Phone Call in iOS 10 Using Swift
In this post we will learn how to load PDF in UIWebView.
Loading PDF in WebView is simple. Just follow the following steps.
Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “PDFInWebView”
Step 2 − Open Main.storyboard and add UIWebView as shown below
Step 3 − Create @IBOutlet for the UIWebView, name it webview.
Step 4 − Add as sample PDF project. We will load this PDF in webivew. I am adding a PDF file named sample PDF.
Step 5 − Add the following lines in viewDidLoad method of ViewController
if let pdf = Bundle.main.url(forResource: "sample", withExtension: "pdf", subdirectory: nil, localization: nil) { let reqest = NSURLRequest(url: pdf) webView.loadRequest(reqest as URLRequest) }
In the above code we are first getting the URL to the sample pdf file, then loading that URL into the webview.
Step 6 − Run the project, you will see the PDF load in webview
Advertisements