com.aspose.words

Class RelativeHorizontalPosition

  • java.lang.Object
    • com.aspose.words.RelativeHorizontalPosition
public class RelativeHorizontalPosition 
extends java.lang.Object

Utility class containing constants. Specifies to what the horizontal position of a shape or text frame is relative.

Example:

Shows how to insert a floating image in the middle of a page.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// By default, the image is inline
Shape shape = builder.insertImage(getImageDir() + "Logo.jpg");

// Make the image float, put it behind text and center on the page
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setVerticalAlignment(VerticalAlignment.CENTER);

doc.save(getArtifactsDir() + "Image.CreateFloatingPageCenter.docx");

Example:

Shows how to insert an image, and use it as a watermark.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert the image into the header so that it will be visible on every page.
BufferedImage image = ImageIO.read(new File(getImageDir() + "Transparent background logo.png"));
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
Shape shape = builder.insertImage(image);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);

// Place the image at the center of the page.
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2.0);
shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2.0);

doc.save(getArtifactsDir() + "DocumentBuilder.InsertWatermark.docx");
See Also:
ShapeBase.RelativeHorizontalPosition

Field Summary
static final intMARGIN = 0
Specifies that the horizontal positioning shall be relative to the page margins.
static final intPAGE = 1
The object is positioned relative to the left edge of the page.
static final intCOLUMN = 2
The object is positioned relative to the left side of the column.
static final intCHARACTER = 3
The object is positioned relative to the left side of the paragraph.
static final intLEFT_MARGIN = 4
Specifies that the horizontal positioning shall be relative to the left margin of the page.
static final intRIGHT_MARGIN = 5
Specifies that the horizontal positioning shall be relative to the right margin of the page.
static final intINSIDE_MARGIN = 6
Specifies that the horizontal positioning shall be relative to the inside margin of the current page (the left margin on odd pages, right on even pages).
static final intOUTSIDE_MARGIN = 7
Specifies that the horizontal positioning shall be relative to the outside margin of the current page (the right margin on odd pages, left on even pages).
static final intDEFAULT = 2
Default value is COLUMN.
 

    • Field Detail

      • MARGIN = 0

        public static final int MARGIN
        Specifies that the horizontal positioning shall be relative to the page margins.
      • PAGE = 1

        public static final int PAGE
        The object is positioned relative to the left edge of the page.
      • COLUMN = 2

        public static final int COLUMN
        The object is positioned relative to the left side of the column.
      • CHARACTER = 3

        public static final int CHARACTER
        The object is positioned relative to the left side of the paragraph.
      • LEFT_MARGIN = 4

        public static final int LEFT_MARGIN
        Specifies that the horizontal positioning shall be relative to the left margin of the page.
      • RIGHT_MARGIN = 5

        public static final int RIGHT_MARGIN
        Specifies that the horizontal positioning shall be relative to the right margin of the page.
      • INSIDE_MARGIN = 6

        public static final int INSIDE_MARGIN
        Specifies that the horizontal positioning shall be relative to the inside margin of the current page (the left margin on odd pages, right on even pages).
      • OUTSIDE_MARGIN = 7

        public static final int OUTSIDE_MARGIN
        Specifies that the horizontal positioning shall be relative to the outside margin of the current page (the right margin on odd pages, left on even pages).
      • DEFAULT = 2

        public static final int DEFAULT
        Default value is COLUMN.