简体   繁体   English

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

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

I have an Aspose.Words document. 我有一个Aspose.Words文件。 I would like to insert a TextBox Shape on each page of my document. 我想在文档的每一页上插入一个TextBox Shape。

This is my document: 这是我的文件:

 // 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.");

This is how I do it for the first page: 这是我第一页的处理方法:

 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);

This is working great for the first page. 这对于首页非常有效。

I also know that I can get the number of pages doing: 我也知道我可以得到的页面数量:

 document.getPageCount();

However I do not know how to go through all the pages. 但是,我不知道如何浏览所有页面。

Any suggestions? 有什么建议么?

my name is Nayyer and I am support developer/technical evangelist at Aspose. 我叫Nayyer,是Aspose的开发人员/技术推广人员。

If you need something to display on all pages, then you must have to move that content in Headers/Footers area. 如果需要在所有页面上显示内容,则必须在“页眉/页脚”区域中移动该内容。 Please try following the approach similar to How to add Watermark to document . 请尝试遵循与如何向文档添加水印类似的方法。 Please note that content/object can be placed anywahere on the page but in order to display something on all pages, the content should just be anchored inside header/footers. 请注意,内容/对象可以放置在页面上的任何位置,但是为了在所有页面上显示内容,内容应仅锚定在页眉/页脚中。

Now concerning to specifying the location for shape, please note that shapes have RelativeHorizontalPosition property and if you set this to RelativeHorizontalPosition.Page and then set the Left and Top positions, you can float this anywhere at the center or even at the bottom of Page (Even though it is anchored inside Header). 现在要指定形状的位置,请注意,形状具有RelativeHorizo​​ntalPosition属性,如果将其设置为RelativeHorizo​​ntalPosition.Page然后设置Left和Top位置,则可以将其浮动在页面的中心甚至底部(即使它固定在Header中)。

PS, Ms Word just repeats whatever is inside header/footer for every Page at run-time, but of course there is only a single copy of content. PS,Word女士在运行时只为每个Page重复页眉/页脚中的内容,但是当然只有一个内容副本。

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

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