View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vidéos

Ouvrir le menu Fermer le menu
  • Collections
  • Toutes les vidéos
  • À propos

Plus de vidéos

  • À propos
  • Code
  • What's new in PDFKit

    Discover PDFKit — a full-featured framework that helps your app view, edit, and save PDF documents. We'll take you through the latest features in PDFKit, including support for live text and forms, creating PDFs from images, building interactive overlays, and saving annotations.

    Ressources

    • PDFAnnotationWidgetsAdvanced
      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    WWDC22

    • WWDC22 Day 4 recap

    WWDC19

    • Introducing PencilKit
  • Rechercher dans cette vidéo…
    • 6:54 - Implementing the overlay protocol

      class Coordinator: NSObject, PDFPageOverlayViewProvider {
      
          var pageToViewMapping = [PDFPage: UIView]()
         
          func pdfView(_ view: PDFView, overlayViewFor page: PDFPage) -> UIView? {
              var resultView: PKCanvasView? = nil
              
              if let overlayView = pageToViewMapping[page] {
                  resultView = overlayView
              } else {
                  let canvasView = PKCanvasView(frame: .zero)
                  canvasView.drawingPolicy = .anyInput
                  canvasView.tool = PKInkingTool(.pen, color: .systemYellow, width: 20)
                  canvasView.backgroundColor = UIColor.clear
                  pageToViewMapping[page] = canvasView
                  resultView = canvasView
              }
              
              // If we have stored a drawing on the page, set it on the canvas
              let page = page as! MyPDFPage
              if let drawing = page.drawing {
                  resultView?.drawing = drawing;
              }
              return resultView
          }
      
          func pdfView(_ pdfView: PDFView, willEndDisplayingOverlayView
              overlayView: UIView, for page: PDFPage) {
              let overlayView = overlayView as! PKCanvasView
              let page = page as! MyPDFPage
              page.drawing = overlayView.drawing
              pageToViewMapping.removeValue(forKey: page)
          }
      }
    • 10:22 - Create a subclass of PDFAnnotation

      // Implement a subclass with a drawing override
      
      class MyPDFAnnotation: PDFAnnotation {
          
          override func draw(with box: PDFDisplayBox, in context: CGContext) {
              UIGraphicsPushContext(context)
              context.saveGState()
              
              let page = self.page as! MyPDFPage
              if let drawing = page.drawing {
                  let image = drawing.image(from: drawing.bounds, scale: 1)
                  image.draw(in: drawing.bounds)
              }
              
              context.restoreGState()
              UIGraphicsPopContext()
          }
      }
    • 10:35 - Add annotations to your document when saving

      override func contents(forType typeName: String) throws -> Any {
              
          if let pdfDocument = pdfDocument {
            
              // Go through all pages in the document
              for i in 0...pdfDocument.pageCount-1 {
                  if let page = pdfDocument.page(at: i) {                       
                      if let drawing = (page as! MyPDFPage).drawing {
                              
                          // Create an annotation of our custom subclass
                          let newAnnotation = MyPDFAnnotation(bounds: drawing.bounds,
                                                              forType: .stamp, withProperties: nil)
                              
                          // Add our custom data
                          let codedData = try! NSKeyedArchiver.archivedData(withRootObject: drawing,
                                                                            requiringSecureCoding: true)
                          newAnnotation.setValue(codedData,
                                                 forAnnotationKey: PDFAnnotationKey(rawValue: "drawingData"))
                              
                          // Add our annotation to the page
                          page.addAnnotation(newAnnotation)
                      }
                  }
              }
      
              // -- Option #1: Save the document to a data representation
              if let resultData = pdfDocument.dataRepresentation() {
                  return resultData
              }
            
              // -- Option #2: Save the document to a data representation and "burn in" annotations
              let options = [PDFDocumentWriteOption.burnInAnnotationsOption: true]
              if let resultData = pdfDocument.dataRepresentation(options: options) {
                  return resultData
              }
          }
                      
          // Fall through to returning empty data
          return Data()
      }

Developer Footer

  • Vidéos
  • WWDC22
  • What's new in PDFKit
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines