in reply to Master Pages and OpenOffice::OODoc
Well, shouldn't I feel stupid now? Of course, I had to post my stupidity for all to see before I could find what was plainly in sight. How typical!
Just for the sake of anybody who might be misled by my question above, the style that introduces a new page layout should only be applied to a single paragraph and it seems to remain effective for the rest of the document (unless, of course, you need to apply a new page layout). All following paragraphs should have a style that is not linked with any page layout.
So, here's the corrected code that does the job properly:
#!/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 $regularnextstyle = $styles->createStyle( "regularnext", family => "paragraph", parent => "Standard", replace => 1, ); my $regularstyle = $styles->createStyle( "regular", family => "paragraph", parent => "regularnext", 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 => 'regularnext', ); for (my $i = 0; $i < 100; $i++) { $doc->appendParagraph( text => 'And some more.', style => 'regularnext', ); } $doc->save;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Master Pages and OpenOffice::OODoc
by ww (Archbishop) on Aug 21, 2016 at 15:05 UTC | |
|
Re^2: Master Pages and OpenOffice::OODoc
by MidLifeXis (Monsignor) on Aug 22, 2016 at 13:05 UTC |