Here is a simple code to insert a watermark to current document:
Sub SetWatermark
Dim document As Object
Dim dispatcher As Object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
' Using arguments skips dialog and allows direct insertion of the watermark '
Dim args(4) As New com.sun.star.beans.PropertyValue
args(0).Name = "Text"
args(0).Value = "Watermark" ' Which text will be shown as the watermark '
args(1).Name = "Font"
args(1).Value = "Arial"
args(2).Name = "Angle"
args(2).Value = 45 ' Degrees, int '
args(3).Name = "Transparency"
args(3).Value = 50 ' Percent, int '
args(4).Name = "Color"
args(4).Value = 16711680 ' FF0000 = Red; number only '
dispatcher.executeDispatch(document, ".uno:Watermark", "", 0, args())
End Sub
Using this macro, and your previous questions to run the macro in a batch, you may try to implement something like that, … but there is a but, even two:
- The function is Writer-only, so you can’t use it for other documents;
- Setting a watermark adds a header, which may change documents’ layout.
So possibly better use some external post-processing of your PDFs, e.g. like suggested here with pdftk.