【问题标题】:Xamarin Android Convert Byte array to PDF fileXamarin Android 将字节数组转换为 PDF 文件
【发布时间】:2016-04-14 19:29:22
【问题描述】:

我想将字节数组转换为 PDF 文件并将其存储到内部存储中。我正在使用下面提到的代码,它说 PDF 格式无效。

private void ConvertToFile(string fileName , string filePath,Byte[] Bytes){



        if (!File.Exists (filePath)) {
            File.WriteAllBytes(filePath, Bytes);

        }

    }

【问题讨论】:

  • 字节从何而来?您确定它是有效的 PDF 文件吗?
  • 是的。我已经通过Android本机尝试过它,但它不适用于Xamarin。它来自WS
  • 我也有同样的问题,您找到 Xamarin 表单的任何解决方案了吗?

标签: android xamarin bytearray file-handling


【解决方案1】:

首先,您从应用程序中的 Web 服务获取字节数据。然后给出各自的绝对路径(我在下面的代码中的下载文件夹中设置了内部存储路径)。之后 WriteAllBytes 是在这里将字节转换为 pdf 的内置函数:

 WebService ws= new Android.WebService();
 byte[] getbytedata= ws.YourMethodName();
 string directory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
 string file = Path.Combine(directory, "temp.pdf");
 System.IO.File.WriteAllBytes(file, getbytedata);

希望这会奏效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-16
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2013-04-12
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多