Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created August 17, 2024 19:17
Show Gist options
  • Save colinfwren/091cd20615a9d1da6eb89c8d4daff01b to your computer and use it in GitHub Desktop.
Save colinfwren/091cd20615a9d1da6eb89c8d4daff01b to your computer and use it in GitHub Desktop.
CV Preview View
import SwiftUI
import PDFKit
import PDFBlocks
struct CVPreviewView: UIViewRepresentable {
var pdfDocument: PDFDocument
init(pdfData pdfDoc: PDFDocument) {
self.pdfDocument = pdfDoc
}
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
}
}
struct CVDetailView: View {
@State private var cvdata: Data?
var body: some View {
Button("Create PDF", action: createPDF)
if (cvData != nil) {
CVPreviewView(pdfData: PDFDocument(data: cvData!)!)
}
}
func createPDF() {
let doc = CVDoc()
if let data = try await doc.renderPDF(size: .a4, margins: .init(.in(0.4))) {
cvData = data
}
}
}
struct CVDoc: Block {
var body: some Block {
// PDFBlocks based PDF structure
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment