【发布时间】:2017-09-27 15:50:21
【问题描述】:
我想获取经过 Base64 编码并以字符串形式呈现的 PDF 文件。 一开始我是通过这个方法在手机本地保存文件,并返回文件的路径:
byte[] byteBuffer = Encoding.UTF8.GetBytes(pdfString);
public string SaveBinary(string filename, byte[] bytes)
{
string filepath = GetFilePath(filename);
if (File.Exists((filepath)))
{
File.Delete(filepath);
}
File.WriteAllBytes(filepath, bytes);
return filepath;
}
string GetFilePath(string filename)
{
return Path.Combine(GetDocsPath(), filename);
}
string GetDocsPath()
{
return System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
}
然后我尝试在浏览器中打开 PDF,但没有任何反应。
string filename = DependencyService.Get<IFileWorker>().SaveBinary($"name.pdf", byteBuffer);
try
{
Device.OpenUri(new Uri(filename));
【问题讨论】:
标签: c# pdf xamarin xamarin.forms base64