My problem: I am writing an automated system that needs to read .doc and .odt, performs some operation on it, and again exports it to PDF.
Currently, this works fine for everything I need, I could solve all the problems before that:
If the user provides a document with the recorded changes (Redlines), I need to automatically accept all the changes or hide them.
I could solve this problem with the code below while OOo is showing on screen. When I launch it hidden, my calls do nothing at all.
So here is what I am doing now:
// DO NOT try to cast this to Desktop as com.sun.star.frame.Desktop is NOT a valid class! // keep it as Object and cast it to XDesktop later (via queryInterface) Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, xMCF); // what goes for desktop above is valid for DispatchHelper as well. Object dispatchHelper = xFactory.createInstance("com.sun.star.frame.DispatchHelper"); // the DispatchHelper is the class that handles the interaction with dialogs. XDispatchHelper helper = (XDispatchHelper) UnoRuntime.queryInterface( XDispatchHelper.class, dispatchHelper); XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop); XFrame xFrame = xDesktop.getCurrentFrame(); XDispatchProvider xDispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame); // We issute the Track Changes Dialog (Bearbeiten - Änderungen // Edit - Changes) and tell it // to ACCEPT all changes. PropertyValue[] acceptChanges = new PropertyValue[1]; acceptChanges[0] = new PropertyValue(); acceptChanges[0].Name = "AcceptTrackedChanges"; acceptChanges[0].Value = Boolean.TRUE; helper.executeDispatch(xDispatchProvider, ".uno:AcceptTrackedChanges", "", 0, acceptChanges); // We issue it again to tell it to stop showing changes. PropertyValue[] showChanges = new PropertyValue[1]; showChanges[0] = new PropertyValue(); showChanges[0].Name = "ShowTrackedChanges"; showChanges[0].Value = Boolean.FALSE; helper.executeDispatch(xDispatchProvider, ".uno:ShowTrackedChanges", "", 0, showChanges);
My last assumption is that I cannot call it because, being hidden, I do not have a frame to call any dispatcher. But I could not find a way to get a Dispatcher for a Component.
I already tried to send TrackChanges (before FALSE ), but this also did not.