Search code examples
javajacob

Splitting word document to pages using JACOB


I have been trying to split a word document to pages. A through POC that led to the fact that this cannot be done through Apache POI, and consequently made me resort to JACOB to invoke MS Word as a proxy to achieve such transformation.

I have made some reasonable advancements with my code, now I am able to open a document, search, replace, and so on. However I am unable to get the "page" bookmark

            ActiveXComponent oDocuments = oWord.getPropertyAsComponent("Documents");
        ActiveXComponent oDocument = oDocuments.invokeGetComponent("Open", new Variant(sInputDoc), new Variant(false));
        ActiveXComponent oSelection = oWord.getPropertyAsComponent("Selection");

        ActiveXComponent oBookmarks = oSelection.getPropertyAsComponent("Bookmarks");
        int bookMarksnumber = oBookmarks.getProperty("Count").getInt();
        System.out.println(bookMarksnumber);

This always returns 0 (If the same can be achieved using POI I am open to all suggestions)


Solution

  • use this to achieve bookmarks

    ActiveXComponent oBookmarks = oDocument.getPropertyAsComponent("Bookmarks");