Search code examples
perlodt

Perl OpenOffice::OODoc - accessing header/footer elements


How do you get elements in a header/footer of a odt doc?

for example I have:

use OpenOffice::OODoc;    
my $doc = odfDocument(file => 'whatever.odt');
    my $t=0;
    while (my $table = $doc->getTable($t))
    {
       print "Table $t exists\n";
       $t++;
    }

When I check the tables they are all from the body. I can't seem to find elements for anything in the header or footer?


Solution

  • I found sample code here which led me to the answer:

    #! /usr/local/bin/perl
    
    use OpenOffice::OODoc;
    
    my $file='asdf.odt';
    
    # odfContainer is a representation of the zipped odf file 
    # and all of its parts.
    my $container = odfContainer("$file");
    
    # We're going to look at the 'style' part of the container,
    # because that's where the header is located.
    my $style = odfDocument
        (
        container => $container,
        part      => 'styles'
        );
    
    # masterPageHeader takes the style name as its argument.
    # This is not at all clear from the documentation.
    my $masterPageHeader = $style->masterPageHeader('Standard');
    my $headerText = $style->getText( $masterPageHeader );
    
    print "$headerText\n"
    

    The master page style defines the look and feel of the document -- think CSS. Apparently 'Standard' is the default name for the master page style of a document created by OpenOffice... that was the toughest nut to crack... once I found the example code, that fell out in my lap.