GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  PDF::TABLE (3)

.ds Aq ’

NAME

PDF::Table - A utility class for building table layouts in a PDF::API2 object.

CONTENTS

SYNOPSIS



 use PDF::API2;
 use PDF::Table;

 my $pdftable = new PDF::Table;
 my $pdf = new PDF::API2(-file => "table_of_lorem.pdf");
 my $page = $pdf->page;

 # 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
 ];

 $left_edge_of_table = 50;
 # build the table layout
 $pdftable->table(
     # required params
     $pdf,
     $page,
     $some_data,
     x => $left_edge_of_table,
     w => 495,
     start_y => 500,
     start_h => 300,
     # some optional params
     next_y  => 750,
     next_h  => 500,
     padding => 5,
     padding_right => 10,
     background_color_odd  => "gray",
     background_color_even => "lightblue", #cell background color for even rows
  );

 # do other stuff with $pdf
 $pdf->saveas();
...



EXAMPLE

For a complete working example or initial script look into distribution‘s ’examples’ folder.

DESCRIPTION

This class is a utility for use with the PDF::API2 module from CPAN. It can be used to display text data in a table layout within a PDF. 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. Also a (non)repeated header row with different layout properties can be specified.

See the METHODS section for complete documentation of every parameter.

METHODS

new()



    my $pdf_table = new PDF::Table;



Description Creates a new instance of the class. (to be improved)
Parameters There are no parameters.
Returns Reference to the new instance

table()



    my ($final_page, $number_of_pages, $final_y) = table($pdf, $page, $data, %settings)



Description Generates a multi-row, multi-column table into an existing PDF document based on provided data set and settings.
Parameters


    $pdf      - a PDF::API2 instance representing the document being created
    $page     - a PDF::API2::Page instance representing the current page of the document
    $data     - an ARRAY reference to a 2D data structure that will be used to build the table
    %settings - HASH with geometry and formatting parameters.



For full %settings description see section Table settings below.

This method will add more pages to the pdf instance as required based on the formatting options and the amount of data.

Reuturns The return value is a 3 items list where



    $final_page - The first item is a PDF::API2::Page instance that the table ends on
    $number_of_pages - The second item is the count of pages that the table spans on
    $final_y - The third item is the Y coordinate of the table bottom so that additional content can be added in the same document.



Example


    my $pdf  = new PDF::API2;
    my $page = $pdf->page();
    my $data = [
        [foo1,bar1,baz1],
        [foo2,bar2,baz2]
    ];
    my %settings = (
        x       => 10,
        w       => 570,
        start_y => 220,
        start_h => 180,
    );
   
    my ($final_page, $number_of_pages, $final_y) = $pdftable->table( $pdf, $page, $data, %options );



Table settings

Mandatory

There are some mandatory parameteres for setting table geometry and position across page(s)
<B>xB> - X coordinate of upper left corner of the table. Left edge of the sheet is 0. <B>Value:B> can be any whole number satisfying 0 =< X < PageWidth <B>Default:B> No default value



    x => 10



<B>start_yB> - Y coordinate of upper left corner of the table at the initial page. <B>Value:B> can be any whole number satisfying 0 < start_y < PageHeight (depending on space availability when embedding a table) <B>Default:B> No default value



    start_y => 327



<B>wB> - width of the table starting from X. <B>Value:B> can be any whole number satisfying 0 < w < PageWidth - x <B>Default:B> No default value



    w  => 570



<B>start_hB> - Height of the table on the initial page <B>Value:B> can be any whole number satisfying 0 < start_h < PageHeight - Current Y position <B>Default:B> No default value



    start_h => 250



Optional
<B>next_hB> - Height of the table on any additional page <B>Value:B> can be any whole number satisfying 0 < next_h < PageHeight <B>Default:B> Value of param <B>’start_h’B>



    next_h  => 700



<B>next_yB> - Y coordinate of upper left corner of the table at any additional page. <B>Value:B> can be any whole number satisfying 0 < next_y < PageHeight <B>Default:B> Value of param <B>’start_y’B>



    next_y  => 750



<B>max_word_lengthB> - Breaks long words (like serial numbers hashes etc.) by adding a space after every Nth symbol <B>Value:B> can be any whole positive number <B>Default:B> 20



    max_word_length => 20    # Will add a space after every 20 symbols



<B>paddingB> - Padding applied to every cell
<B>padding_topB> - top cell padding, overrides ’padding’
<B>padding_rightB> - right cell padding, overrides ’padding’
<B>padding_leftB> - left cell padding, overrides ’padding’
<B>padding_bottomB> - bottom padding, overrides ’padding’ <B>Value:B> can be any whole positive number

<B>Default padding:B> 0

<B>Default padding_*B> $padding



    padding        => 5      # all sides cell padding
    padding_top    => 8,     # top cell padding, overrides padding
    padding_right  => 6,     # right cell padding, overrides padding
    padding_left   => 2,     # left cell padding, overrides padding
    padding_bottom => undef  # bottom padding will be 5 as it will fallback to padding



<B>borderB> - Width of table border lines.
<B>horizontal_bordersB> - Width of horizontal border lines. Overrides ’border’ value.
<B>vertical_bordersB> - Width of vertical border lines. Overrides ’border’ value. <B>Value:B> can be any whole positive number. When set to 0 will disable border lines. <B>Default:B> 1



    border             => 3     # border width is 3
    horizontal_borders => 1     # horizontal borders will be 1 overriding 3
    vertical_borders   => undef # vertical borders will be 3 as it will fallback to border



<B>vertical_bordersB> - Width of vertical border lines. Overrides ’border’ value. <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> ’black’



    border_color => red



<B>fontB> - instance of PDF::API2::Resource::Font defining the fontf to be used in the table <B>Value:B> can be any PDF::API2::Resource::* type of font <B>Default:B> ’Times’ with UTF8 encoding



    font => $pdf->corefont("Helvetica", -encoding => "utf8")



<B>font_sizeB> - Default size of the font that will be used across the table <B>Value:B> can be any positive number <B>Default:B> 12



    font_size => 16



<B>font_colorB> - Font color for all rows
<B>font_color_oddB> - Font color for odd rows
<B>font_color_evenB> - Font color for even rows
<B>background_color_oddB> - Background color for odd rows
<B>background_color_evenB> - Background color for even rows <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> ’black’ font on ’white’ background



    font_color            => #333333
    font_color_odd        => purple
    font_color_even       => #00FF00
    background_color_odd  => gray    
    background_color_even => lightblue



<B>row_heightB> - Desired row height but it will be honored only if row_height > font_size + padding_top + padding_bottom <B>Value:B> can be any whole positive number <B>Default:B> font_size + padding_top + padding_bottom



    row_height => 24



<B>new_page_funcB> - CODE reference to a function that returns a PDF::API2::Page instance. If used the parameter ’new_page_func’ must be a function reference which when executed will create a new page and will return the object back to the module. For example you can use it to put Page Title, Page Frame, Page Numbers and other staff that you need. Also if you need some different type of paper size and orientation than the default A4-Portrait for example B2-Landscape you can use this function ref to set it up for you. For more info about creating pages refer to PDF::API2 PAGE METHODS Section. Don’t forget that your function must return a page object created with PDF::API2 page() method.



    new_page_func  => $code_ref



<B>header_propsB> - HASH reference to specific settings for the Header row of the table. See section ‘‘Header Row Properties’’ below


    header_props => $hdr_props



<B>column_propsB> - HASH reference to specific settings for each column of the table. See section ‘‘Column Properties’’ below


    column_props => $col_props



<B>cell_propsB> - HASH reference to specific settings for each column of the table. See section ‘‘Cell Properties’’ below


    cell_props => $cel_props



Header Row Properties

If the ’header_props’ parameter is used, it should be a hashref. Passing an empty HASH will triger a header row initialised with Default values. There is no ’data’ variable for the content, because the module asumes that first table row will become the header row. It will copy this row and put it on every new page if ’repeat’ param is set.
<B>fontB> - instance of PDF::API2::Resource::Font defining the fontf to be used in the header row <B>Value:B> can be any PDF::API2::Resource::* type of font <B>Default:B> ’font’ of the table. See table parameter ’font’ for more details.
<B>font_sizeB> - Font size of the header row <B>Value:B> can be any positive number <B>Default:B> ’font_size’ of the table + 2
<B>font_colorB> - Font color of the header row <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> ’#000066’
<B>bg_colorB> - Background color of the header row <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> #FFFFAA
<B>repeatB> - Flag showing if header row should be repeated on every new page <B>Value:B> 0,1 1-Yes/True, 0-No/False <B>Default:B> 0
<B>justifyB> - Alignment of text in the header row <B>Value:B> One of ’left’, ’right’, ’center’ <B>Default:B> ’left’



    my $hdr_props =
    {
        font       => $pdf->corefont("Helvetica", -encoding => "utf8"),
        font_size  => 18,
        font_color => #004444,
        bg_color   => yellow,
        repeat     => 1,   
        justify    => center
    };



Column Properties

If the ’column_props’ parameter is used, it should be an arrayref of hashrefs, with one hashref for each column of the table. The columns are counted from left to right so the hash reference at $col_props[0] will hold properties for the first column from left to right. If you DO NOT want to give properties for a column but to give for another just insert and empty hash reference into the array for the column that you want to skip. This will cause the counting to proceed as expected and the properties to be applyed at the right columns.

Each hashref can contain any of the keys shown below:
<B>min_wB> - Minimum width of this column. Auto calculation will try its best to honour this param but aplying it is NOT guaranteed. <B>Value:B> can be any whole number satisfying 0 < min_w < w <B>Default:B> Auto calculated
<B>max_wB> - Maximum width of this column. Auto calculation will try its best to honour this param but aplying it is NOT guaranteed. <B>Value:B> can be any whole number satisfying 0 < max_w < w <B>Default:B> Auto calculated
<B>fontB> - instance of PDF::API2::Resource::Font defining the fontf to be used in this column <B>Value:B> can be any PDF::API2::Resource::* type of font <B>Default:B> ’font’ of the table. See table parameter ’font’ for more details.
<B>font_sizeB> - Font size of this column <B>Value:B> can be any positive number <B>Default:B> ’font_size’ of the table.
<B>font_colorB> - Font color of this column <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> ’font_color’ of the table.
<B>background_colorB> - Background color of this column <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> undef
<B>justifyB> - Alignment of text in this column <B>Value:B> One of ’left’, ’right’, ’center’ <B>Default:B> ’left’

Example:



    my $col_props = [
        {},# This is an empty hash so the next one will hold the properties for the second column from left to right.
        {
            min_w => 100,       # Minimum column width of 100.
            max_w => 150,       # Maximum column width of 150 .
            justify => right, # Right text alignment
            font => $pdf->corefont("Helvetica", -encoding => "latin1"),
            font_size => 10,
            font_color=> blue,
            background_color => #FFFF00,
        },
        # etc.
    ];



NOTE: If ’min_w’ and/or ’max_w’ parameter is used in ’col_props’, have in mind that it may be overriden by the calculated minimum/maximum cell witdh so that table can be created. When this happens a warning will be issued with some advises what can be done. In cases of a conflict between column formatting and odd/even row formatting, ’col_props’ will override odd/even.

Cell Properties

If the ’cell_props’ parameter is used, it should be an arrayref with arrays of hashrefs (of the same dimension as the data array) with one hashref for each cell of the table.

Each hashref can contain any of the keys shown below:
<B>fontB> - instance of PDF::API2::Resource::Font defining the fontf to be used in this cell <B>Value:B> can be any PDF::API2::Resource::* type of font <B>Default:B> ’font’ of the table. See table parameter ’font’ for more details.
<B>font_sizeB> - Font size of this cell <B>Value:B> can be any positive number <B>Default:B> ’font_size’ of the table.
<B>font_colorB> - Font color of this cell <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> ’font_color’ of the table.
<B>background_colorB> - Background color of this cell <B>Value:B> Color specifier as ’name’ or ’HEX’ <B>Default:B> undef
<B>justifyB> - Alignment of text in this cell <B>Value:B> One of ’left’, ’right’, ’center’ <B>Default:B> ’left’

Example:



    my $cell_props = [
        [ #This array is for the first row. If header_props is defined it will overwrite these settings.
            {    #Row 1 cell 1
                background_color => #AAAA00,
                font_color       => yellow,
            },

            # etc.
        ],
        [#Row 2
            {    #Row 2 cell 1
                background_color => #CCCC00,
                font_color       => blue,
            },
            {    #Row 2 cell 2
                background_color => #BBBB00,
                font_color       => red,
            },
            # etc.
        ],
        # etc.
    ];

    OR
   
    my $cell_props = [];
    $cell_props->[1][0] = {
        #Row 2 cell 1
        background_color => #CCCC00,
        font_color       => blue,
    };



NOTE: In case of a conflict between column, odd/even and cell formating, cell formating will overwrite the other two. In case of a conflict between header row and cell formating, header formating will override cell.

text_block()



    my ($width_of_last_line, $ypos_of_last_line, $left_over_text) = text_block( $txt, $data, %settings)



Description Utility method to create a block of text. The block may contain multiple paragraphs. It is mainly used internaly but you can use it from outside for placing formated text anywhere on the sheet.

NOTE: This method will NOT add more pages to the pdf instance if the space is not enough to place the string inside the block. Leftover text will be returned and has to be handled by the caller - i.e. add a new page and a new block with the leftover.

Parameters


    $txt  - a PDF::API2::Page::Text instance representing the text tool
    $data - a string that will be placed inside the block
    %settings - HASH with geometry and formatting parameters.



Reuturns The return value is a 3 items list where



    $width_of_last_line - Width of last line in the block
    $final_y - The Y coordinate of the block bottom so that additional content can be added after it
    $left_over_text - Text that was did not fit in the provided box geometry.



Example


    # PDF::API2 objects
    my $page = $pdf->page;
    my $txt  = $page->text;

    my %settings = (
        x => 10,
        y => 570,
        w => 220,
        h => 180
       
        #OPTIONAL PARAMS
        lead     => $font_size | $distance_between_lines,
        align    => "left|right|center|justify|fulljustify",
        hang     => $optional_hanging_indent,
        Only one of the subsequent 3params can be given.
        They override each other.-parspace is the weightest
        parspace => $optional_vertical_space_before_first_paragraph,
        flindent => $optional_indent_of_first_line,
        fpindent => $optional_indent_of_first_paragraph,
        indent   => $optional_indent_of_text_to_every_non_first_line,
    );
   
    my ( $width_of_last_line, $final_y, $left_over_text ) = $pdftable->text_block( $txt, $data, %settings );



VERSION

0.9.7

AUTHOR

Daemmon Hughes

DEVELOPMENT

Further development since Ver: 0.02 - Desislav Kamenov

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Daemmon Hughes, portions Copyright 2004 Stone Environmental Inc. (www.stone-env.com) 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.

PLUGS

by Daemmon Hughes Much of the work on this module was sponsered by Stone Environmental Inc. (www.stone-env.com).

The text_block() method is a slightly modified copy of the one from Rick Measham’s PDF::API2 tutorial at http://pdfapi2.sourceforge.net/cgi-bin/view/Main/YourFirstDocument

by Desislav Kamenov (@deskata on Twitter) The development of this module was supported by SEEBURGER AG (www.seeburger.com) till year 2007

Thanks to my friends Krasimir Berov and Alex Kantchev for helpful tips and QA during development of versions 0.9.0 to 0.9.5

Thanks to all GitHub contributors!

CONTRIBUTION

Hey PDF::Table is on GitHub. You are more than welcome to contribute!

https://github.com/kamenov/PDF-Table

SEE ALSO

PDF::API2
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PDF::TABLE (3) 2015-10-08

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.