PDF-API2-Simple

 view release on metacpan or  search on metacpan

lib/PDF/API2/Simple.pm  view on Meta::CPAN


  $self->current_font( $self->fonts->{$font_name} );

  if ($pt && ($pt > 0)) {
    $self->current_font_size( $pt );
  }
}

=head3 as_string

An alias for the stringify method

=cut

sub as_string { stringify( @_ ); }

=head3 stringify

Ends the current page, and returns the pdf as a string

=cut

sub stringify {
  my $self = shift;

  $self->end_page();
  $self->{'_pdf'}->stringify;
}

sub save_as { save( @_ ); }
sub saveas { save( @_ ); }

=head3 save [C<file>]

End the current page, and save the document to the file argument, or the file specified when instaniating the object. If not suitable file can be found to save in, a C<Carp::croak> is emitted. Aliases for this method are C<saveas> and C<save_as>.

=cut

sub save {
  my ($self, $file) = @_;

  $self->file( $file ) if ($file);

  if ( ! $self->file ) {
    Carp::croak( "No file specified" );
  }

  $self->end_page();
  $self->{'_pdf'}->saveas( $self->file );
}

# public methods - layout
# ================================================

=head2 Layout

These methods modify the actual layout of the PDF. Note that most of these methods set some internal state. Most often, the last C<x> and C<y> are set after the rendered object.

Most times, underscores may be stripped and the arguments will still work, such as is the difference between C<fill_color>, and C<fillcolor>.

=head3 popup C<text>[, C<%opts>]

Creates a 25x25 box at C<opts{x}> (or the current C<x>), C<opts{y}> (or the current C<y>) to represent an annotation at that point. The user may then click that icon for a full annotation.

=cut

sub popup {
  my ($self, $text, %opts) = @_;
  my $x = exists $opts{'x'} ? $opts{'x'} : $self->x;
  my $y = exists $opts{'y'} ? $opts{'y'} : $self->y;
  my $annotation = $self->current_page->annotation;
  
  $annotation->rect( $x, $y, $x + 25, $y + 25 );
  $annotation->text( $text );
}

=head3 url

This is an alias for the C<link> method.

=cut

sub url {
  my $self = shift;

  return $self->link( @_ );
}

=head3 link C<url>, C<text>[, C<%opts>]

Specifies a link to C<url>, having C<text>. C<%opts> may contain:

=over

=item * C<x> - The x position of the link. Defaults to C<x>.

=item * C<y> - The y position of the link. Defaults to C<y>.

=item * C<limit> - The amount to "limit" the text. This will add an ellipis (...) a few characters from the end if the text length is greater than this numerical value. Defaults to 0, which is to mean "do not limit".

=item * C<align> - Which alignment you want for your text. The choices are 'left', 'center', and 'right'. Defaults to 'left'.

=item * C<font> - Specifies via font name, the font to use. This sets the current font.

=item * C<font_size> - Specifies the font size. This sets the current font size.

=item * C<fill_color> - Specifies the fill color. This sets the current fill color.

=item * C<stroke_color> - Specifies the stroke color. This sets the current stroke color.

=back

This method returns the width of the text.

=cut

sub link {
  my ($self, $url, $text, %opts) = @_;
  my $x = exists $opts{'x'} ? $opts{'x'} : $self->x;
  my $y = exists $opts{'y'} ? $opts{'y'} : $self->y;
  my $limit = $opts{'limit'} || 0;
  my $align = $opts{'align'} || 'left';
  my $text_obj = $self->_get_text_object_for_current_page( %opts );
  my @rect;
  my $annotation;

  $text = $self->_limit_text( $text, $limit ) if ($limit);



( run in 1.079 second using v1.01-cache-2.11-cpan-364913b4093 )