Build PDF viewers in SwiftUI with search, page overlays, and navigation driven by your controls.
Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License
Keep the viewer’s state in sync with SwiftUI while your controls decide where to navigate. Search publishes matches without moving the document, and PDFViewReader gives controls a proxy for page commands; the PDF guides cover overlays and state bindings.
import PDF
import PDFKit
import SwiftUI
@MainActor
func reader(for document: PDFDocument) -> some View {
PDFViewReader { proxy in
VStack {
PDF(document: document).pdf.autoScales(true)
Button("Next") { proxy.goToNextPage() }
}
}
}Add the package and its PDF product to Package.swift:
dependencies: [
.package(
url: "https://github.com/swift-library/swift-pdf.git",
.upToNextMinor(from: "0.1.0")
),
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "PDF", package: "swift-pdf"),
]
),
]Note
swift-pdf is pre-1.0. Minor releases may include source-breaking changes,
so depend on it with .upToNextMinor(from:).
PDF(source:) accepts .document, .data, or .fileURL. Loading is handled
by PDFKit. Prepare a PDFDocument yourself when your interface needs to
handle a loading error before displaying the viewer.
Use .pdf.displayDirection, .pdf.autoScales, and .pdf.isInMarkupMode to
configure a viewer. Applying configuration to a parent view supplies defaults
for its descendant viewers.
Bind .pdf.searchQuery and .pdf.searchOptions to control a search. Observe
matches through .pdf.searchResults, .pdf.searchResultCount, and
.pdf.searchResultIndex; use the proxy to select a result. A query change
updates matches without automatically navigating.
Use .pdf.overlay to draw SwiftUI content on a page and .pdf.overlayRelease
to release associated resources when its overlay leaves the view lifecycle.
The getting started, search, and page overlay guides contain complete examples and behavior details.
- Swift 6.2 or later.
- iOS 18+, macOS 15+, or visionOS 2+.
- SwiftUI and PDFKit; the package has no external package dependencies.
- Architecture and lifecycle
- PDF module and API index
- PDFViewer example
- Versioning and release policy
- Release guide
See Contributing. Run Scripts/check for the package's
formatting, builds, tests, simulator checks, and compiling DocC examples.
Apache-2.0 WITH Swift-exception. See NOTICE for source ownership and attribution.