import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
public class PdfBase64Example {
public static void main(String[] args) throws Exception {
// 读取PDF文件
Path pdfPath = Paths.get("sample.pdf");
byte[] pdfBytes = Files.readAllBytes(pdfPath);
// 将PDF文件编码为Base64字符
String base64Pdf = Base64.getEncoder().encodeToString(pdfBytes);
System.out.println("Base64 PDF: " + base64Pdf);
}
}