【问题标题】:How to insert a floating shape on each page of an Aspose.Words document?如何在 Aspose.Words 文档的每一页上插入浮动形状?
【发布时间】:2012-10-10 17:57:09
【问题描述】:

我有一个 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();

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

有什么建议吗?

【问题讨论】:

    标签: java aspose


    【解决方案1】:

    我叫 Nayyer,是 Aspose 的支持开发人员/技术布道者。

    如果您需要在所有页面上显示某些内容,则必须将该内容移动到页眉/页脚区域。请尝试使用类似于How to add Watermark to document 的方法。请注意,内容/对象可以放置在页面上的任何位置,但为了在所有页面上显示某些内容,内容应该锚定在页眉/页脚内。

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

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

    【讨论】:

      猜你喜欢
      • 2015-05-05
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多