How to remove internal margin of textbox using Java

Hi,

I would like to know if it is possible to remove all margins for a text field whose default value in MSWord is 0.1 inch.The problem with this is that if we set the input text width to 0.2 inch and we want to add a photo with a width of 0.1 of them, it can’t be added. (msword can render it? )

@aolo23

Could you please ZIP and attach your input and expected output Word documents here for our reference? We will then provide you more information about your query.

Code:

try {
        final Document doc = new Document();
        final DocumentBuilder documentBuilder = new DocumentBuilder(doc);
        /* Size  324 x 7.2  pt */
        final FileInputStream fis = new FileInputStream(System.getProperty("user.dir").concat(File.separator).concat("SLG_9.svg"));
        double oneTenthOfInch =  7.2D;

                Shape rootShape = documentBuilder.insertShape(ShapeType.TEXT_BOX, 324,oneTenthOfInch*2 );
                rootShape.setWrapType(WrapType.NONE);
                rootShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
                rootShape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);

                final Shape img = documentBuilder.insertImage(fis);
                img.setHeight(oneTenthOfInch);
                img.setWidth(320);
                img.setLeft(0);
                img.setTop(0);
                img.setDistanceLeft(50);
                img.setDistanceTop(50);

                rootShape.getLastParagraph().appendChild(img);

                documentBuilder.getDocument().save(System.getProperty("user.dir").concat(File.separator).concat("out.docx"));
            } catch (Exception e) {
                e.printStackTrace();
            }

The sizes have been chosen so that they fit perfectly but…

Current state:
png1.png (8.4 KB)
Expected result::
png2.png (7.6 KB)

Used image:
SLG_9.zip (888 Bytes)

So how can i remove all margins?

@aolo23

The Shape.TextBox property defines attributes that specify how text is displayed in a shape.
Please use the following modified code to get the desired output.

final Document doc = new Document();
final DocumentBuilder documentBuilder = new DocumentBuilder(doc);

double oneTenthOfInch =  7.2D;

Shape rootShape = documentBuilder.insertShape(ShapeType.TEXT_BOX, 324,oneTenthOfInch*2 );
rootShape.setWrapType(WrapType.NONE);
rootShape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
rootShape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
rootShape.getTextBox().setInternalMarginRight(0);
rootShape.getTextBox().setInternalMarginLeft(0);
rootShape.getTextBox().setInternalMarginTop(0);
rootShape.getTextBox().setInternalMarginBottom(0);

final Shape img = documentBuilder.insertImage(MyDir + "SLG_9.svg");
img.setHeight(oneTenthOfInch);
img.setWidth(320);
img.setLeft(0);
img.setTop(0);
img.setDistanceLeft(50);
img.setDistanceTop(50);

rootShape.getLastParagraph().appendChild(img);

doc.save(MyDir + "20.6.docx");