BJH*_*ios 13
是的,您必须将其转换为数据,然后将其保存到设备上的文档目录中.像这样的函数可以工作:
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)
}
Run Code Online (Sandbox Code Playgroud)
你想要这样的东西:
if let d = Data(base64Encoded: base64string) {
do {
try d.write(to: outputFile)
} catch {
// handle error
}
}
Run Code Online (Sandbox Code Playgroud)
其中base64string是 base64 PDF 字符串,outputFile是 PDF 输出文件的 URL。
| 归档时间: |
|
| 查看次数: |
6135 次 |
| 最近记录: |