CtrlO-PDF

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

written to, and is the location that content will be positioned at the next
write. Note that the value is measured from the bottom of the page.

## set\_y\_position($pixels)

Sets the current Y position. See _y\_position_.

## move\_y\_position($pixels)

Moves the current Y position, relative to its current value. Positive values
will move the cursor up the page, negative values down. See _y\_position_.

## heading($text, %options)

Add a heading. If called on a new page, will automatically move the cursor down
to account for the heading's height (based on the assumption that one pixel
equals one point). Options available are:

    size _n_

        `n` is the font size in points, **default 16**

    indent _n_

        `n` is the amount (in points) to indent the text, **default 0**

lib/CtrlO/PDF.pm  view on Meta::CPAN

the is_new_page flag records that a new page is in use with no content. See
that method for more details.

=cut

sub add_page
{   my $self = shift;
    my $page = $self->pdf->page;
    $page->mediabox(0, 0, $self->width, $self->height);
    $self->_set_page($page);
    $self->_set__y($self->_y_start_default); # Reset y cursor
    # Flag that we have just started a new page. Because text is positioned from
    # its bottom-left corner, we will need to move the cursor down further to
    # account for the font size of the text, but we don't know that yet.
    $self->_set_is_new_page(1);
    return $page;
}

=head2 is_new_page

Whether the current page is new with no content. When the heading or text
methods are called and this is true, additional top margin is added to account
for the height of the text being added. Any other content manually added will

lib/CtrlO/PDF.pm  view on Meta::CPAN

sub set_y_position
{   my ($self, $y) = @_;
    $y && $y =~ /^-?[0-9]+(\.[0-9]+)?$/
        or croak "Invalid y value for set_y_position: $y";
    $self->_set__y($y);
}

=head2 move_y_position($pixels)

Moves the current Y position, relative to its current value. Positive values
will move the cursor up the page, negative values down. See L</y_position>.

=cut

sub move_y_position
{   my ($self, $y) = @_;
    $y && $y =~ /^-?[0-9]+(\.[0-9]+)?$/
        or croak "Invalid y value for move_y_position: $y";
    $self->_set__y($self->_y + $y);
}

lib/CtrlO/PDF.pm  view on Meta::CPAN

    builder => sub { $_[0]->_y_start_default },
);

sub _y_start_default
{   my $self = shift;
    return $self->height - $self->margin_top;
}

=head2 heading($text, %options)

Add a heading. If called on a new page, will automatically move the cursor down
to account for the heading's height (based on the assumption that one pixel
equals one point). Options available are:

=over

=item size I<n>

C<n> is the font size in points, B<default 16>

=item indent I<n>

lib/CtrlO/PDF.pm  view on Meta::CPAN

# Return the spacing above/below a line based on font size and line height
sub _line_spacing {
    my ($self, $size) = @_;
    my $spacing = $self->_line_height($size);
    ($spacing - $size) / 2;
}

sub heading
{   my ($self, $string, %options) = @_;

    my $page = $self->page; # Ensure that page is built and cursor adjusted for first use

    $page = $self->add_page if $self->_y < 150; # Make sure there is room for following paragraph text
    my $size = $options{size} || 16;

    if ($options{topmargin}) {
        # Always let override take precedence
        $self->_down($options{topmargin}) if $options{topmargin};
    }
    elsif ($self->is_new_page)
    {

lib/CtrlO/PDF.pm  view on Meta::CPAN


sub text
{   my ($self, $string, %options) = @_;

    $string or return;

    my $size = delete $options{size} || 10;
    my $color = delete $options{color} || 'black';
    my $format = delete $options{format} || 'none';

    my $page = $self->page; # Ensure that page is built and cursor adjusted for first use

    # Add new page if already at the bottom from previous operation (e.g.
    # rendering table)
    $page = $self->add_page
        if $self->_y - $self->_line_height($size) < $self->margin_bottom;

    my $text   = $page->text;
    my $grfx   = $page->gfx;
    my $x      = $self->_x + ($options{indent} || 0),
    my $height = $self->_y - $self->margin_bottom;

lib/CtrlO/PDF.pm  view on Meta::CPAN


Add a table, based on PDF::Table. Options available are C<data> to pass in the
data for the table; all other options are passed to the table method of
PDF::Table.

=cut

sub table
{   my ($self, %options) = @_;

    $self->page; # Ensure that page is built and cursor adjusted for first use

    # Move onto new page if little space left on this one.
    # TODO Change arbitary "60" to something calculated? Needs to be able to
    # fit header and one row as a minimum.
    $self->add_page if $self->_y < 60 + $self->margin_bottom;

    my $table = PDF::Table->new;

    my $data = delete $options{data};



( run in 0.239 second using v1.01-cache-2.11-cpan-4d50c553e7e )