Вот код: < /p>
Код: Выделить всё
public class JavaApplication {
public static void main(String[] args) throws WriterException, IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode("113", BarcodeFormat.QR_CODE, 100, 100);
BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(qrImage, "png", baos);
baos.flush();
byte[] imageBytes = baos.toByteArray();
baos.close();
String filePath = "C:\\Users\\Desktop\\123.doc";
// Открытие существующего документа
try (FileInputStream fis = new FileInputStream(filePath);
HWPFDocument document = new HWPFDocument(fis)) {
Range range = document.getRange();
int pictureIndex = document.addPicture(imageBytes, PictureType.PNG);
range.insertAfter(pictureIndex, PictureType.PNG);
// Сохранение документа
try (FileOutputStream fos = new FileOutputStream(filePath)) {
document.write(fos);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... g-poi-hwpf
Мобильная версия