| | |
| | | Base64.Decoder decoder = Base64.getDecoder(); |
| | | byte[] imageByte = decoder.decode(url); |
| | | InputStream stream = new ByteArrayInputStream(imageByte); |
| | | File tempFile = FileUtil.createTempFile("/usr/local/project/file/temp", ".jpg", true); |
| | | // File tempFile = File.createTempFile("/usr/local/project/file/temp", ".jpg"); |
| | | // tempFile.deleteOnExit(); // 程序结束时删除文件 |
| | | // File tempFile = FileUtil.createTempFile("/usr/local/project/file/temp", ".jpg", true); |
| | | File tempFile = File.createTempFile("/usr/local/project/file/temp", ".jpg"); |
| | | tempFile.deleteOnExit(); // 程序结束时删除文件 |
| | | |
| | | try (OutputStream out = new FileOutputStream(tempFile); |
| | | InputStream in = stream) { |
| | |
| | | if (text != null && text.contains("picture")) { |
| | | run.setText("", 0); // 清除占位符文本 |
| | | run.addPicture( |
| | | new FileInputStream(new File("/usr/local/project/file/sign.jpg")), XWPFDocument.PICTURE_TYPE_JPEG, |
| | | "/usr/local/project/file/sign.jpg", |
| | | new FileInputStream(tempFile), XWPFDocument.PICTURE_TYPE_JPEG, |
| | | tempFile.getName(), |
| | | Units.toEMU(60), |
| | | Units.toEMU(30)); // 插入图片 |
| | | } |