
Pdfkit
Ship in-app PDF viewing, search, annotations, and SwiftUI wrappers in Swift/iOS projects without piecing together PDFKit APIs from scratch.
Install
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill pdfkitWhat is this skill?
- End-to-end PDFView setup: load from bundle, Data, or file URL with auto-scaling, zoom limits, and display modes (single
- Page navigation APIs: go to first/last, next/previous, and outline-driven jumps via PDFOutline
- Text search and selection with PDFDocument.findString and PDFSelection bounds for highlights
- Annotation recipes: highlight, free text, ink, stamp, line, and link annotations on PDFPage
- SwiftUI integration pattern via UIViewRepresentable wrapping PDFView for modern app shells
Adoption & trust: 1.2k installs on skills.sh; 713 GitHub stars; 2/3 security scanners passed (skills.sh audits).
Recommended Skills
Journey fit
PDFKit guidance applies while you are implementing native UI and document-handling features in an iOS or iPadOS app, not during market research or launch SEO. Primary work is PDFView/UIKit and SwiftUI representable integration, page UI, thumbnails, and on-screen annotation workflows—classic mobile frontend surface area.
Common Questions / FAQ
Is Pdfkit safe to install?
skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Pdfkit
# PDFKit Display, navigate, search, annotate, and manipulate PDF documents with `PDFView`, `PDFDocument`, `PDFPage`, `PDFAnnotation`, and `PDFSelection`. Targets Swift 6.3 / iOS 26+. ## Contents - [Setup](#setup) - [Displaying PDFs](#displaying-pdfs) - [Loading Documents](#loading-documents) - [Page Navigation](#page-navigation) - [Text Search and Selection](#text-search-and-selection) - [Annotations](#annotations) - [Thumbnails](#thumbnails) - [SwiftUI Integration](#swiftui-integration) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## Setup PDFKit requires no entitlements or Info.plist entries. ```swift import PDFKit ``` **Platform availability:** iOS 11+, iPadOS 11+, Mac Catalyst 13.1+, macOS 10.4+, tvOS 11+, visionOS 1.0+. ## Displaying PDFs `PDFView` is a `UIView` subclass that renders PDF content, handles zoom, scroll, text selection, and page navigation out of the box. ```swift import PDFKit import UIKit class PDFViewController: UIViewController { let pdfView = PDFView() override func viewDidLoad() { super.viewDidLoad() pdfView.frame = view.bounds pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(pdfView) pdfView.autoScales = true pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical if let url = Bundle.main.url(forResource: "sample", withExtension: "pdf") { pdfView.document = PDFDocument(url: url) } } } ``` ### Display Modes | Mode | Behavior | |---|---| | `.singlePage` | One page at a time | | `.singlePageContinuous` | Pages stacked vertically, scrollable | | `.twoUp` | Two pages side by side | | `.twoUpContinuous` | Two-up with continuous scrolling | ### Scaling and Appearance ```swift pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit pdfView.maxScaleFactor = 4.0 pdfView.displaysPageBreaks = true pdfView.pageShadowsEnabled = true pdfView.interpolationQuality = .high ``` ## Loading Documents `PDFDocument` loads from a URL, `Data`, or can be created empty. ```swift let fileDoc = PDFDocument(url: fileURL) let dataDoc = PDFDocument(data: pdfData) let emptyDoc = PDFDocument() ``` ### Password-Protected PDFs ```swift guard let document = PDFDocument(url: url) else { return } if document.isLocked { if !document.unlock(withPassword: userPassword) { // Show password prompt } } ``` ### Saving and Page Manipulation ```swift document.write(to: outputURL) document.write(to: outputURL, withOptions: [ .ownerPasswordOption: "ownerPass", .userPasswordOption: "userPass" ]) let data = document.dataRepresentation() // Pages (0-based) let count = document.pageCount document.insert(PDFPage(), at: count) document.removePage(at: 2) document.exchangePage(at: 0, withPageAt: 3) ``` ## Page Navigation `PDFView` provides built-in navigation with history tracking. ```swift // Go to a specific page if let page = pdfView.document?.page(at: 5) { pdfView.go(to: page) } // Sequential navigation pdfView.goToNextPage(nil) pdfView.goToPreviousPage(nil) pdfView.goToFirstPage(nil) pdfView.goToLastPage(nil) // Check navigation state if pdfView.canGoToNextPage { /* ... */ } // History navigation if pdfView.canGoBack { pdfView.goBack(nil) } // Go to a specific point on a page let destination = PDFDestination(page: page, at: CGPoint(x: 0, y: 500)) pdfView.go(to: destination) ``` ### Observing Page Changes ```swift NotificationCenter.default.addObserver( self, selector: #selector(pageChanged), name: .PDFVi