Monday, 29 July 2019 08:22

How to wrap text around image on Word document in Java

Written by  support iceblue
Rate this item
(0 votes)

This article will show you how to set the wrapping style to adjust the position of the image in Java applications with the help of Spire.Doc for Java.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.documents.TextWrappingType;
import com.spire.doc.fields.DocPicture;

public class ImageWrappingStyle {
    public static void main(String[] args) throws Exception {

        Document doc = new Document();
        doc.loadFromFile("Sample.docx");

        Section sec = doc.getSections().get(0);

        Paragraph para = sec.getParagraphs().get(0);
        DocPicture picture = para.appendPicture("logo.png");

        //Set image width and height
        picture.setWidth(150f);
        picture.setHeight(125f);

        //Set text wrapping style to Behind
        picture.setTextWrappingStyle(TextWrappingStyle.Behind);
        picture.setTextWrappingType(TextWrappingType.Both);

        //Save the document to file
        doc.saveToFile("Output/WrapStyle.docx");
        doc.close();

    }
}

Effective screenshot after setting the wrapping style for image:

How to wrap text around image on Word document in Java

Additional Info

  • tutorial_title: Wrap text around image on Word document in Java
Last modified on Monday, 29 July 2019 08:29