A quick PDF Viewer in SwiftUI

Hello Reader,

I have been working on a personal project which requires a PDF file to be loaded and editable. I chose Swift for this project and using Apple’s PDFKit package.

But then today, I just thought of trying out the basic PDF file loading and viewing via SwiftUI. I found SwiftUI to be really sleek, swift (aptly named), and fun to work on. Kind of felt it similar to Flutter framework, just a personal perspective.

Anyways, for reading a PDF document using PDFKit only two steps are required for Swift, and in case of SwiftUI, an additional step is needed :)

  1. Fetch a Document object from PDFDocument class by providing the URL/File path of your pdf file
  2. Assign this Document object to a PDFView class object
  3. You need to create a UIView generator wrapper for PDFView class, as SwiftUI doesn’t have a readily available UIView subclass for it.
Fetch a Document object from PDFDocument class
Create a UIView representable wrapper for PDFView class object

Now you can directly use this PDFViewUI object in SwiftUI framework layout

And this is how the app looks on iPad and iPhone sims


I also have a Swift only version of this app and with additional features like:

  • Add coloured annotations
  • Multi-page support
  • Undo feature





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

API Documentation Writers: One Sentence Introduces Concepts

Debugging PL/SQL with Visual Studio Code (and more)

My Toolbox

Fractal Aggregation and MongoDB Charts

YSL.IO x Im Community AMA Recap


What is Google Cloud Anthos’ promise for hybrid & multi-cloud environments?

How remove tracking elements from URLs? | ClearURLs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Singh

Abhishek Singh


More from Medium

Detecting Screen Size/Resolution Changes in macOS with SwiftUI

How can SwiftUI & UIKit interact

Journey to the Center of SwiftUI with Firebase

Classifying Sounds with the SoundAnalysis framework and custom CoreML models in Swift