Search in sources :

Example 6 with Bookmark

use of org.apache.poi.hwpf.usermodel.Bookmark in project poi by apache.

the class TestBookmarksTables method test.

public void test() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
    Bookmarks bookmarks = doc.getBookmarks();
    assertEquals(1, bookmarks.getBookmarksCount());
    Bookmark bookmark = bookmarks.getBookmark(0);
    assertEquals("userref", bookmark.getName());
    assertEquals(27, bookmark.getStart());
    assertEquals(38, bookmark.getEnd());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Bookmarks(org.apache.poi.hwpf.usermodel.Bookmarks) Bookmark(org.apache.poi.hwpf.usermodel.Bookmark)

Example 7 with Bookmark

use of org.apache.poi.hwpf.usermodel.Bookmark in project poi by apache.

the class TestBookmarksTables method testReplaceTextBefore.

public void testReplaceTextBefore() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
    Bookmark bookmark = doc.getBookmarks().getBookmark(0);
    Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
    range.replaceText("1destin2ation3", false);
    bookmark = doc.getBookmarks().getBookmark(0);
    assertEquals("userref", bookmark.getName());
    assertEquals(27, bookmark.getStart());
    assertEquals(41, bookmark.getEnd());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Bookmark(org.apache.poi.hwpf.usermodel.Bookmark) Range(org.apache.poi.hwpf.usermodel.Range)

Example 8 with Bookmark

use of org.apache.poi.hwpf.usermodel.Bookmark in project poi by apache.

the class WordToFoConverter method processBookmarks.

@Override
protected void processBookmarks(HWPFDocumentCore wordDocument, Element currentBlock, Range range, int currentTableLevel, List<Bookmark> rangeBookmarks) {
    Element parent = currentBlock;
    for (Bookmark bookmark : rangeBookmarks) {
        Element bookmarkElement = foDocumentFacade.createInline();
        final String idName = "bookmark_" + bookmark.getName();
        // make sure ID used once
        if (setId(bookmarkElement, idName)) {
            /*
                 * if it just empty fo:inline without "id" attribute doesn't
                 * making sense to add it to DOM
                 */
            parent.appendChild(bookmarkElement);
            parent = bookmarkElement;
        }
    }
    if (range != null)
        processCharacters(wordDocument, currentTableLevel, range, parent);
}
Also used : Bookmark(org.apache.poi.hwpf.usermodel.Bookmark) Element(org.w3c.dom.Element)

Aggregations

Bookmark (org.apache.poi.hwpf.usermodel.Bookmark)8 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)6 Range (org.apache.poi.hwpf.usermodel.Range)4 Bookmarks (org.apache.poi.hwpf.usermodel.Bookmarks)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CharacterRun (org.apache.poi.hwpf.usermodel.CharacterRun)1 Field (org.apache.poi.hwpf.usermodel.Field)1 HWPFList (org.apache.poi.hwpf.usermodel.HWPFList)1 Picture (org.apache.poi.hwpf.usermodel.Picture)1