This page provides a guide on how to setup and use LibreOffice Writer for the IAC protocol.
Warning
LibreOffice needs to have the UNO bridge running for it to function properly. Please see the instructions for more details.
If you wish to contribute to LibreOffice Writer, try playing around with Python’s library imports for LibreOffice Writer. But the best way is probably to view the UNO API documentation online, available from both LibreOffice and OpenOffice, which are essentially identical APIs. If the functionality is written in Java or another language, please try to change the logic to Python. The same namespace and class names are typically used, so this isn’t usually difficult to do.
Then, clone the project repository from the project’s GitHub page, add your modified application, and submit a pull request to be reviewed. If your additions to the application follow the protocol convention and it doesn’t contain any obvious errors, it will be accepted! See IAC protocol plugin implementation for more details.
Here is a sample demonstrating LibreOffice Writer’s functionality. First, run the UNO bridge:
libreoffice "--accept=socket,host=localhost,port=18100;urp;StarOffice.ServiceManager" --norestore --nofirststartwizard --nologo --writer
Run the server (iacs) and then run the following Hello, World! shell script:
#!/usr/bin/env bash
# Netcat: -u is for UDP, -c closes the connection on EOF
PORT=14733
if [[ $# -eq 2 ]]; then
echo -e "lowriter -> doc = new_document()\n" | nc -uc localhost $PORT
echo -e "lowriter -> text = doc.get_document_text()\n" | nc -uc localhost $PORT
echo -e "lowriter -> text.set_text('$1')\n" | nc -uc localhost $PORT
echo -e "lowriter -> doc.save_as('$2')\n" | nc -uc localhost $PORT
else
echo "Usage: $0 [string] [path]"
fi
Or try the interpreter by directing the following as stdin:
lowriter -> doc = new_document()
lowriter -> text = doc.get_document_text()
lowriter -> text.set_text('Hello, World!')
lowriter -> doc.save_as('/home/gyeh/hello.odt')
And then run it as something like iaci < hello-lowriter.txt (assuming it’s saved as that name).
lowriter -> doc = current_document()
Returns: | A document object. |
---|
lowriter -> doc = load_document(‘/home/gyeh/hello.odt’)
Parameters: | path (str) – The path where the document is (must end with .odt) |
---|---|
Returns: | A document object. |
lowriter -> doc = new_document()
Returns: | A document object. |
---|
lowriter -> doc.save_as(‘/home/gyeh/hello.odt’)
Parameters: | path (str) – The path to save the document to (must end with .odt) |
---|---|
Returns: | True on success, False otherwise. |
lowriter -> doc.save_as_pdf(‘/home/gyeh/hello.pdf’)
Parameters: | path (str) – The path to save the document to (must end with .pdf) |
---|---|
Returns: | True on success, False otherwise. |
lowriter -> document.select_text()
Returns: | A text_range object. |
---|
lowriter -> document.get_document_text()
Returns: | A text object (inherits text_range). |
---|
lowriter -> text_range.set_text(“Hello, World!”)
Parameters: | string (str) – A string to set the text range contents to. |
---|---|
Returns: | True on success, False otherwise. |
lowriter -> text_range.get_text()
Returns: | The text_range’s text. |
---|
lowriter -> text_range.weight(‘bold’)
Returns: | True on success, False otherwise. |
---|