OpenOffice-OODoc - Re: Create new ODT with 2 columns

Posted on Sat May 13 20:19:14 2006 by jmgdoc in response to 2277 (See the whole thread of 3)
Re: Create new ODT with 2 columns

The best way to create a new document with 2 columns (or any other non-default page layout) is probably to copy the layout of an existing document. Yes, OODoc allows you to create a 2-column page layout from scratch, but you have to provide a *lot* of properties to do so.

In other words, you should:
1) Create an empty (or not) document with OpenOffice.org with the layout you exactly want as its standard page layout;
2) In your program, retrieve the standard page layout of this "template" document and use it as a replacement of the default page layout.

I hear your next question: what's the way to import a page layout from another document?
The example below shows a possibility (among many others).

Assume "columns.odt" is a template document your previously created one for all, whose page layout is exactly the right one for you (number and size of columns, etc) and "target.odt" is the document you want to customize. The program will retrieve the layout of the "Standard" page style in the two documents, then it will insert a copy of the layout element extracted from "columns.odt" in "target.odt", and finally it, will remove the old standard page layout of "target.odt". As you can see, the program is connected to the "styles" members of both "target.odt" and "columns.odt".
$source = ooDocument ( file => "columns.odt", member => "styles" ); $new_layout = $source->getPageLayoutElement("Standard")->copy; $target = ooDocument ( file => "target.odt", member => "styles" ); $old_layout = $target->getPageLayoutElement("Standard"); $target->insertElement($old_layout, $new_layout); $target->removeElement($old_layout);

This sequence is very simplistic because it works only with the "Standard" page layout. Some applications could create multi-section documents with more than one page layout. A more sophisticated version of this example could extract a lot of custom page layouts, selected by their respective names. But another approach consists of using a custom template document (with the full set of needed page layouts and other styles) instead of the default ODT template provided with the OODoc distribution.

PS: Yes, the "OODoc tips and tricks" cookbook idea is great. It could be very efficient if a bunch of users (other than the developer of the API;-) were ready to feed it with their various skills and uses.
Direct Responses: 2300 | Write a response