View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Grzegorz Papkala > PDF-TableX-0.013 > PDF::TableX



Annotate this POD


New  2
Open  1
View/Report Bugs
Module Version: 0.013   Source   Latest Release: PDF-TableX-0.014


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


Version 0.012


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
                ->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



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



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

        # set the background color of rows to cycle with three colors: black, white, red


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->ellipse($x+$self->width/2, $y-$self->height/2, $self->width/2, $self->height/2);

        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();

        # set some styles

        # 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


Grzegorz Papkala, <grzegorzpapkala at>


Please report any bugs or feature requests at:


PDF::TableX is hosted on GitHub



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: