import SwiftUI
import PDFKit
struct PDFViewWrapper: View {
@State private var pdfDocument: PDFDocument?
var body: some View {
VStack {
if let document = pdfDocument {
PDFView(document: document)
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
Text("PDF not available")
}
}
}
}
struct PDFViewWrapper_Previews: PreviewProvider {
static var previews: some View {
PDFViewWrapper()
.onAppear {
let generatedPDF = generatePDF() // Replace with your PDF generation code
PDFDocument(data: generatedPDF) { document in
pdfDocument = document
}
}
}
}
func generatePDF() -> Data {
// Replace with your PDF generation code
// Return the generated PDF data
return Data()
}
how about this?