0
点赞
收藏
分享

微信扫一扫

c# - - - pdf 文件转 base64 字符串

c# - - - pdf 文件转 base64 字符串

pdf 文件转 base64 字符串

1.1 pdf 文件转 base64 字符串

// 读取 pdf 文件转 base64 字符串
byte[] bytes = System.IO.File.ReadAllBytes("测试.pdf");
string base64String = Convert.ToBase64String(bytes);
Console.WriteLine(base64String);

效果:

image.png

1.2 base64 字符串转 pdf 文件

string base64String = "JVBERi0xLjcKJcKzx9gNCjM...";
// 保存为 pdf 文件
byte[] pdf =  Convert.FromBase64String(base64String.Replace("data:application/pdf;base64,", "")); // 去除 base64 字符串中可能存在的数据 URI 前缀
File.WriteAllBytes("new.pdf", pdf);
举报

相关推荐

0 条评论