Slide 1

Slide 1 text

WWDC Developer's Living [email protected]

Slide 2

Slide 2 text

Katsumi Kishikawa Realm Inc. [email protected]

Slide 3

Slide 3 text

Slide 4

Slide 4 text

PDFKit • PDFView • PDFThumbnailView • PDFDocument • PDFPage • PDFOutline • PDFSelection • PDFAnnotation • PDFAction [email protected]

Slide 5

Slide 5 text

[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

Slide 6

Slide 6 text

Slide 7

Slide 7 text

[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

Slide 8

Slide 8 text

Slide 9

Slide 9 text

[email protected] pdfView.displayMode = .singlePage pdfView.displayMode = .singlePageContinuous pdfView.displayMode = .twoUp pdfView.displayMode = .twoUpContinuous pdfView.displayDirection = .vertical pdfView.displayDirection = .horizontal PDFDisplayMode/PDFDisplayDirection

Slide 10

Slide 10 text

[email protected] singlePageContinuous twoUpContinuous

Slide 11

Slide 11 text

[email protected] singlePage twoUp

Slide 12

Slide 12 text

[email protected] pdfView.usePageViewController(true, withViewOptions: [UIPageViewControllerOptionInterPageSpacingKey: 20]) PDFView with UIPageViewController

Slide 13

Slide 13 text

[email protected] PDFView with UIPageViewController

Slide 14

Slide 14 text

[email protected] pdfView.goToFirstPage(nil) pdfView.goToLastPage(nil) pdfView.goToNextPage(nil) pdfView.goToPreviousPage(nil) pdfView.go(to: document.page(at: 10)!) Change current page

Slide 15

Slide 15 text

[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..

Slide 16

Slide 16 text

[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)

Slide 17

Slide 17 text

[email protected] if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") { if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Draw custom contents

Slide 18

Slide 18 text

[email protected] func classForPage() -> AnyClass { return WatermarkPage.self } Draw custom contents (e.g. Watermark)

Slide 19

Slide 19 text

Slide 20

Slide 20 text

[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

Slide 21

Slide 21 text

[email protected] if let string = document.string { ... } Extract text if let string = page.string { ... }

Slide 22

Slide 22 text

[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

Slide 23

Slide 23 text

[email protected] let selections = document.findString("...", withOptions: [.caseInsensitive]) for selection in selections { selection.color = .yellow ... } Search text (Synchronous)

Slide 24

Slide 24 text

[email protected] if let documentURL = Bundle.main.url(forResource: "...", withExtension: "pdf") { if let document = PDFDocument(url: documentURL) { ... document.delegate = self ... Search text (Asynchronous)

Slide 25

Slide 25 text

[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) ... }

Slide 26

Slide 26 text

[email protected] Search text

Slide 27

Slide 27 text

[email protected] Search text

Slide 28

Slide 28 text

[email protected] Search text ߦΛ·͙ͨͳͲ͢Δͱ͍͍ͨͯ͸ۭനจࣈ͕ؒʹೖͬͯ͠·ͬͯʮΠϯ ε τʔϧʯͷΑ͏ʹͳΔͷͰݕࡧʹϚον͠ͳ͍͜ͱ͕͋Γ·͢ɻ PDFʹ͸ߦ΍ஈམͱ͍͏֓೦͸ͳ͍ͷͰ͜Ε͸࢓ํ͕ͳ͍͜ͱͰ͢ɻ iBooks΍DropBoxΞϓϦͰಉ༷ͷ݁ՌʹͳΓ·͢ɻ ͜ͷ໰୊Λආ͚Δʹ͸ςΩετΛऔΓग़͠ɺۭന΍ۭߦΛऔΓআ͘ͳͲͯ͠ ΫϦʔχϯάࡁΈͷςΩετΛผ్σʔλϕʔεͳͲʹอ࣋͠ɺ͔ͦ͜Βݕ ࡧ͠·͢ɻ

Slide 29

Slide 29 text

241 Introducing PDFKit on iOS [email protected] Reference

Slide 30

Slide 30 text

241 Introducing PDFKit on iOS [email protected] Sample code (iBook clone)

Slide 31

Slide 31 text

[email protected] https://peaks.cc/iOS11

Slide 32

Slide 32 text

Questions? Katsuma Kishikawa [email protected] www.realm.io/jp @k_katsumi