[Solved] New Writer document with custom page size?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

[Solved] New Writer document with custom page size?

Post by _savage »

I am currently creating an empty Writer document:

Code: Select all

document = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())
which uses the default page size settings, US Letter in my case. How can I set the page size to, say, 6 by 9 inches? The documentation doesn't give away much about the property values here. Or is that something I need to set for the returned XComponent instance?

And once I'm at this, how can I modify the verso/recto page margins, footer and header? I found this post from 2004 but am not sure if this is current information.
Last edited by _savage on Thu Oct 15, 2015 3:35 pm, edited 1 time in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Post by _savage »

After some poking around I dug up the following, based on the referenced post above. The available properties are documented here, with some additional information here.

Code: Select all

# Return the number of page styles for the current document.
>>> document.StyleFamilies.getByName("PageStyles").getCount()
10

# Get the name of the first page style.
>>> document.StyleFamilies.getByName("PageStyles").getByIndex(0).getName()
'Standard'
>>> document.StyleFamilies.getByName("PageStyles").getByName("Standard").getName()
'Standard'

# Get a few more properties of this page style.
>>> document.StyleFamilies.getByName("PageStyles").getByIndex(0).Width
21590
>>> document.StyleFamilies.getByName("PageStyles").getByIndex(0).Size
(com.sun.star.awt.Size){ Width = (long)0x270f, Height = (long)0x270f }
>>> document.StyleFamilies.getByName("PageStyles").getByIndex(0).LeftMargin
2000
Looks like assigning values directly to these properties changes the document immediately. It also seems that 'Standard' is the default page size that's used when the cursor runs onto a new page.

Question: Is there a way to automatically alternate 'Left Page' and 'Right Page'?

Question: Is there a way to declare a 'default' page style that's being used when the cursor runs onto a new page?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: New Writer document with custom page size?

Post by RPG »

Hello

I think the magic words are: Styles and templates.

Make a template. Use styles to define your pages in your template and load that template.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Post by _savage »

RPG wrote:I think the magic words are: Styles and templates. Make a template. Use styles to define your pages in your template and load that template.
That sounds good, do you have a pointer to example code or documentation? I found this one and this one, is that the right direction?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: New Writer document with custom page size?

Post by RPG »

Hello

I think using macro's to define a template is not a good idea. But maybe you have good reason when you want use a macro.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Post by _savage »

I followed your suggestion, and instead of opening a blank document and trying to change its properties I opened template:

Code: Select all

document = desktop.loadComponentFromURL("file:///path/to/template.ott", "_blank", 0, ())
Works like a charm, and I think is a much more stable way of solving my problem. That's what you meant?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: New Writer document with custom page size?

Post by RPG »

Hello
_savage wrote:That's what you meant?
Yes. Templates are made for those things. And it is good to under stand the working of styles in OOo.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Post Reply