Thread

Posted on Wed Nov 15 10:22:34 2006 by budman
Working with headers and footers
Hi,

I was able to get most of the code working, but am running into a few issues.

Here is the code:

my $c = ooDocument(file => $filename, member => 'content', create => 'text'); my $s = ooDocument(file => $c, member => 'styles'); my $layout = $s->pageLayout("Standard"); my $master = $s->createMasterPage("NewStylePage",layout=>$layout); my $header = $s->createParagraph("",style=>"Header"); $s->appendElement($header,$s->textField("title")); $s->extendText($header,chr(160) x 30); $s->appendElement($header,$s->textField("chapter")); $s->masterPageExtension($master,"header",$header); my $footer = $s->createParagraph("- ",style=>"Footer"); $s->appendElement($footer,$s->textField("page-number")); $s->extendText($footer,' -'); $s->masterPageExtension($master,"footer",$footer);

This worked great so far.

One problem, I can't seem to get the page-number to center. I tried updateStyle, and tried creating a new style, but it doesn't seem to apply.

The header is working okay, but I would like to change it into a 1x2 Table, with border only on the bottom (maybe thickness 2), cell 1 left-justified, and cell 2 right-justified. I tried append table, but that didn't work. What would be the best way to go about this.

This last question deals with setPageBreak.

Currently, I have it working on Heading 1 and Heading 3, but I see an error msg when its executed. The breaks do occur, just wondering if the syntax is correct.

my $p = $c->appendParagraph(text=>$cat, style=>"Heading 1"); $c->setPageBreak($p,style=>'Heading 1',page=>"NewStylePage");

[OpenOffice::OODoc::Styles::createStyle] Style Heading 1 exists [OpenOffice::OODoc::Document::setPageBreak] Style Heading 1 creation failure [OpenOffice::OODoc::Styles::createStyle] Style Heading 3 exists [OpenOffice::OODoc::Document::setPageBreak] Style Heading 3 creation failure

I tried using a different name, but the style didn't exist. Does this mean I should create a style 'xyz' just for page breaks? Can the page break attribute be applied to Heading1 and Heading3 styles?

Lastly, is there a manual or doc site that has more examples setting attributes and styles?

The module works great so far. My wife thanks you - I'm able to automate database entries into a document for her now. Saves her hours of formatting and layout. Thanks! :)

Thanks, Rich

Direct Responses: 3563 | Write a response
Posted on Thu Nov 16 21:51:56 2006 by jmgdoc in response to 3540
Re: Working with headers and footers

Hi,
The first issue is here:
my $footer = $s->createParagraph("- ",style=>"Footer");
The target document is a new one which has just been built by ooDocument() using the "create" option. So, there is no predefined "Footer" style in it. This behaviour could be changed by using custom templates instead of the basic templates provided with the OpenOffice::OODoc CPAN distribution, but the right solution is much simpler: you have just to create a custom paragraph style with the appropriate text alignment property:
$s->createStyle ( "CustomCenteredFooter", family = "paragraph", properties => { "fo:text-align" => "center" } );

The new "CustomCentered" style name is ready for use as the style option for the footer paragraph.

About the table in the header:
Creating a table in a header from scratch is possible, but not recommended (and the explanation is a bit tricky). When a rich presentation is needed, the best option consists of using a template document, bringing the appropriate style definitions (including table prototypes and page styles), instead of creating the document from scratch.

About the page break question:
The "style" option of setPageBreak(), if set, must provide an arbitrary but unique name, which must differ from any existing style name. If the existing paragraph style is a named style (i.e. a style which will appear in the stylist dialog box of OpenOffice.org), this option is mandatory. It should be omitted otherwise. Details about setPageBreak() are provided in the OpenOffice::OODoc::Document manual page.
Write a response