Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust how PDF backup is rendered and written #31

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions modules/Sources/Features/ExportSeed/ExportSeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ private extension ExportSeedView {

let url = URL.documentsDirectory.appending(path: "encrypted_seed.pdf")
renderer.render { size, context in
guard let pdfData = CFDataCreateMutable(nil, 0) else { return }
var box = CGRect(x: 0, y: 0, width: size.width, height: size.height)
guard let pdf = CGContext(url as CFURL, mediaBox: &box, nil) else {
return
}
guard let pdfDataConsumer = CGDataConsumer(data: pdfData),
let pdf = CGContext(consumer: pdfDataConsumer, mediaBox: &box, nil)
else { return }

pdf.beginPDFPage(nil)
context(pdf)
pdf.endPDFPage()
pdf.closePDF()

// Read as a PDF document and encrypt with the provided password
guard let pdfDocument = PDFDocument(url: url) else { return }
guard let pdfDocument = PDFDocument(data: pdfData as Data) else { return }
pdfDocument.write(
to: url,
withOptions: [
Expand Down