[Solved] Not printing the background

Creating a macro - Writing a Script - Using the API

[Solved] Not printing the background

Postby zenlord » Tue Dec 22, 2009 5:59 pm

Hello,

I found a great solution to mimick my stationary, and it is to put the image of my stationary as a full-page background in my letter-template. So if I send someone a PDF of my letter through email, he gets the letter with my heading etc.

Now I've found an option in Print > Printer options > Elements to unselect the 'background'-element, which is a perfect solution, except for the fact that this setting is forgotten by openoffice / my printer everytime I make a new document out of this template.

Instead of teaching my 2 colleagues to always deselect this option, I'm looking for a macro to automate the deselection of this option upon loading the document.

Studying the openoffice-API is a disaster though. I find several Xprintable, print, getprinter, setprinter, printoptions etc.-possible attributes, but none of them seems to be able to set the attribute 'do not print background'.

Does anyone know the solution?

THX!
Last edited by zenlord on Tue Jan 12, 2010 11:03 am, edited 1 time in total.
LibreOffice 4.1 on Linux (Debian Wheezy backports)
zenlord
 
Posts: 51
Joined: Tue Dec 22, 2009 5:50 pm

Re: Not printing the background

Postby FJCC » Fri Dec 25, 2009 8:48 pm

I found the answer here. The service that supports the printPageBackground property is com.sun.star.view.PrintSettings, but I couldn't find how to access it. The post I referenced shows the way.
Code: Select all   Expand viewCollapse view
oDoc = ThisComponent
oDocSettings = oDoc.createInstance("com.sun.star.text.DocumentSettings")
oDocSettings.PrintPageBackground = False
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7194
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Not printing the background

Postby zenlord » Tue Jan 05, 2010 5:32 pm

Thx!

I have been trying different macro's in the last week, but I don't seem to get it working. Stuff I'll try out tonight are:

Code: Select all   Expand viewCollapse view
Dim oText As Object
oDoc = ThisComponent
oText = oDoc.DocumentSettings
oText.PrintPageBackground = False
print(oDoc)


oDoc = ThisComponent
Dim oDocSettings As Object
oDocSettings = createInstance("com.sun.star.text.DocumentSettings")
oDocSettings.PrintPageBackground = False
print(oDoc)


oDoc = ThisComponent
Dim oDocSettings As Object
oDocSettings = createInstance("com.sun.star.view.PrintSettings")
oDocSettings.PrintPageBackground = False
print(oDoc)

Maybe someone can rule out one or several of these possibilities.

Something that made me doubt earlier today is the way this macro works: I've been 'testing' the macro by looking at the 'print options'-dialog to see if the option was effectively disabled or not. This was never the case, but maybe the macro doesn't disable this option permanently, but only for a short while (f.e. until the end of the macro?). That would explain why I never saw a disabled print option for the background, and that's why I'll be trying the above macro's with the 'print()'-cmd, effectively printing the document before the macro has finished.

If someone else could shed some (more) light at my problem, I'd be much obliged. Wrestling through the API documentation, the Pitonyak-PDF and the starbasic developer tutorial has not really enlightened me (although I know my way around PHP, so I'm not a complete beginner when it comes to coding/hacking/'programming').

Thx again!
LibreOffice 4.1 on Linux (Debian Wheezy backports)
zenlord
 
Posts: 51
Joined: Tue Dec 22, 2009 5:50 pm

Re: Not printing the background

Postby zenlord » Tue Jan 12, 2010 11:02 am

OK, I think I nailed it and want to leave this code snippet here for anyone who wants it:

Code: Select all   Expand viewCollapse view
oDoc = ThisComponent

DIM oDocSettings AS Object
oDocSettings = createInstance("com.sun.star.view.PrintSettings")
oDocSettings.PrintPageBackground = False

DIM oPropertyValue(3) AS new com.sun.star.beans.PropertyValue
oPropertyValue(0).Name = "Copies"
oPropertyValue(0).Value = "1"
oPropertyValue(1).Name = "Collate"
oPropertyValue(1).Value = True
oPropertyValue(2).Name = "PrinterPaperTray"
oPropertyValue(2).Value = "Tray1"
oDoc.Print(oPropertyValue())


The code worked last night, but I'll be getting my new printer with different trays somewhere this week. I found http://www.oooforum.org/forum/viewtopic.phtml?t=52170&highlight=printerpapertray, which suggests that my tray-selection is not correct.
Also beware: I'm typing this from memory - I'll check the code tonight at home.

Zl.
LibreOffice 4.1 on Linux (Debian Wheezy backports)
zenlord
 
Posts: 51
Joined: Tue Dec 22, 2009 5:50 pm

Re: [Solved] Not printing the background

Postby zenlord » Wed Jan 13, 2010 9:45 am

EDIT: I posted a macro to solve a complete question, but since this macro didn't do exactly what I needed, I'm just posting the answer to the initial question and I will open a new thread for the other problems(s).

So: This piece of macro works to disable printing of the background:

Code: Select all   Expand viewCollapse view
Sub printDocWithoutBackground
   DIM oPropertyValue(0) AS New com.sun.star.beans.PropertyValue
   DIM oDoc
   DIM oSettings
   
   oDoc = ThisComponent
REM Set backgroundImage-option to False
   oSettings = oDoc.createInstance("com.sun.star.text.DocumentSettings")
   oSettings.PrintPageBackground = False
REM Set some print options
   oPropertyValue(0).Name = "CopyCount"
   oPropertyValue(0).Value = 1
   oDoc.Print(oPropertyValue())
End Sub
LibreOffice 4.1 on Linux (Debian Wheezy backports)
zenlord
 
Posts: 51
Joined: Tue Dec 22, 2009 5:50 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests