Hello,
I have a little Problem. I want to insert some content before printing a Writer document und want to remove it afterwards.
I already got the methods for inserting and removing the content. And it is also no problem to catch the OnPrint event and insert the content. But how can I call my remove method after printing? I have no clue .
By the way I'm using OpenOfficeBasic for programming. Thanks for help.
Xenon
[Solved] Perform something after printing a document
[Solved] Perform something after printing a document
Last edited by Xenon on Thu Jan 10, 2008 4:46 pm, edited 1 time in total.
Re: Perform something after printing a document
Referring to documentation
http://api.openoffice.org/docs/common/r ... aster.html
http://api.openoffice.org/docs/common/r ... State.html
and with no printer at hand I hacked the following first draft into a text editor. I leave it up to you how to handle the other PrintableState events. My code will add more of the same listeners if something goes wrong and you trigger the script event another time.
http://api.openoffice.org/docs/common/r ... aster.html
http://api.openoffice.org/docs/common/r ... State.html
and with no printer at hand I hacked the following first draft into a text editor. I leave it up to you how to handle the other PrintableState events. My code will add more of the same listeners if something goes wrong and you trigger the script event another time.
Code: Select all
Global g_Listener
Sub scriptEventOnPrint
do_something
g_Listener = createUnoListener("someprefix_", "com.sun.star.view.XPrintJobListener")
oView = thisComponent.getCurrentController()
oView.addPrintJobListener(g_Listener)
End Sub
Sub someprefix_printJobEvent(oEv)
REM oView = thisComponent.getCurrentController()
REM may be pointless if the macro is stored in a public container.
REM oEv.Source might be the view having this listener attached:
oView = oEv.Source
nState = oEv.State
with com.sun.star.view.PrintableState
if nState = .JOB_SPOOLED then
oView.removePrintJobListener(g_Listener)
do_other_thing
endif
end with
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: Perform something after printing a document
Hi,
thanks for the quick help. With some modifications your code worked for me. here is my changed code:
You helped me very much
Xenon
thanks for the quick help. With some modifications your code worked for me. here is my changed code:
Code: Select all
Global g_Listener
Sub scriptEventOnPrint
do something
g_Listener = createUnoListener("someprefix_", "com.sun.star.view.XPrintJobListener")
oView = ThisComponent
oView.addPrintJobListener(g_Listener)
End Sub
Sub someprefix_printJobEvent(oEv)
oView = oEv.Source
nState = oEv.State
if nState = 1 then
ThisComponent.removePrintJobListener(g_Listener)
do something else
endif
End Sub
Xenon