Thread

Posted on Thu May 11 04:43:23 2006 by pauld
Create new ODT with 2 columns
Hi there, still hunting around the documentation for this module. I really like it so far! I'd like to create a new ODT document with two columns. Could someone please let me know how I might go about accessing style:columns and fo:column-count? I think a great idea for this module, given it's obvious usefulness and complexity, would be a cookbook hosted on CPAN. Anyone else think this is a good idea? Perhaps you have some tricks to submit! Thanks very much in advance for your help. Regards, Paul
Direct Responses: 2298 | Write a response
Posted on Sat May 13 20:19:14 2006 by jmgdoc in response to 2277
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
Posted on Sun May 14 23:20:43 2006 by pauld in response to 2298
Re: Create new ODT with 2 columns
Thanks for the comprehensive reply Jean-Marie! I recommend you add your reply to the OpenOffice::OODoc::Intro page as I think it probably covers a bunch of different non-standard page layout issues. In terms of the cookbook, would it be a good approach to have a note on each module page requesting submissions? With respect to my two-columns question, I'm wondering if a helper-application (written in Perl of course) could be written which could generate the code required to create or alter more complex documents with custom layouts. Perhaps a simple option-driven system which provides the equivalent capabilities of the various formatting dialogues in OOo itself. This would serve as (a) a useful development tool, (b) a testing framework to confirm that the module produces ISO/IEC 26300 compliant documents, and (c) a comprehensive illustration of how the module can be used at a low level. You've clearly done a great deal of work -- thanks very much!
Write a response