Last active
August 13, 2022 02:00
-
-
Save siliconsorcery/aacf39e820e7222e070c60c89cd7aa5e to your computer and use it in GitHub Desktop.
PDF View in SwiftUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import PDFKit | |
struct PDFPage: View { | |
var body: some View { | |
let url = URL(string: "https://web.stanford.edu/class/archive/cs/cs161/cs161.1168/lecture4.pdf")! | |
let pdfDoc = PDFDocument(url: url)! | |
ZStack { | |
Color.yellow | |
PDFKitView(showing: pdfDoc) | |
} | |
.ignoresSafeArea() | |
} | |
struct PDFKitView: UIViewRepresentable { | |
let pdfDocument: PDFDocument | |
init(showing pdfDoc: PDFDocument) { | |
self.pdfDocument = pdfDoc | |
} | |
//you could also have inits that take a URL or Data | |
func makeUIView(context: Context) -> PDFView { | |
let pdfView = PDFView() | |
pdfView.document = pdfDocument | |
pdfView.autoScales = true | |
return pdfView | |
} | |
func updateUIView(_ pdfView: PDFView, context: Context) { | |
pdfView.document = pdfDocument | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you get user input example the link and process it?