[Solved] New Writer document with custom page size?

The Application Programming Interface and the OASIS Open Document Format

[Solved] New Writer document with custom page size?

Postby _savage » Tue Oct 13, 2015 8:16 pm

I am currently creating an empty Writer document:

Code: Select all   Expand viewCollapse view
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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 165
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Postby _savage » Wed Oct 14, 2015 6:57 am

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   Expand viewCollapse view
# 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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 165
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Postby RPG » Wed Oct 14, 2015 11:58 am

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 6.1.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2164
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: New Writer document with custom page size?

Postby _savage » Wed Oct 14, 2015 2:23 pm

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 165
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Postby RPG » Wed Oct 14, 2015 11:21 pm

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 6.1.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2164
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: New Writer document with custom page size?

Postby _savage » Wed Oct 14, 2015 11:54 pm

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

Code: Select all   Expand viewCollapse view
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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 165
Joined: Sun Apr 21, 2013 12:55 am

Re: New Writer document with custom page size?

Postby RPG » Thu Oct 15, 2015 10:25 am

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 6.1.5.2 on openSUSE Leap 15
RPG
Volunteer
 
Posts: 2164
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest