Aaron Mitti > PostScript-Simple-Table-1.02 > PostScript::Simple::Table

Download:
PostScript-Simple-Table-1.02.tar.gz

Dependencies

Annotate this POD

Related Modules

HTML::Table
LaTeX::Table
more...
By perlmonks.org

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 1.02   Source  

NAME ^

PostScript::Simple::Table - Adds easy table creation to PostScript::Simple

SYNOPSIS ^

  use PostScript::Simple;
  use PostScript::Simple::Table;

  $ps = new PostScript::Simple(
    papersize => "letter",
    colour => 1,
    eps => 0,
  );
  
  $ps->newpage;

  # some data to layout
  my $some_data =[
    ["1 Lorem ipsum dolor",
    "Donec odio neque, faucibus vel",
    "consequat quis, tincidunt vel, felis."],
    ["Nulla euismod sem eget neque.",
    "Donec odio neque",
    "Sed eu velit."],
    ... and so on
  ];
  
  my $pstable = new PostScript::Simple::Table;
  
  # build the table layout
  $pstable->table(
    # required params
    $ps,
    $some_data,
    -x  => $left_edge_of_table,
    -start_y => 500,
    -next_y => 700,
    -start_h => 300,
    -next_h => 500,
    # some optional params
    -w => 570, 
    -padding => 5,
    -padding_right => 10, 
    -background_color_odd => "gray", 
    -background_color_even => "#FFFFCC", #cell background color for even rows
  );

DESCRIPTION ^

This class is a utility for use with the PostScript::Simple module from CPAN. It can be used to display text data in a table layout within a PostScript document. The text data must be in a 2d array (such as returned by a DBI statement handle fetchall_arrayref() call). The PDF::Table will automatically add as many new pages as necessary to display all of the data. Various layout properties, such as font, font size, and cell padding and background color can be specified for each column and/or for even/odd rows. See the METHODS section.

METHODS ^

new

Returns an instance of the class. There are no parameters.

table($pdf, $page_obj, $data, %opts)

 The main method of this class. Takes a PDF::API2 instance, a page instance, 
 some data to build the table and formatting options. The formatting options 
 should be passed as named parameters. This method will add more pages to the 
 pdf instance as required based on the formatting options and the amount of 
 data.
 The return value is the y position of the table bottom.
Example:
 ($table_bot_y) = $pdftable->table(
         $ps, # A PostScript::Simple instance
         $data, # 2D arrayref of text strings
         -x  => $left_edge_of_table,
         -start_y   => $baseline_of_first_line_on_first_page,
         -next_y   => $baseline_of_first_line_on_succeeding_pages,
         -start_h   => $height_on_first_page,
         -next_h => $height_on_succeeding_pages,
         [-w  => 570,] # width of table. technically optional, but almost always a good idea to use
         [-padding => "5",] # cell padding
         [-padding_top => "10",] #top cell padding, overides -pad 
         [-padding_right  => "10",] #right cell padding, overides -pad 
         [-padding_left  => "10",] #left padding padding, overides -pad 
         [-padding_bottom  => "10",] #bottom padding, overides -pad
         [-border  => 1,] # border width, default 1, use 0 for no border
         [-border_color => "red",] # default black
         [-font  => "Helvetica",] # default font
         [-font_size => 12,]
         [-font_color_odd => "purple",]
         [-font_color_even => "black",]
         [-background_color_odd => "gray",] #cell background color for odd rows
         [-background_color_even => "#FFFFCC",] #cell background color for even rows
         [-column_props => $col_props] # see below
 )

If the -column_props parameter is used, it should be an arrayref of hashrefs, with one hashref for each column of the table. Each hashref can contain any of keys shown here:

  $col_props = [
        {
                width => 100,  
                justify => "[left|right|center]",
                font => $pdf->corefont("Times", -encoding => "latin1"),
                font_size => 10
                font_color=> "red"
                background_color => "yellow", 
        },
        # etc.
  ];

If the "width" parameter is used for -col_props, it should be specified for every column and the sum of these should be exacty equal to the -w parameter, otherwise Bad Things may happen. In cases of a conflict between column formatting and odd/even row formatting, the former will oeverride the latter.

text_block($txtobj,$string,-x => $x, -y => $y, -w => $width, -h => $height)

Utility method to create a block of text. The block may contain multiple paragraphs.

Example:
 $left_over_text = $pdftable->text_block(
    $ps,
    $text_to_place,
    -x        => $left_edge_of_block,
    -y        => $baseline_of_first_line,
    -w        => $width_of_block,
    -h        => $height_of_block,
   [-lead     => $font_size * 1.2 | $distance_between_lines,]
   [-parspace => 0 | $extra_distance_between_paragraphs,]
   [-align    => "left|right|center|justify|fulljustify",]
   [-hang     => $optional_hanging_indent,]
 );

SEE ALSO ^

This is a port from Daemmon Hughes's PDF::Table to PostScript::Simple.

AUTHOR ^

Aaron Mitti, <mitti@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2005 by Aaron Mitti =item Copyright (C) 2005 by Daemmon Hughes =item Copyright (C) 2005 by Rick Measham =item Copyright (C) 2004 by Stone Environmental Inc. =item All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: