pdfkit

Display and manipulate PDF documents using PDFKit. Use when embedding PDFView to show PDF files, creating or modifying PDFDocument instances, adding annotations (highlights, notes, signature widgets), extracting text with PDFSelection, navigating pages, generating thumbnails, filling PDF forms, or w

By dpearson2699 · 2,694 installs

npx skills add dpearson2699/swift-ios-skills --skill pdfkit

Source repository · Upstream listing

PDFKit Display, navigate, search, annotate, and manipulate PDF documents with PDFView , PDFDocument , PDFPage , PDFAnnotation , and PDFSelection . 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. API Availability PDFKit framework iOS/iPadOS/tvOS 11+, Mac Catalyst 13.1+, macOS 10.4+, visionOS 1.0+ Find interaction and page overlays iOS/iPadOS 16+ Displaying PDFs PDFView renders PDF content and handles zoom, scrolling, text selection, and page navigation. 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 Loading Documents PDFDocument loads from a URL, Data , or can be created empty. Password Protected PDFs Saving and Page Manipulation Page Navigation PDFView provides built in navigation with history tracking. Observing Page Changes Text Search and Selection Synchronous Search Asynchronous Search Use PDFDocumentDelegate for background searches on large documents. Implement didMatchString( :) to receive each match and documentDidEndDocumentFind( :) for completion. Incremental Search and Find Interaction Text Extraction Highlighting Search Results Annotations Annotations are created with PDFAnnotation(bounds:forType:withProperties:) and added to a PDFPage . Highlight Annotation Text Note Annotation Free Text Annotation Link Annotation Removing Annotations Common subtypes include .highlight , .underline , .strikeOut , .text , .freeText , .ink , .link , .line , .square , .circle , .stamp , and .widget . Thumbnails PDFThumbnailView PDFThumbnailView shows a strip of page thumbnails linked to a PDFView . Generating Thumbnails Programmatically SwiftUI Integration Wrap PDFView in a UIViewRepresentable for SwiftUI. PDF specific wrappers that configure PDFView , pages, annotations, search, thumbnails, or overlays belong in this skill; route only generic representable lifecycle, layout, or SwiftUI state architecture questions to SwiftUI/UIKit interop guidance. Usage For interactive wrappers with page tracking, annotation hit detection, and coordinator patterns, see [references/pdfkit patterns.md](references/pdfkit patterns.md). Page Overlays PDFPageOverlayViewProvider places UIKit views on top of individual pages for interactive controls or custom rendering beyond standard annotations. pageOverlayViewProvider is weak, so keep the provider strongly owned. For overlay lifecycle and save handling, read [references/pdfkit patterns.md](references/pdfkit patterns.md). Common Mistakes DON'T: Force unwrap PDFDocument init PDFDocument(url:) and PDFDocument(data:) are failable initializers. DON'T: Forget autoScales on PDFView Without autoScales , the PDF renders at its native resolution. DON'T: Ignore PDF coordinate system in annotations PDF page coordinates have origin at the bottom left with Y increasing upward opposite of UIKit. DON'T: Modify annotations on a background thread PDFKit classes are not thread safe. DON'T: Compare PDFDocument with == in UIViewRepresentable PDFDocument is a reference type. Use identity ( !== ). Review Checklist [ ] PDFDocument init uses optional binding, not force unwrap [ ] pdfView.autoScales = true set for proper initial display [ ] Page indices checked against pageCount before access [ ] displayMode and displayDirection configured to match design [ ] Annotations use PDF coordinate space (origin bottom left, Y up) [ ] All PDFKit mutations happen on the main thread [ ] Password protected PDFs handled with isLocked / unlock(withPassword:) [ ] SwiftUI wrapper uses !== identity check in updateUIView [ ] PDFViewPageChanged notification observed for page tracking [ ] PDFThumbnailView.pdfView linked to the main PDFView [ ] Large document search uses async beginFindString with delegate [ ] Saved documents use write(to:withOptions:) when encryption needed References Extended patterns (forms, watermarks, merging, printing, overlays, outlines, custom drawing): [references/pdfkit patterns.md](references/pdfkit patterns.md) [PDFKit framework](https://sosumi.ai/documentation/pdfkit) [PDFView](https://sosumi.ai/documentation/pdfkit/pdfview) [PDFDocument](https://sosumi.ai/documentation/pdfkit/pdfdocument) [PDFPage](https://sosumi.ai/documentation/pdfkit/pdfpage), [PDFAnnotation](https://sosumi.ai/documentation/pdfkit/pdfannotation), [PDFSelection](https://sosumi.ai/documentation/pdfkit/pdfselection), [PDFThumbnailView](https://sosumi.ai/documentation/pdfkit/pdfthumbnailview) [PDFPageOverlayViewProvider](https://sosumi.ai/documentation/pdfkit/pdfpageoverlayviewprovider) [Adding Widgets to a PDF Document](https://sosumi.ai/documentation/pdfkit/adding widgets to a pdf document) [Adding Custom Graphics to a PDF](https://sosumi.ai/documentation/pdfkit/adding custom graphics to a pdf)