[Solved] Perform something after printing a document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Xenon
Posts: 2
Joined: Thu Jan 10, 2008 11:41 am

[Solved] Perform something after printing a document

Post by Xenon »

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 :cry:.
By the way I'm using OpenOfficeBasic for programming. Thanks for help.

Xenon
Last edited by Xenon on Thu Jan 10, 2008 4:46 pm, edited 1 time in total.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Perform something after printing a document

Post by Villeroy »

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.

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
Xenon
Posts: 2
Joined: Thu Jan 10, 2008 11:41 am

Re: Perform something after printing a document

Post by Xenon »

Hi,

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
You helped me very much :D :D :D :D :D :D :D

Xenon
Post Reply