1、pdf文件转换为base64字符串
private string GetBase64StringByPdf(string file)
{
byte[] bytes = null;
FileStream fileStream = new FileStream(file, FileMode.Open);
bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
return Convert.ToBase64String(bytes);
}
//这里是你的pdf路径
string bytes=GetBase64StringByPdf("E:\\PDF文件\\测试1.pdf");
2、base64字符串转换为pdf
public string Base64StringToPdf(string base64String, string filePath)
{
byte[] pdfBytes = Convert.FromBase64String(base64String);
File.WriteAllBytes(filePath, pdfBytes);
return filePath;
}
//使用方法
string base64string="这里是base64字符串";
string filepath="你要写入字符流的pdf";
//得到pdf
string pdf=GetBase64StringByPdf(base64string,filepath);