繁体   English   中英

如何在Aspose.Words文档的每一页上插入浮动形状?

[英]How to insert a floating shape on each page of an Aspose.Words document?

我有一个Aspose.Words文件。 我想在文档的每一页上插入一个TextBox Shape。

这是我的文件:

 // Aspose.Words document
 Document document = new Document();

 // The DocumentBuilder
 DocumentBuilder builder = new DocumentBuilder(document);

 builder.insertHtml("Here, there is a big String with a lot of HTML.");

这是我第一页的处理方法:

 Shape textBox = new Shape(document, ShapeType.TEXT_BOX);
 textBox.setWrapType(WrapType.SQUARE);
 // Shape position
 textBox.setDistanceTop(0);
 textBox.setDistanceLeft(42);
 // Shape dimensions
 textBox.setWidth(200);
 textBox.setHeight(20);

 // ... other options useless here.

 // Paragraph, content of the Shape
 Paragraph paragraph = new Paragraph(document);
 Run run = new Run(document);
 run.setText("Here some text.");
 paragraph.appendChild(run);

 textBox.appendChild(paragraph);

 // Now I insert my Shape on the first page.
 builder.moveToDocumentStart();
 builder.insertNode(textBox);

这对于首页非常有效。

我也知道我可以得到的页面数量:

 document.getPageCount();

但是,我不知道如何浏览所有页面。

有什么建议么?

我叫Nayyer,是Aspose的开发人员/技术推广人员。

如果需要在所有页面上显示内容,则必须在“页眉/页脚”区域中移动该内容。 请尝试遵循与如何向文档添加水印类似的方法。 请注意,内容/对象可以放置在页面上的任何位置,但是为了在所有页面上显示内容,内容应仅锚定在页眉/页脚中。

现在要指定形状的位置,请注意,形状具有RelativeHorizo​​ntalPosition属性,如果将其设置为RelativeHorizo​​ntalPosition.Page然后设置Left和Top位置,则可以将其浮动在页面的中心甚至底部(即使它固定在Header中)。

PS,Word女士在运行时只为每个Page重复页眉/页脚中的内容,但是当然只有一个内容副本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM