Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WWDC - Developer's Living - PDFKit on iOS 11 -

WWDC - Developer's Living - PDFKit on iOS 11 -

WWDC Retrospective
- PDFKit on iOS 11

Kishikawa Katsumi

July 04, 2017
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. PDFKit • PDFView • PDFThumbnailView • PDFDocument • PDFPage •

    PDFOutline • PDFSelection • PDFAnnotation • PDFAction kk@realm.io
  2. kk@realm.io if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { pdfView.document = document pdfView.backgroundColor = UIColor.lightGray pdfView.autoScales = true pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical PDFView
  3. kk@realm.io if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { ... pdfThumbnailView.thumbnailSize = CGSize(width: 50, height: 75) pdfThumbnailView.layoutMode = .horizontal pdfThumbnailView.pdfView = pdfView ... PDFThumbnailView
  4. kk@realm.io pdfView.displayMode = .singlePage pdfView.displayMode = .singlePageContinuous pdfView.displayMode = .twoUp

    pdfView.displayMode = .twoUpContinuous pdfView.displayDirection = .vertical pdfView.displayDirection = .horizontal PDFDisplayMode/PDFDisplayDirection
  5. kk@realm.io if let root = pdfDocument?.outlineRoot { var stack =

    [root] while !stack.isEmpty { let current = stack.removeLast() if let label = current.label, !label.isEmpty { var indentationLevel = -1 var parent = current.parent while let _ = parent { indentationLevel += 1 parent = parent?.parent } print(String(repeating: " ", count: indentationLevel) + label) } for i in (0..<current.numberOfChildren).reversed() { stack.append(current.child(at: i)) } } } Table of Contents (PDFOutline)
  6. kk@realm.io ͸͡Ίʹ ຊॻͷ಺༰ʹ͍ͭͯ TechBoosterͱ͸ ͓໰͍߹Θͤઌ ୈ1ষ ReVIEWೖ໳ 1.1 ReVIEWͱ͸Կ͔ 1.2

    ReVIEWͷಛ৭ 1.3 ReVIEWͷ޲͍͍ͯΔ෼໺ɺ޲͍͍ͯͳ͍෼໺ 1.4 ReVIEWͷ՝୊ 1.5 ·ͱΊ ୈ2ষ ؀ڥߏங 2.1 ReVIEW؀ڥͷߏ੒ 2.2 MacͰͷ؀ڥߏங 2.3 LinuxͰͷ؀ڥߏங 2.4 WindowsͰͷ؀ڥߏங ୈ3ষ ࣥචΛ࢝ΊΔ 3.1 ϓϩδΣΫτΛ࡞੒͢Δ Table of Contents (PDFOutline)
  7. kk@realm.io if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Draw custom contents
  8. kk@realm.io if let document = PDFDocument(url: documentURL) { if document.isEncrypted

    && document.unlock(withPassword: "...") { if document.permissionsStatus == .owner { // owner... } else { // user... if document.allowsCopying { ... } if document.allowsPrinting { ... } ... } } ... Open protected PDF
  9. kk@realm.io if let string = document.string { ... } Extract

    text if let string = page.string { ... }
  10. kk@realm.io if document.pageCount > 0 { if let page =

    document.page(at: 0) { let text = page.string let attributedText = page.attributedString let annotations = page.annotations ... } } Extract text
  11. kk@realm.io let selections = document.findString("...", withOptions: [.caseInsensitive]) for selection in

    selections { selection.color = .yellow ... } Search text (Synchronous)
  12. kk@realm.io if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Search text (Asynchronous)
  13. kk@realm.io func documentDidBeginPageFind(_ notification: Notification) { ... } func documentDidBeginDocumentFind(_

    notification: Notification) { ... } func documentDidEndDocumentFind(_ notification: Notification) { ... } func documentDidEndPageFind(_ notification: Notification) { ... } func documentDidFindMatch(_ notification: Notification) { let selection = notification.userInfo["PDFDocumentFoundSelection"] ... } func didMatchString(_ instance: PDFSelection) { instance.color = .yellow selections.append(instance) ... }