• <i id='ytkO0'><tr id='ytkO0'><dt id='ytkO0'><q id='ytkO0'><span id='ytkO0'><b id='ytkO0'><form id='ytkO0'><ins id='ytkO0'></ins><ul id='ytkO0'></ul><sub id='ytkO0'></sub></form><legend id='ytkO0'></legend><bdo id='ytkO0'><pre id='ytkO0'><center id='ytkO0'></center></pre></bdo></b><th id='ytkO0'></th></span></q></dt></tr></i><div id='ytkO0'><tfoot id='ytkO0'></tfoot><dl id='ytkO0'><fieldset id='ytkO0'></fieldset></dl></div>

    <legend id='ytkO0'><style id='ytkO0'><dir id='ytkO0'><q id='ytkO0'></q></dir></style></legend>

    <small id='ytkO0'></small><noframes id='ytkO0'>

      <tfoot id='ytkO0'></tfoot>
      • <bdo id='ytkO0'></bdo><ul id='ytkO0'></ul>
      1. 如何使用 base64 字符串制作 PDF 文件?迅速

        How can I make a PDF file using base64 string ? Swift(如何使用 base64 字符串制作 PDF 文件?迅速)

        <small id='c3PbR'></small><noframes id='c3PbR'>

            <tbody id='c3PbR'></tbody>
        1. <i id='c3PbR'><tr id='c3PbR'><dt id='c3PbR'><q id='c3PbR'><span id='c3PbR'><b id='c3PbR'><form id='c3PbR'><ins id='c3PbR'></ins><ul id='c3PbR'></ul><sub id='c3PbR'></sub></form><legend id='c3PbR'></legend><bdo id='c3PbR'><pre id='c3PbR'><center id='c3PbR'></center></pre></bdo></b><th id='c3PbR'></th></span></q></dt></tr></i><div id='c3PbR'><tfoot id='c3PbR'></tfoot><dl id='c3PbR'><fieldset id='c3PbR'></fieldset></dl></div>
        2. <legend id='c3PbR'><style id='c3PbR'><dir id='c3PbR'><q id='c3PbR'></q></dir></style></legend>
            <tfoot id='c3PbR'></tfoot>

                <bdo id='c3PbR'></bdo><ul id='c3PbR'></ul>

                  本文介绍了如何使用 base64 字符串制作 PDF 文件?迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找一种在我的项目目录中保存 PDF 文件的方法,我已经从 Web 服务收到了一个 base 64 pdf 字符串.我是否必须将其转换为 NSData 或类似的东西?

                  I'm looking for a way to save a PDF file on my project directory, I've received a base 64 pdf string from a Web Service yet. Do I have to convert it to NSData or something like that?

                  我是 Swift 编码的新手,但我可以按照您的指示进行操作.

                  I'm new at coding in Swift but I can follow your instructions.

                  我希望你能帮助我.谢谢

                  I hope you can help me. Thanks

                  推荐答案

                  是的,你必须将其转换为Data,然后将其保存到设备上的文档目录中.像这样的功能会起作用:

                  Yes, you have to convert it to Data and then save it to the documents directory on the device. A function like this would work:

                  func saveBase64StringToPDF(_ base64String: String) {
                  
                      guard
                          var documentsURL = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last,
                          let convertedData = Data(base64Encoded: base64String)
                          else {
                          //handle error when getting documents URL
                          return
                      }
                  
                      //name your file however you prefer
                      documentsURL.appendPathComponent("yourFileName.pdf")
                  
                      do {
                          try convertedData.write(to: documentsURL)
                      } catch {
                          //handle write error here
                      }
                  
                      //if you want to get a quick output of where your 
                      //file was saved from the simulator on your machine
                      //just print the documentsURL and go there in Finder
                      print(documentsURL)
                  }
                  

                  这篇关于如何使用 base64 字符串制作 PDF 文件?迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)
                    <i id='YnwLX'><tr id='YnwLX'><dt id='YnwLX'><q id='YnwLX'><span id='YnwLX'><b id='YnwLX'><form id='YnwLX'><ins id='YnwLX'></ins><ul id='YnwLX'></ul><sub id='YnwLX'></sub></form><legend id='YnwLX'></legend><bdo id='YnwLX'><pre id='YnwLX'><center id='YnwLX'></center></pre></bdo></b><th id='YnwLX'></th></span></q></dt></tr></i><div id='YnwLX'><tfoot id='YnwLX'></tfoot><dl id='YnwLX'><fieldset id='YnwLX'></fieldset></dl></div>

                      <small id='YnwLX'></small><noframes id='YnwLX'>

                          <tbody id='YnwLX'></tbody>
                        • <bdo id='YnwLX'></bdo><ul id='YnwLX'></ul>

                          <tfoot id='YnwLX'></tfoot>
                        • <legend id='YnwLX'><style id='YnwLX'><dir id='YnwLX'><q id='YnwLX'></q></dir></style></legend>