Page 1 of 1

[Solved] New Writer document with custom page size?

Posted: Tue Oct 13, 2015 8:16 pm
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.

Re: New Writer document with custom page size?

Posted: Wed Oct 14, 2015 6:57 am
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?

Re: New Writer document with custom page size?

Posted: Wed Oct 14, 2015 11:58 am
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

Re: New Writer document with custom page size?

Posted: Wed Oct 14, 2015 2:23 pm
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?

Re: New Writer document with custom page size?

Posted: Wed Oct 14, 2015 11:21 pm
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

Re: New Writer document with custom page size?

Posted: Wed Oct 14, 2015 11:54 pm
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?

Re: New Writer document with custom page size?

Posted: Thu Oct 15, 2015 10:25 am
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