Differences

This shows you the differences between the selected revision and the current version of the page.

headers.footers 2007/08/21 20:12 headers.footers 2007/08/23 15:49 current
Line 1: Line 1:
This example illustrates using headers and footers in a document. Note that they are defined as subroutines, and called each time they're needed. This example illustrates using headers and footers in a document. Note that they are defined as subroutines, and called each time they're needed.
-        #!/usr/bin/perl +<code perl> 
-        +#!/usr/bin/perl 
-       use PDF::API2::Simple; + 
-        +use PDF::API2::Simple; 
-       my $page_num = 1; + 
-       my $pdf = PDF::API2::Simple->new(  +my $page_num = 1; 
-                                         file => '04_headers.pdf', +my $pdf = PDF::API2::Simple->new(  
-                                         header => \&header, +                                 file => '04_headers.pdf', 
-                                         footer => \&footer +                         header => \&header, 
-                                         ); +                         footer => \&footer 
-        +                         ); 
-       $pdf->add_font('VerdanaBold'); + 
-       $pdf->add_font('Verdana'); +$pdf->add_font('VerdanaBold'); 
-       $pdf->add_page(); +$pdf->add_font('Verdana'); 
-        +$pdf->add_page(); 
-       for (my $i = 0; $i < 250; $i++) { + 
-           my $text = "$i - All work and no play makes Jack a dull boy"; +for (my $i = 0; $i < 250; $i++) { 
-        +   my $text = "$i - All work and no play makes Jack a dull boy"; 
-           $pdf->text( $text,  + 
-                       x => $pdf->margin_left, +   $pdf->text( $text,  
-                       autoflow => 'on' ); +               x => $pdf->margin_left, 
-       +               autoflow => 'on' ); 
-        +
-       $pdf->save(); + 
-        +$pdf->save(); 
-       sub header { + 
-           my $strokecolor = $pdf->strokecolor; +sub header { 
-        +   my $strokecolor = $pdf->strokecolor; 
-           $pdf->stroke_color( '#0000FF' ); + 
-        +   $pdf->stroke_color( '#0000FF' ); 
-           $pdf->next_line; + 
-           $pdf->text( 'Unix time of report: ' . time() ); +   $pdf->next_line; 
-        +   $pdf->text( 'Unix time of report: ' . time() ); 
-           $pdf->y( $pdf->y - 5 ); + 
-        +   $pdf->y( $pdf->y - 5 ); 
-           $pdf->line( to_x => $pdf->effective_width, + 
-                       to_y => $pdf->y, +   $pdf->line( to_x => $pdf->effective_width, 
-                       stroke => 'on', +               to_y => $pdf->y, 
-                       fill => 'off', +               stroke => 'on', 
-                       width => 2 ); +               fill => 'off', 
-        +               width => 2 ); 
-           $pdf->y( $pdf->height - 60 ); + 
-        +   $pdf->y( $pdf->height - 60 ); 
-           $pdf->strokecolor( $strokecolor ); + 
-       +   $pdf->strokecolor( $strokecolor ); 
-        +
-       sub footer { + 
-           my $fillcolor = $pdf->fill_color; +sub footer { 
-           my $font = $pdf->current_font; +   my $fillcolor = $pdf->fill_color; 
-        +   my $font = $pdf->current_font; 
-           $pdf->fill_color( '#552F55' ); + 
-        +   $pdf->fill_color( '#552F55' ); 
-           $pdf->set_font( 'VerdanaBold' ); + 
-           $pdf->text( 'Page ' . $page_num++, +   $pdf->set_font( 'VerdanaBold' ); 
-                       x => $pdf->effective_width, +   $pdf->text( 'Page ' . $page_num++, 
-                       y => 20, +               x => $pdf->effective_width, 
-                       align => 'right' ); +               y => 20, 
-        +               align => 'right' ); 
-           $pdf->fill_color( $fillcolor ); + 
-           $pdf->current_font( $font ); +   $pdf->fill_color( $fillcolor ); 
-       }+   $pdf->current_font( $font ); 
 +} 
 +</code>
 
headers.footers.txt · Last modified: 2007/08/23 15:49 by bprudent
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki