Created
August 17, 2024 19:17
-
-
Save colinfwren/091cd20615a9d1da6eb89c8d4daff01b to your computer and use it in GitHub Desktop.
CV Preview View
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 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