import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
* 用于PDF与Base64之间的转换
* Created by Administrator on 2018/12/5 0005.
*/
public class PDFAndBase64ConvertUtil {
/**
* 将base64字符串转换为PDF在显示到页面中
* @param base64String
* @param httpServletResponse
*/
public static void base64StringToPDFToPage(String base64String, HttpServletResponse httpServletResponse){
BASE64Decoder decoder = new BASE64Decoder();
ByteArrayOutputStream baos = null;
ServletOutputStream sos = null;
try {
byte[] bytes = decoder.decodeBuffer(base64String);
baos = new ByteArrayOutputStream();
baos.write(bytes); //把byte写进输出流里
if (baos != null) {
httpServletResponse.setContentType("application/pdf");
pdf与base64相互转换的工具类
最新推荐文章于 2024-06-24 17:13:49 发布
本文介绍了一个用于在Java中进行PDF文件与Base64字符串之间转换的工具类。通过这个工具,可以方便地将PDF文档编码为Base64字符串,也可以将Base64编码的数据解码并保存为PDF文件,适用于在Web应用中进行数据传输和存储。
摘要由CSDN通过智能技术生成