OOo: UNO (Java) TrackedChanges: how to accept (or hide) tracked changes when hiding a document?

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.

+4
source share
1 answer

After spending two days studying the OOo API, I realized that the document was not loaded into the external interface, so this approach does not work. However, you can directly change the document property:

 XPropertySet docProperties = UnoRuntime.queryInterface(XPropertySet.class, document); docProperties.setPropertyValue("RedlineDisplayType", RedlineDisplayType.NONE); 

The property name "RedlineDisplayType" can be found in the RedlinePortion documentation.

+4
source

Source: https://habr.com/ru/post/1398861/


All Articles