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 [email protected]
  2. [email protected] 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. [email protected] 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. [email protected] pdfView.displayMode = .singlePage pdfView.displayMode = .singlePageContinuous pdfView.displayMode = .twoUp

    pdfView.displayMode = .twoUpContinuous pdfView.displayDirection = .vertical pdfView.displayDirection = .horizontal PDFDisplayMode/PDFDisplayDirection
  5. [email protected] 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. [email protected] ͸͡Ίʹ ຊॻͷ಺༰ʹ͍ͭͯ 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. [email protected] if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Draw custom contents
  8. [email protected] 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. [email protected] 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
  10. [email protected] if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") {

    if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Search text (Asynchronous)
  11. [email protected] 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) ... }