I am trying to add watermark in a document using python but I am unable to find the code or any kind of help in documentation. Any suggestions or samples please !!
P.S: I have seen some examples in java but as I am new to python then I wasn't sure how to convert them into python as I still don't understand how to read python documentation.
Watermark generation using Pyuno
Watermark generation using Pyuno
LibreOffice 5.3.3.2 on Linux 16.10
Re: watermark generation using Pyuno
If you post the java code, or a link to it, we can more easily suggest equivalent Python code. Which programming language is used is not as important as knowing what API calls to use.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Watermark generation using Pyuno
Actually I was looking at this question viewtopic.php?f=45&t=2586 and I found some related info here in java.
LibreOffice 5.3.3.2 on Linux 16.10
Re: Watermark generation using Pyuno
It looks like the code you found adds the watermark as part of the process of exporting the document to PDF. Is that what you want to do or do you want to add the watermark as you would with the menu Format -> Page -> Background?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Watermark generation using Pyuno
Actually I want to add the watermark while creation of PDF file. so you can say menu Format -> Page -> Background.
LibreOffice 5.3.3.2 on Linux 16.10
Re: Watermark generation using Pyuno
[Tutorial] Introduction into object inspection with MRI
menu:Tools>Add-Ons>Mri
StyleFamilies
method getByName(PageStyles)
method getByName(...)
various properties...
mri-menu:Tools>Code>Python
Ctrl+H
menu:Tools>Add-Ons>Mri
StyleFamilies
method getByName(PageStyles)
method getByName(...)
various properties...
mri-menu:Tools>Code>Python
Ctrl+H
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: Watermark generation using Pyuno
This pair of Python functions adds a watermark to a Writer file and export it as a PDF. The SVG file used as an image was provided by acknak here. He posted it as a txt file but it is really an svg, you just need to change the extension from txt to svg. I also tried adding a watermark in the same way the Java code did, using the PropertyValue named Watermark but that did not do anything. I commented out that code but you can see how I did it. I never use Python, so this code could probably be written more elegantly.
Code: Select all
import uno
from com.sun.star.beans import PropertyValue
def AddBkgrd():
doc = XSCRIPTCONTEXT.getDocument()
oStyleFamilies = doc.getStyleFamilies()
PageStyles = oStyleFamilies.getByName("PageStyles")
DefaultStyle = PageStyles.getByName("Standard")
DefaultStyle.BackGraphicURL =uno.systemPathToFileUrl('c:\\users\\fjcc\\desktop\\watermark.svg')
def exportPDF():
storeUrl = uno.systemPathToFileUrl('c:\\users\\fjcc\\desktop\\PDFversion.pdf')
doc = XSCRIPTCONTEXT.getDocument()
#filterProps = PropertyValue()
#filterProps.Name = "Watermark"
#filterProps.Value = "MyMark"
storeProps0 = PropertyValue()
storeProps0.Name = "FilterName"
storeProps0.Value = "writer_pdf_Export"
storeProps1 = PropertyValue()
storeProps1.Name = "Overwrite "
storeProps1.Value = True
#storeProps2 = PropertyValue()
#storeProps2.Name = "FilterData"
#storeProps2.Value = (filterProps,)
doc.storeToURL(storeUrl, (storeProps0, storeProps1))
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Watermark generation using Pyuno
Hallo
AFAIK there is no need for this double backslash-plaque on Windows with python, use single slashes instead…
Karolus
AFAIK there is no need for this double backslash-plaque on Windows with python, use single slashes instead…
Code: Select all
…uno.systemPathToFileUrl('c:/users/fjcc/desktop/watermark.svg')
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (Bookworm) (on RaspberryPI5)