My Problem: I write an automated system that needs to read .doc and .odt, performs some operation on it and exports it to pdf again.
Currently that works fine for everything I need, I could solve all problems until this one:
If a user provides a Document that had recorded changes (Redlines) I need to automatically accept all that changes or hide them.
I could solve that one with the code below as long as the OOo is showing on screen. When I launch it hidden, my calls do nothing at all.
So, here is what I do currently:
// 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 current guess is that I cannot call this because being hidden, I have no Frame to call any dispatcher to. But I could not find a way to get the Dispatcher for the Component.
I already tried to dispatch TrackChanges
as well (to FALSE
) but that didn't do it either.
After spending two days understanding the OOo API, I realized that the document isn't loaded in the frontend which is why this approach fails. However, you can modify the document's property directly:
XPropertySet docProperties = UnoRuntime.queryInterface(XPropertySet.class, document);
docProperties.setPropertyValue("RedlineDisplayType", RedlineDisplayType.NONE);
The property name "RedlineDisplayType"
can be found in the RedlinePortion documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With