C#中pdf文件与base64字符串的相互转换

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);

相关推荐
MrSYJ4 分钟前
UserDetailService是在什么环节生效的,为什么自定义之后就能被识别
java·spring boot·后端
科大饭桶1 小时前
C++入门自学Day11-- String, Vector, List 复习
c语言·开发语言·数据结构·c++·容器
范范之交1 小时前
JavaScript基础语法two
开发语言·前端·javascript
Felven1 小时前
C. Game of Mathletes
c语言·开发语言
long3161 小时前
构建者设计模式 Builder
java·后端·学习·设计模式
吐个泡泡v1 小时前
Maven 核心命令详解:compile、exec:java、package 与 IDE Reload 机制深度解析
java·ide·maven·mvn compile
点云SLAM1 小时前
C++中内存池(Memory Pool)详解和完整示例
开发语言·c++·内存管理·内存池·new/delete·malloc/free
天上掉下来个程小白1 小时前
微服务-01.导入黑马商城
java·微服务·架构
Noii.2 小时前
Spring Boot初级概念及自动配置原理
java·spring boot·后端
探索java2 小时前
Tomcat Server 组件原理
java·后端·tomcat