I've been trying to process some XML files to create OpenOffice text documents and have been mostly successful so far. However, I would like to add page numbers in the footer, which should appear on all pages but the first couple of them where the title is supposed to appear.

So far, I think I've figured out that the way to go about achieving this is through master/layout pages but I have been unable to accomplish the required task. Of course, it would be easier to simply produce the basic document and then edit it through LibreOffice to get what I need but... you know how it is! I've got to know now!

So, the sample code below produces what I expect: An .odt document with the title on the first page without a page number in the footer and the text appears in the following pages with a page number in the footer. However, the problem seems to be that every page contains one paragraph only preceded by a page break.

I guess the problem lies somewhere in the way I connect master/layout pages to the paragraph styles... or something... but I couldn't find any concrete examples on line to help me fix my mistake(s). I would appreciate any pointers because this is almost driving me crazy.

Here's the sample code:

#!/usr/bin/perl -w use strict; use warnings; use utf8; use Win32; use Encode; use OpenOffice::OODoc; use Data::Dumper::AutoEncode; ooLocalEncoding('utf-8'); my $curfolder = Win32::GetCwd(); my $outfolder = $curfolder . '\\out'; my $outfile = $outfolder . '\\test.odt'; my $doc = odfDocument( file => $outfile, create => 'text', opendocument => 0, ); my $styles = odfDocument( container => $doc, part => "styles", ); my $centerfooter = $styles->createStyle( 'centerfooter', family => "paragraph", properties => { "fo:margin-top" => "0.5cm", "fo:text-align" => 'center', }, replace => 1, ); my $headerstyle = $styles->createStyle( "header", family => "paragraph", parent => "Standard", properties => { "fo:margin-top" => "8cm", "fo:text-align" => "center", "fo:break-after" => "page", }, replace => 1, ); $styles->styleProperties( $headerstyle, -area => "text", "fo:font-size" => "200%", "fo:font-weight" => "bold", ); $styles->setAttributes( $headerstyle, "master-page-name" => 'header', ); my $regularstyle = $styles->createStyle( "regular", family => "paragraph", parent => "Standard", replace => 1, ); $styles->setAttributes( $regularstyle, "master-page-name" => 'pagenumbers', ); my $pagelayout = $styles->pageLayout("Standard"); my $titlepage = $styles->createMasterPage( 'titlepage', layout => $pagelayout, ); my $pnpage = $styles->createMasterPage( 'pagenumbers', layout => $pagelayout, ); my $pn = $styles->createParagraph( '', 'centerfooter' ); my $pg = $styles->textField( 'page-number', style => 'centerfooter' ); $styles->appendElement( $pn, $pg ); $styles->masterPageFooter( 'pagenumbers', $pn ); my $wordlist = $doc->appendParagraph( text => '', style => 'header', ); $doc->extendText( $wordlist, uc 'Main Title', 'header' ); my $regular = $doc->appendParagraph( text => 'Some text.', style => 'regular', ); $doc->appendParagraph( text => 'More text.', style => 'regular', ); $doc->appendParagraph( text => 'And some more.', style => 'regular', ); $doc->save;

In reply to Master Pages and OpenOffice::OODoc by emav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.