Post marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
Post marked as solved with 2 replies, 0 views
Replied In
ShareLink and PDFDocument
So I managed to get it working by extending PDFDocument. This is not a super clean solution, so please feel free to improve it further in the comments!
extension PDFDocument: Transferable {
public static var transferRepresentation: some TransferRepresentation {
DataRepresentation(contentType: .pdf) { pdf in
if let data = pdf.dataRepresentation() {
return data
} else {
return Data()
}
} importing: { data in
if let pdf = PDFDocument(data: data) {
return pdf
} else {
return PDFDocument()
}
}
DataRepresentation(exportedContentType: .pdf) { pdf in
if let data = pdf.dataRepresentation() {
return data
} else {
return Data()
}
}
}
}
And then you can share the PDF document like this:
if let document = document {
ShareLink(item: document, preview: SharePreview("PDF"))
}