有一份需要签名的word文件,需要签名的位置有多个。我需要解析文档内容,比如:签名____。当我获取到这个签名____时,能否获取这段内容在文档当前页的坐标位置?如果word无法实现的话,转换成pdf格式的文件能否实现?
@Maiden 您可以使用LayoutCollector和LayoutEnumerator类来获取文档中节点的布局信息。 例如以下代码获取文档中书签的布局信息:
Document doc = new Document("C:\\Temp\\in.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
// Get layout information of the bookmarks.
for (Bookmark bk : doc.getRange().getBookmarks())
{
System.out.println("Bookmark name: " + bk.getName());
System.out.println("Bookmark start page: " + collector.getStartPageIndex(bk.getBookmarkStart()));
System.out.println("Bookmark end page: " + collector.getEndPageIndex(bk.getBookmarkEnd()));
// Use LayoutEnumerator to calculate rectangle ocupped by the bookmark.
// Code is simplified and handles only situation when whole bookmark is on page.
enumerator.setCurrent(collector.getEntity(bk.getBookmarkStart()));
// Print bounding box of the BookmarkStart
Rectangle2D rect = enumerator.getRectangle();
System.out.println("Page:" + enumerator.getPageIndex() + " X=" + rect.getX() + "; Y=" + rect.getY() + "; Width=" + rect.getWidth() + "; Height=" + rect.getHeight());
// Do the same for the bookmark end.
enumerator.setCurrent(collector.getEntity(bk.getBookmarkEnd()));
rect = enumerator.getRectangle();
System.out.println("Page:" + enumerator.getPageIndex() + " X=" + rect.getX() + "; Y=" + rect.getY() + "; Width=" + rect.getWidth() + "; Height=" + rect.getHeight());
// If you need to calculate bounding box of the whole area ocuppied by bookmark,
// you can calculate it as union of the start and end lines
// if the bookmark start and end are located on the same page and the same txt column.
// Otherwise it will be required to add additional logic to calculate bounding box
// of bookmark' located on different pages or text columns
System.out.println("=============================");
}
另外,请参阅我们的文档以了解如何使用签名行:
https://docs.aspose.com/words/net/working-with-digital-signatures/