/**
* BufferedImage转成 PDFbase64
*
* @param bufferedImage
* @return
* @throws IOException
*/
public static String getBufferedImageToPDFBase64(BufferedImage bufferedImage) throws IOException, BadElementException {
ByteArrayOutputStream baos = null;
//转base64 io流
baos = new ByteArrayOutputStream();
//io流
ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream();
String base64Img = null;
// 写入流中
ImageIO.write(bufferedImage, "png", baos);
baos.flush();
Image image = Image.getInstance(baos.toByteArray());
Document document = new Document();
//设置文档页边距
document.setMargins(0, 0, 0, 0);
try {
PdfWriter.getInstance(document, pdfbaos);
//打开文档
document.open();
//获取图片的宽高
float imageHeight = image.getScaledHeight();
float imageWidth = image.getScal
BufferedImage与PDF的base64字符串互转
最新推荐文章于 2024-09-03 14:33:49 发布