RelativeHorizontalPosition

RelativeHorizontalPosition enumeration

指定形状或文本框的水平位置的相对位置。

public enum RelativeHorizontalPosition

价值观

姓名价值描述
Margin0指定水平定位应相对于页边距。
Page1对象相对于页面左边缘定位。
Column2该对象相对于列的左侧定位。
Character3对象相对于段落左侧定位。
LeftMargin4指定水平定位应相对于页面左边距。
RightMargin5指定水平定位应相对于页面的右边距。
InsideMargin6指定水平定位应相对于 当前页的内边距(奇数页的左边距,偶数页的右边距)。
OutsideMargin7指定水平定位应相对于 当前页的外边距(奇数页的右边距,偶数页的左边距)。
Default2默认值为Column.

例子

展示如何将浮动图像插入到页面的中心。

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

// 插入一个浮动图像,该图像将出现在重叠文本后面,并将其与页面的中心对齐。
Shape shape = builder.InsertImage(ImageDir + "Logo.jpg");
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.VerticalAlignment = VerticalAlignment.Center;

doc.Save(ArtifactsDir + "Image.CreateFloatingPageCenter.docx");

展示如何插入图像并将其用作水印。

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

// 将图像插入页眉,以便它在每个页面上都可见。
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(ImageDir + "Transparent background logo.png");
shape.WrapType = WrapType.None;
shape.BehindText = true;

// 将图像放置在页面的中心。
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.Left = (builder.PageSetup.PageWidth - shape.Width) / 2;
shape.Top = (builder.PageSetup.PageHeight - shape.Height) / 2;

doc.Save(ArtifactsDir + "DocumentBuilder.InsertWatermark.docx");

也可以看看