Grzegorz Papkala > PDF-TableX-0.013 > PDF::TableX

Download:
PDF-TableX-0.013.tar.gz

Dependencies

Annotate this POD

CPAN RT

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

NAME ^

PDF::TableX - Moose driven table generation module that is uses famous PDF::API2

VERSION ^

Version 0.012

SYNOPSIS ^

The module provides capabilities to create tabular structures in PDF files. It is similar to PDF::Table module, however extends its functionality adding OO interface and allowing placement of any element inside table cell such as image, another pdf, or nested table.

Sample usage:

        use PDF::API2;
        use PDF::TableX;

        my $pdf         = PDF::API2->new();
        my $table = PDF::TableX->new(40,40);     # create 40 x 40 table
        $table
                ->padding(3)                           # set padding for cells
                ->border_width(2)                      # set border width
                ->border_color('blue');                # set border color
        $table[0][0]->content("Sample text");    # place "Sample text" in cell 0,0 (first cell in first row)
        $table[0][1]->content("Some other text"; # place "Some other text" in cell 0,1
        $table->draw($pdf, 1);                   # place table on the first page of pdf

        $pdf->save_as('some/file.pdf');

ATTRIBUTES ^

All attributes when set return $self allowing chaining of the calls.

Style Definitions

Following attributes take as argument either array reference with four values describing the style in each cell side in followin order [TOP, RIGHT, BOTTOM, LEFT]. Alternatively a scalar value can be provided in which case it is coerced to ARRAY REF

Following attributes require single value.

Placing & Behaviour

Following attributes control placing of the table and its behaviour

METHODS ^

cycle_background_color

Set the background colors of rows. The method takes the list of colors and applies them to subsequent rows. There is no limit to style e.g. only in odd/even fashio.

        # set odd and even background colors to black and white
        $table->cycle_background_color('black','white');

        # set the background color of rows to cycle with three colors: black, white, red
        $table->cycle_background_color('black','white','red');

EXTENDING THE MODULE ^

PDF::TableX uses Moose::Role(s) to define the styles and placing of the table. They can be relatively extended providing capabilites beyond those already available. Below code snipped creates the role that uses elliptical background shape instead of rectangle.

        package EllipsedBackground;
        use Moose::Role;

        sub draw_background {
                my ($self, $x, $y, $gfx, $txt) = @_;
                $gfx->linewidth(0);
                $gfx->fillcolor('yellow');
                $gfx->ellipse($x+$self->width/2, $y-$self->height/2, $self->width/2, $self->height/2);
                $gfx->fill();
        }

        use Moose::Util qw( apply_all_roles );
        use PDF::TableX;
        use PDF::API2;

        my $table = PDF::TableX->new(2,2);
        my $pdf         = PDF::API2->new();
        $pdf->mediabox('a4');

        # set some styles
        $table->padding(10)->border_width(1)->text_align('center');

        # apply moose roles to specific cells
        apply_all_roles( $table->[0][0], 'ElipsedBackground' );
        apply_all_roles( $table->[0][1], 'ElipsedBackground' );

        # set some content to those roles
        $table->[0][0]->content("Some text");
        $table->[0][1]->content("Some other text");

        # and finally draw it
        $table->draw($pdf, 1);
        # and save it
        $pdf->saveas('some/output.pdf');

AUTHOR ^

Grzegorz Papkala, <grzegorzpapkala at gmail.com>

BUGS ^

Please report any bugs or feature requests at: https://github.com/grzegorzpapkala/PDF-TableX/issues

SUPPORT ^

PDF::TableX is hosted on GitHub https://github.com/grzegorzpapkala/PDF-TableX

ACKNOWLEDGEMENTS ^

COPYRIGHT & LICENSE ^

Copyright 2013 Grzegorz Papkala, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: