Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
はじめてのPDFKit
Search
shoma.kato
February 10, 2025
Technology
45
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめてのPDFKit
PDFKitに関して様々なTipsを紹介します
shoma.kato
February 10, 2025
More Decks by shoma.kato
See All by shoma.kato
体験!SwiftChartsの世界
shomakato
0
24
動画エフェクトに関する新技術の紹介
shomakato
0
28
はじめてのPDFKit.pdf
shomakato
0
220
SwiftとC++を利用した画像処理プログラミング
shomakato
0
2.4k
Other Decks in Technology
See All in Technology
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
1.1k
2026TECHFRESH畢業分享會 - 葬送的通靈師:化系統與用戶雜訊成行動訊號
line_developers_tw
PRO
0
1.1k
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
7k
Kiroで書いた 設計書 が AI レビューの 採点基準 になる
ezaki
0
110
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
1.1k
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
2.4k
新しいUbuntu/GNOMEが使いたいからXからWaylandへ移行頑張ってるの巻 2026-06-20
nobutomurata
0
120
MUSUBI 田中裕一『AIと共に行う「しごとのリデザイン」- スモールバックオフィス編』AI Ops Lab #4
musubi
0
190
現地で盛り上がった WWDC26 Keynote
zozotech
PRO
1
250
連合学習と機密コンピューティング
lycorptech_jp
PRO
0
120
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
350
【セミナー資料】Claude Code をセキュアに使うための考え方と設定の勘どころ / Claude Code Webinar 20260616
masahirokawahara
2
350
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Unsuck your backbone
ammeep
672
58k
GitHub's CSS Performance
jonrohan
1033
470k
エンジニアに許された特別な時間の終わり
watany
107
250k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
Making the Leap to Tech Lead
cromwellryan
135
9.9k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
430
Git: the NoSQL Database
bkeepers
PRO
432
67k
Transcript
Copyright © ZOZO, Inc. ͡ΊͯͷPDFKit גࣜձࣾZOZO ϒϥϯυιϦϡʔγϣϯ։ൃຊ෦ FAANS෦ ϑϩϯτΤϯυϒϩοΫ Ճ౻
ਅ @shoma10170806
© ZOZO, Inc. 2 גࣜձࣾZOZO ϒϥϯυιϦϡʔγϣϯ։ൃຊ෦ FAANS෦ ϑϩϯτΤϯυϒϩοΫ Ճ౻ ਅ
• X: @shoma10170806 • 20234݄: ZOZOೖࣾʢ2ʣ • γϣοϓελοϑͷൢചαϙʔτπʔϧ ʮFAANSʯͷiOSΞϓϦΛ։ൃ • ത࢜ޙظ՝ఔʹࡏֶதɹը૾ॲཧͳͲͷݚڀʹैࣄ
© ZOZO, Inc. 3 FAANSͷ৽ػೳ ɾPDFͷදࣔػೳ - ίʔσΟωʔτͷߘʹཱͭใ - ֦େɾॖখ
- ϖʔδ൪߸ͷදࣔ
© ZOZO, Inc. 4 FAANSͷ৽ػೳ ɾPDFͷදࣔػೳ - ίʔσΟωʔτͷߘʹཱͭใ - ֦େɾॖখ
- ϖʔδ൪߸ͷදࣔ
© ZOZO, Inc. 5 FAANSͷ৽ػೳ ɾPDFͷදࣔػೳ - ίʔσΟωʔτͷߘʹཱͭใ - ֦େɾॖখ
- ϖʔδ൪߸ͷදࣔ
© ZOZO, Inc. 6 FAANSͷ৽ػೳ PDFදࣔ: PDFKit ɾPDFͷදࣔػೳ - ίʔσΟωʔτͷߘʹཱͭใ
- ֦େɾॖখ - ϖʔδ൪߸ͷදࣔ
© ZOZO, Inc. 7 Section1: PDFKitΛ༻͍ͨදࣔ Section2: ϖʔδ൪߸ͷߋ৽
© ZOZO, Inc. 8 Section1: PDFKitΛ༻͍ͨදࣔ Section2: ϖʔδ൪߸ͷߋ৽
© ZOZO, Inc. 9 PDFDocumentͷಡΈࠐΈ Section1: PDFKitΛ༻͍ͨදࣔ extension URLSession {
func data(with url: URL) async throws -> (Data, URLResponse) { try await data(from: url) } } private func loadPdfDocument() async { var pdfDocument: PDFDocument? do { let (data, _) = try await URLSession.shared.data(with: pdfUrl) if let document = PDFDocument(data: data), document.pageCount > 0 { self.pdfDocument = document } } catch { // ಡΈࠐΈΤϥʔͷ߹ } }
© ZOZO, Inc. private func loadPdfDocument() async { var pdfDocument:
PDFDocument? do { let (data, _) = try await URLSession.shared.data(with: pdfUrl) if let document = PDFDocument(data: data), document.pageCount > 0 { self.pdfDocument = document } } catch { // ಡΈࠐΈΤϥʔͷ߹ } } 10 PDFDocumentͷಡΈࠐΈ Section1: PDFKitΛ༻͍ͨදࣔ pdfUrl: https:// xxx.pdf extension URLSession { func data(with url: URL) async throws -> (Data, URLResponse) { try await data(from: url) } }
© ZOZO, Inc. private func loadPdfDocument() async { var pdfDocument:
PDFDocument? do { let (data, _) = try await URLSession.shared.data(with: pdfUrl) if let document = PDFDocument(data: data), document.pageCount > 0 { self.pdfDocument = document } } catch { // ಡΈࠐΈΤϥʔͷ߹ } } extension URLSession { func data(with url: URL) async throws -> (Data, URLResponse) { try await data(from: url) } } 11 PDFDocumentͷಡΈࠐΈ Section1: PDFKitΛ༻͍ͨදࣔ ɾdata͔ΒPDFDocumentΛੜ ɾϖʔδ: 1Ҏ্
© ZOZO, Inc. 12 PDFͷදࣔ let pdfView = PDFView() pdfView.document
= document pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactor ① PDFViewʹPDFDocumentͷૠೖ Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. 13 PDFͷදࣔ ① PDFViewʹPDFDocumentͷૠೖ ② දࣔํ๏ͷઃఆ let
pdfView = PDFView() pdfView.document = document pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactor Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. let pdfView = PDFView() pdfView.document = document
pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactor 14 PDFͷදࣔ ① PDFViewʹPDFDocumentͷૠೖ ② දࣔํ๏ͷઃఆ ③ PDFͷαΠζΛࣗಈͰௐ Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. let pdfView = PDFView() pdfView.document = document
pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactor 15 PDFͷදࣔ ① PDFViewʹPDFDocumentͷૠೖ ② දࣔํ๏ͷઃఆ ④ ॖখαΠζͷ࠷খͷܾఆ ③ PDFͷαΠζΛࣗಈͰௐ Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. let pdfView = PDFView() pdfView.document = document
pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.autoScales = true pdfView.minScaleFactor = pdfView.scaleFactor 16 PDFͷදࣔ ① PDFViewʹPDFDocumentͷૠೖ ② දࣔํ๏ͷઃఆ ④ ॖখαΠζͷ࠷খͷܾఆ ③ PDFͷαΠζΛࣗಈͰௐ Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. 17 ॳظঢ়ଶʹ͓͚ΔPDFදࣔҐஔͷζϨ ॳظදࣔʢζϨʣ ਖ਼ৗ ζϨ Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. 18 ζϨ ɾζϨͷݪҼ - PDFͷαΠζ - தԝἧ͑
Section1: PDFKitΛ༻͍ͨදࣔ ॳظঢ়ଶʹ͓͚ΔPDFදࣔҐஔͷζϨ ਖ਼ৗ ॳظදࣔʢζϨʣ
© ZOZO, Inc. 19 ζϨ ɾζϨͷݪҼ - PDFͷαΠζ - தԝἧ͑
Section1: PDFKitΛ༻͍ͨදࣔ ॳظঢ়ଶʹ͓͚ΔPDFදࣔҐஔͷζϨ ॳظঢ়ଶ: PDFࠨ্͕ը໘ ਖ਼ৗ ॳظදࣔʢζϨʣ
© ZOZO, Inc. 20 ζϨͷվળํ๏ if let firstPage = document.page(at:
0) { pdfView.go( to: firstPage.bounds(for: pdfView.displayBox), on: firstPage ) } Section1: PDFKitΛ༻͍ͨදࣔ
© ZOZO, Inc. 21 if let firstPage = document.page(at: 0)
{ pdfView.go( to: firstPage.bounds(for: pdfView.displayBox), on: firstPage ) } ① PDFDocumentͷ1ϖʔδΛऔಘ ② 1ϖʔδͷࠨ্͕දࣔ͞ΕΔΑ͏ʹҠಈ Section1: PDFKitΛ༻͍ͨදࣔ ζϨͷվળํ๏
© ZOZO, Inc. 22 Section1: PDFKitΛ༻͍ͨදࣔ Section2: ϖʔδ൪߸ͷߋ৽
© ZOZO, Inc. 23 ϖʔδ൪߸ͷදࣔ ࠨଆ: ݱࡏͷϖʔδ൪߸ ӈଆ: ૯ϖʔδ
© ZOZO, Inc. 24 ϖʔδ൪߸ͷऔಘํ๏ let document: PDFDocument? let pdfView
= PDFView() let totalPage = document.pageCount NotificationCenter.default .addObserver(forName: .PDFViewPageChanged, object: pdfView, queue: .main) { _ in Task { @MainActor in let pageNumber = pdfView.currentPage?.pageRef?.pageNumber } } ࠨଆ: ݱࡏͷϖʔδ൪߸ ӈଆ: ૯ϖʔδ ① ૯ϖʔδͷऔಘ
© ZOZO, Inc. 25 ϖʔδ൪߸ͷऔಘํ๏ let document: PDFDocument? let pdfView
= PDFView() let totalPage = document.pageCount NotificationCenter.default .addObserver(forName: .PDFViewPageChanged, object: pdfView, queue: .main) { _ in Task { @MainActor in let pageNumber = pdfView.currentPage?.pageRef?.pageNumber } } ࠨଆ: ݱࡏͷϖʔδ൪߸ ӈଆ: ૯ϖʔδ ① ૯ϖʔδͷऔಘ ② ϖʔδͷมߋࢹɾ൪߸औಘ
© ZOZO, Inc. 26 ϖʔδ൪߸ͷऔಘํ๏ let document: PDFDocument? let pdfView
= PDFView() let totalPage = document.pageCount NotificationCenter.default .addObserver(forName: .PDFViewPageChanged, object: pdfView, queue: .main) { _ in Task { @MainActor in let pageNumber = pdfView.currentPage?.pageRef?.pageNumber } } ࠨଆ: ݱࡏͷϖʔδ൪߸ ӈଆ: ૯ϖʔδ ① ૯ϖʔδͷऔಘ ② ϖʔδͷมߋࢹɾ൪߸औಘ
© ZOZO, Inc. 27 ϖʔδ൪߸औಘͷ ɾԣͷPDF - ը໘্ʹෳຕͷPDF - ϖʔδ൪߸:
2͔Βදࣔ͞ΕΔ ॳظঢ়ଶ: ϖʔδ൪߸Λ1ʹ͢Δ ※ Πϝʔδը૾
© ZOZO, Inc. 28 ॳظঢ়ଶͷఆํ๏ ɾoffset͕0: ϖʔδ൪߸1 PDFView: offsetऔಘͰ͖ͳ͍
© ZOZO, Inc. 29 ॳظঢ়ଶͷఆํ๏ UIScrollView extension PDFView { func
scrollView() -> UIScrollView? { return self.subviews.compactMap { $0 as? UIScrollView }.first } } ɾoffset͕0: ϖʔδ൪߸1 PDFView: offsetऔಘͰ͖ͳ͍ ϫʔΫΞϥϯυ
© ZOZO, Inc. 30 ॳظঢ়ଶͷఆํ๏ if let scrollView = pdfView.scrollView()
{ scrollView.publisher(for: \.contentOffset) .sink { [weak pdfView] contentOffset in Task { @MainActor in guard let pdfView = pdfView else { return } if contentOffset.y <= 0.0 { currentPage = 1 } else if let pageNumber = pdfView.currentPage?.pageRef?.pageNumber, pageNumber != currentPage { NotificationCenter.default.post( name: .PDFViewPageChanged, object: pdfView ) } } } } ① UIScrollViewͷݕग़ ② offSetͷpublisherΛൃߦ
© ZOZO, Inc. if let scrollView = pdfView.scrollView() { scrollView.publisher(for:
\.contentOffset) .sink { [weak pdfView] contentOffset in Task { @MainActor in guard let pdfView = pdfView else { return } if contentOffset.y <= 0.0 { currentPage = 1 } else if let pageNumber = pdfView.currentPage?.pageRef?.pageNumber, pageNumber != currentPage { NotificationCenter.default.post( name: .PDFViewPageChanged, object: pdfView ) } } } } 31 ॳظঢ়ଶͷఆํ๏ ③ ϖʔδ൪߸ͷߋ৽ ① UIScrollViewͷݕग़ ② offSetͷpublisherΛൃߦ
© ZOZO, Inc. if let scrollView = pdfView.scrollView() { scrollView.publisher(for:
\.contentOffset) .sink { [weak pdfView] contentOffset in Task { @MainActor in guard let pdfView = pdfView else { return } if contentOffset.y <= 0.0 { currentPage = 1 } else if let pageNumber = pdfView.currentPage?.pageRef?.pageNumber, pageNumber != currentPage { NotificationCenter.default.post( name: .PDFViewPageChanged, object: pdfView ) } } } } 32 ॳظঢ়ଶͷఆํ๏ ③ ϖʔδ൪߸ͷߋ৽ ① UIScrollViewͷݕग़ ② offSetͷpublisherΛൃߦ
© ZOZO, Inc. if let scrollView = pdfView.scrollView() { scrollView.publisher(for:
\.contentOffset) .sink { [weak pdfView] contentOffset in Task { @MainActor in guard let pdfView = pdfView else { return } if contentOffset.y <= 0.0 { currentPage = 1 } else if let pageNumber = pdfView.currentPage?.pageRef?.pageNumber, pageNumber != currentPage { NotificationCenter.default.post( name: .PDFViewPageChanged, object: pdfView ) } } } } 33 ॳظঢ়ଶͷఆํ๏ ③ ϖʔδ൪߸ͷߋ৽ ① UIScrollViewͷݕग़ ② offSetͷpublisherΛൃߦ
© ZOZO, Inc. 34 ϖʔδ൪߸ͷදࣔ݁Ռ ※දࣔ͞Ε͍ͯΔPDFΠϝʔδͰ͢
© ZOZO, Inc. 35 ·ͱΊ ɾPDFKitͷ͍ํ ɹ- PDFKitΛ༻͍ͨPDFදࣔ ɹ- ϖʔδ൪߸ͷߋ৽
None