Last active
June 7, 2019 17:14
-
-
Save radazzouz/6c1a11925c0a6857a45ba1c4b6f71ad4 to your computer and use it in GitHub Desktop.
Use PSPDFKit in SwiftUI
This file contains hidden or 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 PSPDFKitUI | |
struct PDFView: View { | |
var url: URL | |
var configuration: PSPDFConfiguration? | |
var body: some View { | |
PDFViewController(url, configuration: configuration) | |
} | |
} | |
#if DEBUG | |
struct PDFView_Preview: PreviewProvider { | |
static var previews: some View { | |
PDFView(url: Bundle.main.bundleURL.appendingPathComponent("PSPDFKit 8 QuickStart Guide.pdf"), configuration: PSPDFConfiguration { $0.pageTransition = .scrollPerSpread }) | |
} | |
} | |
#endif | |
struct PDFViewController: UIViewControllerRepresentable { | |
let url: URL | |
let configuration: PSPDFConfiguration? | |
init(_ url: URL, configuration: PSPDFConfiguration?) { | |
self.url = url | |
self.configuration = configuration | |
} | |
func makeUIViewController(context: UIViewControllerRepresentableContext<PDFViewController>) -> UINavigationController { | |
// Create a PSPDFDocument | |
let document = PSPDFDocument(url: url) | |
// Create the PSPDFViewController | |
let pdfController = PSPDFViewController(document: document, configuration: configuration) | |
return UINavigationController(rootViewController: pdfController) | |
} | |
func updateUIViewController(_ uiViewController: UINavigationController, context: UIViewControllerRepresentableContext<PDFViewController>) { | |
// Update the view controller. | |
} | |
} |
Author
radazzouz
commented
Jun 6, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment