Skip to content
swift-libraryPublic

About

Build PDF viewers in SwiftUI with search, page overlays, and navigation driven by your controls.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

swift-pdf logo

swift-pdf

Build PDF viewers in SwiftUI with search, page overlays, and navigation driven by your controls.

CI Swift 6.2+ Platforms: iOS 18+ | macOS 15+ | visionOS 2+ License: Apache-2.0 WITH Swift-exception

Overview · Quick look · Install · Usage · Requirements · Documentation · Contributing · License

Overview

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.

Quick look

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() }
    }
  }
}

Install

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:).

Usage

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.

Requirements

  • Swift 6.2 or later.
  • iOS 18+, macOS 15+, or visionOS 2+.
  • SwiftUI and PDFKit; the package has no external package dependencies.

Documentation

Contributing

See Contributing. Run Scripts/check for the package's formatting, builds, tests, simulator checks, and compiling DocC examples.

License

Apache-2.0 WITH Swift-exception. See NOTICE for source ownership and attribution.

About

Build PDF viewers in SwiftUI with search, page overlays, and navigation driven by your controls.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages