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

Added algorithm for pagination to PDF export, allowing to export consent forms with more than 1 page (#49) #52

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ec18eab
Introduced algorithm to split exported consent document across multip…
RealLast Jun 22, 2024
4ee81b1
Removed leftover continuation from older version of the code.
RealLast Jun 22, 2024
457b273
Resolved swiftlint issues.
RealLast Jun 26, 2024
42c2443
Removed unused variables, further cleaned up code.
RealLast Jun 27, 2024
ee2f2f4
Changed PDF export to use TPPDF for PDF generation, instead of creati…
RealLast Jul 11, 2024
23e5333
Changed personName -> signature.
RealLast Jul 11, 2024
a947d7d
Reverted changes.
RealLast Jul 11, 2024
5fbc2a7
Update iPad Testing Identifier.
RealLast Jul 12, 2024
8ec56a2
Update Tests and try Beta 4
PSchmiedmayer Aug 3, 2024
5238a7b
Update Tests
PSchmiedmayer Aug 3, 2024
a417fa9
Update GitHub Action
PSchmiedmayer Aug 3, 2024
f2e767c
Merging in changes from main.
RealLast Aug 14, 2024
a11df71
Separated PDF export functionality from ConsentDocument. Added type C…
RealLast Aug 14, 2024
2d793db
Added known good PDF files for iOS, macOS and visionOS, which is used…
RealLast Aug 14, 2024
c7cc518
Added known-good PDF documents to test against in testPDFExport.
RealLast Aug 14, 2024
0d287e5
Merge remote-tracking branch 'upstream/main' into PDFPagination
RealLast Aug 24, 2024
e6080f6
Merged in changes from #52.
RealLast Aug 24, 2024
d15f5e3
Resolved errors on macOS.
RealLast Aug 24, 2024
4e919db
Expanded unit test for PDF export to include documents with two pages.
RealLast Aug 24, 2024
c747606
Fixed swiftlint issues. Added license information.
RealLast Aug 24, 2024
d42fa7d
Added missing files.
RealLast Aug 24, 2024
eb1bcea
Added missing comments.
RealLast Aug 24, 2024
b716ada
Merge branch 'main' into PDFPagination
PSchmiedmayer Aug 30, 2024
bd5d975
Try LFS Support
PSchmiedmayer Aug 30, 2024
b813492
Update build-and-test.yml
PSchmiedmayer Aug 30, 2024
aa84929
Update build-and-test.yml
PSchmiedmayer Aug 30, 2024
1e0c539
Added new pdf documents for the tests with better spacing.
RealLast Sep 4, 2024
448e0e4
Resolved swiftlint issues.
RealLast Sep 4, 2024
af181aa
Removed leftover code.
RealLast Sep 4, 2024
2697855
Made PDF export throwing if PDF generation fails. A possible exceptio…
RealLast Sep 4, 2024
9194b05
Resolved swiftlint issue.
RealLast Sep 4, 2024
7abf6cc
Introduced ExportConfiguration.FontSettings to enable more precise co…
RealLast Oct 30, 2024
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
RealLast marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ extension ConsentDocument {
///
/// - Returns: The exported consent form in PDF format as a PDFKit `PDFDocument`
@MainActor
func export() async -> PDFKit.PDFDocument? {
func export() async throws -> PDFKit.PDFDocument {
documentExport.signature = signature
documentExport.name = name
#if !os(macOS)
documentExport.signatureImage = blackInkSignatureImage
return await documentExport.export()
return try await documentExport.export()
#else
return await documentExport.export()
return try await documentExport.export()
#endif
}
}
2 changes: 1 addition & 1 deletion Sources/SpeziOnboarding/ConsentView/ConsentDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public struct ConsentDocument: View {
.onChange(of: viewState) {
if case .export = viewState {
Task {
guard let exportedConsent = await export() else {
guard let exportedConsent = try? await export() else {
RealLast marked this conversation as resolved.
Show resolved Hide resolved
viewState = .base(.error(Error.memoryAllocationError))
return
}
Expand Down
RealLast marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
pdfTextContent: PDFAttributedText,
signatureFooter: PDFGroup,
exportTimeStamp: PDFAttributedText? = nil
) async -> PDFKit.PDFDocument? {
) async throws -> PDFKit.PDFDocument {
let document = TPPDF.PDFDocument(format: exportConfiguration.getPDFPageFormat())

if let exportStamp = exportTimeStamp {
Expand All @@ -172,15 +172,13 @@
// Convert TPPDF.PDFDocument to PDFKit.PDFDocument
let generator = PDFGenerator(document: document)

if let data = try? generator.generateData() {
if let pdfKitDocument = PDFKit.PDFDocument(data: data) {
return pdfKitDocument
} else {
return nil
}
} else {
return nil
let data = try generator.generateData()

guard let pdfDocument = PDFKit.PDFDocument(data: data) else {
throw ConsentDocumentExportError.invalidPdfData("PDF data not compatible with PDFDocument")
}

return pdfDocument
}

#if !os(macOS)
Expand All @@ -193,13 +191,13 @@
/// - signatureImage: Signature drawn when signing the document.
/// - Returns: The exported consent form in PDF format as a PDFKit `PDFDocument`
@MainActor
public func export() async -> PDFKit.PDFDocument? {
public func export() async throws -> PDFKit.PDFDocument{

Check failure on line 194 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport+Export.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
let exportTimeStamp = exportConfiguration.includingTimestamp ? exportTimeStamp() : nil
let header = exportHeader()
let pdfTextContent = await exportDocumentContent()
let signature = exportSignature()

return await createDocument(
return try await createDocument(
header: header,
pdfTextContent: pdfTextContent,
signatureFooter: signature,
Expand All @@ -215,13 +213,13 @@
/// - personName: A string containing the name of the person who signed the document.
/// - Returns: The exported consent form in PDF format as a PDFKit `PDFDocument`
@MainActor
public func export() async -> PDFKit.PDFDocument? {
public func export() async throws -> PDFKit.PDFDocument {
let exportTimeStamp = exportConfiguration.includingTimestamp ? exportTimeStamp() : nil
let header = exportHeader()
let pdfTextContent = await exportDocumentContent()
let signature = exportSignature()

return await createDocument(
return try await createDocument(
header: header,
pdfTextContent: pdfTextContent,
signatureFooter: signature,
Expand Down
14 changes: 7 additions & 7 deletions Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SPDX-License-Identifier: MIT
//

@preconcurrency import PDFKit

Check warning on line 9 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'@preconcurrency' attribute on module 'PDFKit' has no effect
import PencilKit
import SwiftUI

Expand All @@ -20,8 +20,8 @@
public static let documentIdentifier = "ConsentDocument"
}

let asyncMarkdown: () async -> Data

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'; this is an error in the Swift 6 language mode

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'; this is an error in the Swift 6 language mode

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'; this is an error in the Swift 6 language mode

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'; this is an error in the Swift 6 language mode

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'

Check warning on line 23 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Release, SpeziOnboarding-visionOS-Release.xcresult, SpeziO... / Test using xcodebuild or run fastlane

stored property 'asyncMarkdown' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type '() async -> Data'
let exportConfiguration: ConsentDocument.ExportConfiguration

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'; this is an error in the Swift 6 language mode

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'; this is an error in the Swift 6 language mode

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'; this is an error in the Swift 6 language mode

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'; this is an error in the Swift 6 language mode

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'

Check warning on line 24 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Release, SpeziOnboarding-visionOS-Release.xcresult, SpeziO... / Test using xcodebuild or run fastlane

stored property 'exportConfiguration' of 'Sendable'-conforming class 'ConsentDocumentExport' has non-sendable type 'ConsentDocument.ExportConfiguration'
var cachedPDF: PDFDocument?

/// An unique identifier for the exported `ConsentDocument`.
Expand All @@ -45,14 +45,14 @@
/// if the `ConsentDocument` has not been previously exported or the `PDFDocument` was not cached.
/// For now, we always require a PDF to be cached to create a ConsentDocumentExport. In the future, we might change this to lazy-PDF loading.
@MainActor public var pdf: PDFDocument {
get async {
if let cached = cachedPDF {
return cached
} else {
cachedPDF = await export()
// If the export failed, return an empty document.
return cachedPDF ?? .init()
get async throws {
if let pdf = cachedPDF {
return pdf
}

let pdf = try await export()
cachedPDF = pdf
return pdf
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// This source file is part of the Stanford Spezi open-source project
//
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

import Foundation

// Error that can occur if PDF export fails in ``ConsentDocumentExport``.
enum ConsentDocumentExportError: LocalizedError {
case invalidPdfData(String)

var errorDescription: String? {
switch self {
case .invalidPdfData:
String(
localized: "Unable to generate valid PDF document from PDF data.",
comment: """
Error thrown if we generated a PDF document using TPPDF,
but were unable to convert the generated data into a PDFDocument.
"""
)
}
}
}
2 changes: 1 addition & 1 deletion Sources/SpeziOnboarding/OnboardingDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


public func configure() {
guard standard is any OnboardingConstraint || standard is any ConsentConstraint else {

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 44 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Release, SpeziOnboarding-visionOS-Release.xcresult, SpeziO... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.
fatalError("A \(type(of: standard).self) must conform to `ConsentConstraint` to process signed consent documents.")
}
}
Expand Down Expand Up @@ -82,9 +82,9 @@
public func store(_ consent: ConsentDocumentExport) async throws {
RealLast marked this conversation as resolved.
Show resolved Hide resolved
if let consentConstraint = standard as? any ConsentConstraint {
try await consentConstraint.store(consent: consent)
} else if let onboardingConstraint = standard as? any OnboardingConstraint {

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 85 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Release, SpeziOnboarding-visionOS-Release.xcresult, SpeziO... / Test using xcodebuild or run fastlane

'OnboardingConstraint' is deprecated: Storing consent documents without an identifier is deprecated.
let pdf = await consent.pdf
let pdf = try await consent.pdf
await onboardingConstraint.store(consent: pdf)

Check warning on line 87 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

'store(consent:)' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 87 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS Latest / Test using xcodebuild or run fastlane

'store(consent:)' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 87 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

'store(consent:)' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 87 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS Latest / Test using xcodebuild or run fastlane

'store(consent:)' is deprecated: Storing consent documents without an identifier is deprecated.

Check warning on line 87 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Release, SpeziOnboarding-visionOS-Release.xcresult, SpeziO... / Test using xcodebuild or run fastlane

'store(consent:)' is deprecated: Storing consent documents without an identifier is deprecated.
} else {
fatalError("A \(type(of: standard).self) must conform to `ConsentConstraint` to process signed consent documents.")
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/SpeziOnboarding/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
}
}
}
},
"Unable to generate valid PDF document from PDF data." : {
"comment" : "Error thrown if we generated a PDF document using TPPDF,\nbut were unable to convert the generated data into a PDFDocument."
}
},
"version" : "1.0"
Expand Down
7 changes: 7 additions & 0 deletions Tests/SpeziOnboardingTests/.gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
#
# This source file is part of the Stanford Spezi open-source project
#
# SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
#
Resources/*.pdf filter=lfs diff=lfs merge=lfs -text
2 changes: 1 addition & 1 deletion Tests/SpeziOnboardingTests/SpeziOnboardingTests.swift
RealLast marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
documentExport.signature = "Stanford"
#endif

if let pdf = await documentExport.export() {
if let pdf = try? await documentExport.export() {
XCTAssert(comparePDFDocuments(pdf1: pdf, pdf2: knownGoodPdf))

Check failure on line 83 in Tests/SpeziOnboardingTests/SpeziOnboardingTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

testPDFExport, XCTAssertTrue failed
} else {
XCTFail("Failed to export PDF from ConsentDocumentExport.")
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/UITests/TestApp/ExampleStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension ExampleStandard: ConsentConstraint {
func store(consent: ConsentDocumentExport) async throws {
// Extract data outside of the MainActor.run block
let documentIdentifier = await consent.documentIdentifier
let pdf = await consent.pdf
let pdf = try await consent.pdf

// Perform operations on the main actor
try await MainActor.run {
Expand Down
Loading