【问题标题】:Display base64 string into webview as PDF将 base64 字符串以 PDF 格式显示到 webview 中
【发布时间】:2017-07-19 09:36:43
【问题描述】:

我有代表PDFbase64 字符串。 我想在 Webview 中显示它,但我不知道如何做好。

我应该如何处理?我需要先将字符串转换为数据吗?

【问题讨论】:

    标签: swift pdf webview


    【解决方案1】:

    请尝试以下代码。

    if let decodeData = NSData(base64EncodedString: base64String, options: .IgnoreUnknownCharacters) {
        yourWebView.loadData(decodeData, MIMEType: "application/pdf", textEncodingName: "utf-8", baseURL: NSURL(fileURLWithPath: ""))
    } // since you don't have url, only encoded String
    

    斯威夫特 4.0

    if let decodeData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters) {
            yourWebView.load(decodeData, mimeType: "application/pdf", textEncodingName: "utf-8", baseURL: URL(fileURLWithPath: ""))
    } // since you don't have url, only encoded String
    

    【讨论】:

    • 当我将我的字符串传递给返回 nil 的 Data(base64Encoded: base64String) :(
    • 这是客观-c
    • 现在检查@KevinSabbe
    • 干得好!我不知道我可以将这个方法与空字符串一起使用!非常感谢@Sanjay,你拯救了我的一天 :)
    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 2017-12-07
    • 2015-11-17
    • 2020-05-10
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多