Menu

Insert Image to Doc

Shoaib

Apache POI WP

XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();

String imgFile = "aspose.jpg";
XWPFRun r = p.createRun();

int format = XWPFDocument.PICTURE_TYPE_JPEG;
r.setText(imgFile);
r.addBreak();
r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels

Aspose.Words

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertImage("data/background.jpg");
builder.insertImage("data/background.jpg",
        RelativeHorizontalPosition.MARGIN,
        100,
        RelativeVerticalPosition.MARGIN,
        200,
        200,
        100,
        WrapType.SQUARE);

Download Source Code
Many more examples are available at Aspose Docs


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.