Get all Annotations/Comments/Notes
Get all Annotations/Comments/Notes
How to get all Annotations in XTextDocument?
Libre Office 7.6 on Windows 11.
Re: Get all Annotations/Comments/Notes
Annotations are special types of TextFields. MRI records the following:
[Tutorial] Introduction into object inspection with MRI
Code: Select all
Sub Snippet
oTextFields = ThisComponent.getTextFields()
oObj2 = oTextFields.createEnumeration()
oObj3 = oObj2.nextElement()
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Get all Annotations/Comments/Notes
The annotations will support the com.sun.star.text.textfield.Annotation service.
https://www.openoffice.org/api/docs/com ... le-ix.html
https://www.openoffice.org/api/docs/com ... le-ix.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
- Jurassic Pork
- Posts: 24
- Joined: Wed Oct 25, 2017 7:55 am
- Location: France
Re: Get all Annotations/Comments/Notes
Hello,
you can try something like this :
CreateDbgDlg create a non modal dialogbox (code here by JeJe) to display string from basic code with procedure DebugPrint
Friendly, J.P
you can try something like this :
Code: Select all
Sub EnumAnnotations
Dim oTextFields as Object, oTextField As Object
CreateDbgDlg
oTextFields = ThisComponent.getTextFields()
for each oTextField in oTextFields
if oTextField.supportsService("com.sun.star.text.textfield.Annotation") then
DebugPrint "===== " + oTextField.Author + ": " + _
Format(CDateFromUnoDateTime(oTextField.DateTimeValue), _
"d MMM yyyy hh:mm:ss") + " ====="
DebugPrint oTextField.Content
end If
Next
End Sub
Friendly, J.P
OpenOffice 4.1.14 , LibreOffice 7.6.2.1 on Windows 11/ LibreOffice 7.3.7 on Lubuntu 22.04
Re: Get all Annotations/Comments/Notes
To collect all the annotations contained in a Writer document (even if nested into any textcontent objects there) is simple. A next solution using the Basic object 'Collection' you find in the attached example:
Also: The current LibO version 24.2 has a related bug https://bugs.documentfoundation.org/sho ... ?id=160138. It thwaits an attempt to get the number of the page containing the field. V 7.5 does it well AOO versions also do.
It will hopefully soon be fixed.
An open question is how to make reasonable use of the result. Also: The current LibO version 24.2 has a related bug https://bugs.documentfoundation.org/sho ... ?id=160138. It thwaits an attempt to get the number of the page containing the field. V 7.5 does it well AOO versions also do.
It will hopefully soon be fixed.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Get all Annotations/Comments/Notes
First of all, I want to express my sincere gratitude for everyone's enthusiastic assistance.
Just as Lupp said, 'how to make reasonable use of the result?'
You have already helped me find the method to query annotations. Now, let me describe my specific requirement. I want to select and copy the content pointed to by an annotation by clicking on it, namely the content at the anchor of the annotation. Then, I intend to paste it into another location within the document, or even into a different document.
Currently, my challenge lies in how to implement the listening of mouse click events on annotations, so as to identify which annotation I have clicked on, and then...
Just as Lupp said, 'how to make reasonable use of the result?'
You have already helped me find the method to query annotations. Now, let me describe my specific requirement. I want to select and copy the content pointed to by an annotation by clicking on it, namely the content at the anchor of the annotation. Then, I intend to paste it into another location within the document, or even into a different document.
Currently, my challenge lies in how to implement the listening of mouse click events on annotations, so as to identify which annotation I have clicked on, and then...
Libre Office 7.6 on Windows 11.
Re: Get all Annotations/Comments/Notes
Code: Select all
with thiscomponent.currentcontroller
.select .viewcursor.textfield.anchor
end with
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Get all Annotations/Comments/Notes
My experiments with Annotations (not in this thread) showed that all attempts to handle annotations (whether by extraction or merely listing) returned the Annotation nearest the end of the file, then all other annotations in order from the beginning of the file. Hubert Lambert suggested sorting them by their field anchor
viewtopic.php?p=495327#p495327
which worked, but it is an extra step. It would be nice if they were returned in strict order in the document - I can see no reason for this out-of-order return.
viewtopic.php?p=495327#p495327
which worked, but it is an extra step. It would be nice if they were returned in strict order in the document - I can see no reason for this out-of-order return.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Get all Annotations/Comments/Notes
Code: Select all
XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
XTextField xTextField = UnoRuntime.queryInterface(XTextField.class, xViewCursor);
Libre Office 7.6 on Windows 11.
Re: Get all Annotations/Comments/Notes
If the viewcursor isn't in a textfield you will get null.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Get all Annotations/Comments/Notes
I has comfirmed that the viewCursor is in the annotation area,but I still get "null" return.
Libre Office 7.6 on Windows 11.
Re: Get all Annotations/Comments/Notes
My code selects the anchor fine for me in LO as well as OO.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Get all Annotations/Comments/Notes
I took the time to go a bit deeper into this, and must report that it wasn't just fun.
There are versions that accept anchors with non-empty strings, others do not.
With the most recent version of LibO (24.2) you cannot even select the anchor of an annotation, by user code, and therefore you cant't get positioning information with the help of the ViewCursor.
Many versions are stacking the annotations along the margin in a really funny way ...
What I could actually get depending on the version's bugs and regressions is contained in the attached demo. It uses a dedicated spreadsheet to gather and to sort the info about the annotations contained in a Writer document. If positioning information was not accessible, the sorting makes no sense, of course.
===Editing===
Sorry. I hadn't updated the Basic code on the document's pages.
I now attach the updated version. obsolete:
There are versions that accept anchors with non-empty strings, others do not.
With the most recent version of LibO (24.2) you cannot even select the anchor of an annotation, by user code, and therefore you cant't get positioning information with the help of the ViewCursor.
Many versions are stacking the annotations along the margin in a really funny way ...
What I could actually get depending on the version's bugs and regressions is contained in the attached demo. It uses a dedicated spreadsheet to gather and to sort the info about the annotations contained in a Writer document. If positioning information was not accessible, the sorting makes no sense, of course.
===Editing===
Sorry. I hadn't updated the Basic code on the document's pages.
I now attach the updated version. obsolete:
Last edited by Lupp on Mon Mar 11, 2024 11:42 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Get all Annotations/Comments/Notes
If fhere are versions where the viewcursor returns null for the textfield - then I don't see how you can do anything.
If its just getting the anchor that fails, then you could enumerate all the paragraphs and text portions in the document till you find the matching textfield - that would be very slow and cumbersome.
A workaround might be to mark the anchor in some way so you can easily go to it - a bookmark or a unique number (like a footnote uses) which could be hidden text or non visible white text.
A document property could be used to store information pairs that match the anchor text or identifier to some textfield property identifying it.
Edit:
Or, most easily, you could revert to a version where there isn't this problem.
If its just getting the anchor that fails, then you could enumerate all the paragraphs and text portions in the document till you find the matching textfield - that would be very slow and cumbersome.
A workaround might be to mark the anchor in some way so you can easily go to it - a bookmark or a unique number (like a footnote uses) which could be hidden text or non visible white text.
A document property could be used to store information pairs that match the anchor text or identifier to some textfield property identifying it.
Edit:
Or, most easily, you could revert to a version where there isn't this problem.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Get all Annotations/Comments/Notes
I was fiddling around tonight (not very seriously, waiting for a large document to download over a very slow connection).
Andrew Pitonyak, in his personal macro libraries, at
https://www.pitonyak.org/AndrewPersonalLibs.odt
gives some macros for handling Annotations.
I have not inspected these in detail, and not yet tried them, but I think they may solve some of the Annotation problems Lupp and JeJe have mentioned. Also, possibly, the problem of a listing of Annotations starting with the last and then the Annotations in the document in sequence.
Andrew Pitonyak, in his personal macro libraries, at
https://www.pitonyak.org/AndrewPersonalLibs.odt
gives some macros for handling Annotations.
I have not inspected these in detail, and not yet tried them, but I think they may solve some of the Annotation problems Lupp and JeJe have mentioned. Also, possibly, the problem of a listing of Annotations starting with the last and then the Annotations in the document in sequence.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Get all Annotations/Comments/Notes
To be clear: I didn't comment on JeJe's posts.
The ViewCursor wasn't a means for me to get a grip on any textfield. I went through all the textfields, jumped over different subtypes, and selected the ...textfield.Annotation objects to be able to get positioning information (page, position.Y, position.X) about the anchor with the help of the ViewCursor.
Who runs my demo with a not too buggy version (like LibO 7.5 e.g.) will soon see how it works.
V24.2 has the mentioned bug and can therefore not sort the results reasonably.
The ViewCursor wasn't a means for me to get a grip on any textfield. I went through all the textfields, jumped over different subtypes, and selected the ...textfield.Annotation objects to be able to get positioning information (page, position.Y, position.X) about the anchor with the help of the ViewCursor.
Who runs my demo with a not too buggy version (like LibO 7.5 e.g.) will soon see how it works.
V24.2 has the mentioned bug and can therefore not sort the results reasonably.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Get all Annotations/Comments/Notes
First, I bound a mouse click event to the document.
Then, in the mouse event methods, I performed the following operations.
Afterwards, I clicked on the annotation area of the document, triggering a mouse event. In the mouse event, I was able to obtain an XTextViewCursor, but when I tried to perform the next operation (e.g., setString/goLeft), I received exception message “no text selection.”. Conversely, if I clicked on an area other than the annotation area to trigger the mouse event, I was able to obtain an XTextViewCursor and perform the next operation.
By printing the Position information of the XTextViewCursor, I found that the XTextViewCursors obtained from clicking on the annotation or its Anchor position have the same Position attribute (I don't know if this indicates that they are the same), but from the subsequent operations described above, I think they are different.
I don't know why this issue occurs. Please help me.
Then, in the mouse event methods, I performed the following operations.
Code: Select all
public static class MouseClickHandler implements XMouseClickHandler {
@Override
public boolean mousePressed(MouseEvent mouseEvent) {
return false;
}
@Override
public boolean mouseReleased(MouseEvent mouseEvent) {
logger.info("---------------------------------");
XTextCursor xTextCursor = compareRightXTextDocument.getText().createTextCursorByRange(compareRightTextViewCursor);
XParagraphCursor xParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor);
logger.info(xParagraphCursor.getString());
try {
logger.info("X:" + compareRightTextViewCursor.getPosition().X + ",Y:" + compareRightTextViewCursor.getPosition().Y);
compareRightTextViewCursor.goLeft((short)1,false);
compareRightTextViewCursor.setString("123");
}catch (java.lang.Exception e)
{
logger.error(e.getMessage());
}
return false;
}
@Override
public void disposing(EventObject eventObject) {
}
}
By printing the Position information of the XTextViewCursor, I found that the XTextViewCursors obtained from clicking on the annotation or its Anchor position have the same Position attribute (I don't know if this indicates that they are the same), but from the subsequent operations described above, I think they are different.
I don't know why this issue occurs. Please help me.
Libre Office 7.6 on Windows 11.
Re: Get all Annotations/Comments/Notes
You seem to keep changing what you're asking - or you're not being clear about what it is. Now you want to edit the contents of the textfield?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)