String
RPC サーバーからを含む応答を受信しています。これString
は にPDF
変換されたString
です。私のアプリでは、この文字列をファイルに戻す必要がありPDF
ます。ここスタックでいくつかのソリューションを試しましたが、うまくいきませんでした。
問題は、文字列をCGPDFDocument
. ここで何が間違っていますか?
これは私が現在持っているコードです。
final class PdfGenerator: PdfGeneratorInterface {
// MARK: PdfGeneratorProtocol
func generatePdf(string: String) throws -> CGPDFDocument {
guard let
data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false),
cfData = CFDataCreate(kCFAllocatorDefault, UnsafePointer<UInt8>(data.bytes), data.length)
else {
throw PdfGeneratorException.UnsupportedFormatException
}
let cgDataProvider = CGDataProviderCreateWithCFData(cfData)
guard let cgPDFDocument = CGPDFDocumentCreateWithProvider(cgDataProvider) else {
throw PdfGeneratorException.UnsupportedFormatException
}
return cgPDFDocument
}
}
PDF 文字列の内容:
https://gist.github.com/Combidi/fa53f2d74e7ae177bb3885d5d640c13c
ありがとう